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

openmc-dev / openmc / 14840340664

05 May 2025 03:38PM UTC coverage: 85.195% (-0.009%) from 85.204%
14840340664

Pull #3392

github

web-flow
Merge 5bc1ec35f into 1e7d8324e
Pull Request #3392: Map Compton subshell data to atomic relaxation data

14 of 14 new or added lines in 2 files covered. (100.0%)

330 existing lines in 19 files now uncovered.

52194 of 61264 relevant lines covered (85.2%)

37398320.1 hits per line

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

87.5
/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()
13,587,986✔
40
  {
41
#ifdef _OPENMP
42
    omp_init_lock(&mutex_);
7,465,281✔
43
#endif
44
  }
13,587,986✔
45

46
  OpenMPMutex() { init(); }
2,643,358✔
47

48
  ~OpenMPMutex()
13,587,984✔
49
  {
50
#ifdef _OPENMP
51
    omp_destroy_lock(&mutex_);
7,465,279✔
52
#endif
53
  }
13,587,984✔
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
UNCOV
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
87
  {
88
#ifdef _OPENMP
89
    return omp_test_lock(&mutex_);
90
#else
91
    return true;
92
#endif
93
  }
94

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

© 2025 Coveralls, Inc