• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmc-dev / openmc / 30647347479

31 Jul 2026 04:29PM UTC coverage: 81.444% (+0.04%) from 81.4%
30647347479

Pull #3934

github

web-flow
Merge 39a21605d into a8152672b
Pull Request #3934: Fix virtual surface crossing

18511 of 26803 branches covered (69.06%)

Branch coverage included in aggregate %.

25 of 25 new or added lines in 1 file covered. (100.0%)

1004 existing lines in 27 files now uncovered.

60218 of 69864 relevant lines covered (86.19%)

50326619.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.3
/src/message_passing.cpp
1
#include "openmc/message_passing.h"
2

3
#include <algorithm>
4
#include <climits>
5
#include <limits>
6

7
namespace openmc {
8
namespace mpi {
9

10
int rank {0};
11
int n_procs {1};
12
bool master {true};
13

14
#ifdef OPENMC_MPI
15
MPI_Comm intracomm {MPI_COMM_NULL};
16
MPI_Datatype source_site {MPI_DATATYPE_NULL};
17
MPI_Datatype collision_track_site {MPI_DATATYPE_NULL};
18
#endif
19

20
extern "C" bool openmc_master()
6,510✔
21
{
22
  return mpi::master;
6,510✔
23
}
24

25
vector<int64_t> calculate_parallel_index_vector(int64_t size)
849✔
26
{
27
  vector<int64_t> result;
849✔
28
  result.resize(n_procs + 1);
849✔
29
  result[0] = 0;
849✔
30

31
#ifdef OPENMC_MPI
32

33
  // Populate the result with cumulative sum of the number of
34
  // surface source banks per process
35
  int64_t scan_total;
36
  MPI_Scan(&size, &scan_total, 1, MPI_INT64_T, MPI_SUM, intracomm);
520✔
37
  MPI_Allgather(
520✔
38
    &scan_total, 1, MPI_INT64_T, result.data() + 1, 1, MPI_INT64_T, intracomm);
520✔
39
#else
40
  result[1] = size;
849✔
41
#endif
42

43
  return result;
849✔
UNCOV
44
}
×
45

46
#ifdef OPENMC_MPI
47
void reduce_buffer(const void* sendbuf, void* recvbuf, std::size_t count,
48
  MPI_Datatype datatype, std::size_t type_size, MPI_Op op, int root,
49
  MPI_Comm comm)
50
{
51
  // Determine the maximum number of elements accepted by the selected API.
52
#ifdef OPENMC_HAVE_MPI_REDUCE_C
53
  const std::size_t chunk_limit {
54
    static_cast<std::size_t>(std::numeric_limits<MPI_Count>::max())};
55
#else
56
  constexpr std::size_t chunk_limit {INT_MAX};
57
#endif
58

59
  // A legacy MPI reduction accepts an int count, so split the logical buffer
60
  // into bounded chunks before converting the count.
61
  for (std::size_t offset = 0; offset < count; offset += chunk_limit) {
115,984✔
62
    const std::size_t chunk_size = std::min(count - offset, chunk_limit);
57,992!
63

64
    // MPI_IN_PLACE must be passed unchanged on the root. Other buffers are
65
    // advanced by the chunk offset in bytes because their element type is
66
    // represented by an MPI datatype rather than a C++ pointer type here.
67
    const void* send_chunk =
68
      sendbuf == MPI_IN_PLACE
69
        ? MPI_IN_PLACE
57,992✔
70
        : static_cast<const char*>(sendbuf) + offset * type_size;
71
    void* recv_chunk = recvbuf == nullptr
72
                         ? nullptr
57,992✔
73
                         : static_cast<char*>(recvbuf) + offset * type_size;
74

75
#ifdef OPENMC_HAVE_MPI_REDUCE_C
76
    MPI_Reduce_c(send_chunk, recv_chunk, static_cast<MPI_Count>(chunk_size),
77
      datatype, op, root, comm);
78
#else
79
    MPI_Reduce(send_chunk, recv_chunk, static_cast<int>(chunk_size), datatype,
80
      op, root, comm);
81
#endif
82
  }
83
}
84

85
// Specializations of the MPITypeMap template struct
86
template<>
87
const MPI_Datatype MPITypeMap<int>::mpi_type = MPI_INT;
88
template<>
89
const MPI_Datatype MPITypeMap<double>::mpi_type = MPI_DOUBLE;
90
template<>
91
const MPI_Datatype MPITypeMap<int64_t>::mpi_type = MPI_INT64_T;
92
#endif
93

94
} // namespace mpi
95

96
} // namespace openmc
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc