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

openmc-dev / openmc / 14388959122

10 Apr 2025 07:43PM UTC coverage: 85.123% (+0.08%) from 85.044%
14388959122

Pull #3366

github

web-flow
Merge 4dd50b246 into cdc254ccf
Pull Request #3366: Add methods on Material class for waste disposal rating / classification

63 of 71 new or added lines in 2 files covered. (88.73%)

106 existing lines in 18 files now uncovered.

51732 of 60773 relevant lines covered (85.12%)

36998786.8 hits per line

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

80.0
/include/openmc/openmp_interface.h
1
#ifndef OPENMC_OPENMP_INTERFACE_H
2
#define OPENMC_OPENMP_INTERFACE_H
3

4
#ifdef _OPENMP
5
#include <omp.h>
6
#endif
7

8
namespace openmc {
9

10
//==============================================================================
11
//! Accessor functions related to number of threads and thread number
12
//==============================================================================
13
inline int num_threads()
14
{
15
#ifdef _OPENMP
16
  return omp_get_max_threads();
17
#else
18
  return 1;
19
#endif
20
}
21

22
inline int thread_num()
23
{
24
#ifdef _OPENMP
25
  return omp_get_thread_num();
26
#else
27
  return 0;
28
#endif
29
}
30

31
//==============================================================================
32
//! An object used to prevent concurrent access to a piece of data.
33
//
34
//! This type meets the C++ "Lockable" requirements.
35
//==============================================================================
36

37
class OpenMPMutex {
38
public:
UNCOV
39
  void init()
×
40
  {
41
#ifdef _OPENMP
42
    omp_init_lock(&mutex_);
43
#endif
44
  }
45

46
  OpenMPMutex() { init(); }
47

48
  ~OpenMPMutex()
×
49
  {
50
#ifdef _OPENMP
51
    omp_destroy_lock(&mutex_);
52
#endif
53
  }
54

55
  // omp_lock_t objects cannot be deep copied, they can only be shallow
56
  // copied. Thus, while shallow copying of an omp_lock_t object is
57
  // completely valid (provided no race conditions exist), true copying
58
  // of an OpenMPMutex object is not valid due to the action of the
59
  // destructor. However, since locks are fungible, we can simply replace
60
  // copying operations with default construction. This allows storage of
61
  // OpenMPMutex objects within containers that may need to move/copy them
62
  // (e.g., std::vector). It is left to the caller to understand that
63
  // copying of OpenMPMutex does not produce two handles to the same mutex,
64
  // rather, it produces two different mutexes.
65

66
  // Copy constructor
67
  OpenMPMutex(const OpenMPMutex& other) { init(); }
10,944,628✔
68

69
  // Copy assignment operator
70
  OpenMPMutex& operator=(const OpenMPMutex& other) { return *this; }
17,280✔
71

72
  //! Lock the mutex.
73
  //
74
  //! This function blocks execution until the lock succeeds.
75
  void lock()
76
  {
77
#ifdef _OPENMP
78
    omp_set_lock(&mutex_);
79
#endif
80
  }
81

82
  //! Try to lock the mutex and indicate success.
83
  //
84
  //! This function does not block.  It returns immediately and gives false if
85
  //! the lock is unavailable.
86
  bool try_lock() noexcept
26,875✔
87
  {
88
#ifdef _OPENMP
89
    return omp_test_lock(&mutex_);
15,564✔
90
#else
91
    return true;
11,311✔
92
#endif
93
  }
94

95
  //! Unlock the mutex.
96
  void unlock() noexcept
1,232,194,712✔
97
  {
98
#ifdef _OPENMP
99
    omp_unset_lock(&mutex_);
672,106,651✔
100
#endif
101
  }
1,232,194,712✔
102

103
private:
104
#ifdef _OPENMP
105
  omp_lock_t mutex_;
106
#endif
107
};
108

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

© 2026 Coveralls, Inc