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

openmc-dev / openmc / 13546000884

26 Feb 2025 02:19PM UTC coverage: 85.015% (-0.2%) from 85.186%
13546000884

Pull #3328

github

web-flow
Merge 67a173195 into e060534ff
Pull Request #3328: NCrystal becomes runtime rather than buildtime dependency

81 of 108 new or added lines in 6 files covered. (75.0%)

467 existing lines in 21 files now uncovered.

51062 of 60062 relevant lines covered (85.02%)

32488887.43 hits per line

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

85.71
/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:
39
  void init()
40
  {
41
#ifdef _OPENMP
42
    omp_init_lock(&mutex_);
43
#endif
44
  }
45

46
  OpenMPMutex() { init(); }
47

UNCOV
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(); }
68

69
  // Copy assignment operator
70
  OpenMPMutex& operator=(const OpenMPMutex& other) { return *this; }
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
28,978✔
87
  {
88
#ifdef _OPENMP
89
    return omp_test_lock(&mutex_);
15,782✔
90
#else
91
    return true;
13,196✔
92
#endif
93
  }
94

95
  //! Unlock the mutex.
96
  void unlock() noexcept
293,433,132✔
97
  {
98
#ifdef _OPENMP
99
    omp_unset_lock(&mutex_);
146,717,344✔
100
#endif
101
  }
293,433,132✔
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