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

openmc-dev / openmc / 12776996362

14 Jan 2025 09:49PM UTC coverage: 84.938% (+0.2%) from 84.729%
12776996362

Pull #3133

github

web-flow
Merge 0495246d9 into 549cc0973
Pull Request #3133: Kinetics parameters using Iterated Fission Probability

318 of 330 new or added lines in 10 files covered. (96.36%)

1658 existing lines in 66 files now uncovered.

50402 of 59340 relevant lines covered (84.94%)

33987813.96 hits per line

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

88.89
/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()
77,060✔
14
{
15
#ifdef _OPENMP
16
  return omp_get_max_threads();
46,220✔
17
#else
18
  return 1;
30,840✔
19
#endif
20
}
21

22
inline int thread_num()
1,409,082✔
23
{
24
#ifdef _OPENMP
25
  return omp_get_thread_num();
1,409,082✔
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
  OpenMPMutex()
40
  {
41
#ifdef _OPENMP
42
    omp_init_lock(&mutex_);
43
#endif
44
  }
45

46
  ~OpenMPMutex()
47
  {
48
#ifdef _OPENMP
49
    omp_destroy_lock(&mutex_);
50
#endif
51
  }
52

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

64
  // Copy constructor
65
  OpenMPMutex(const OpenMPMutex& other) { OpenMPMutex(); }
66

67
  // Copy assignment operator
68
  OpenMPMutex& operator=(const OpenMPMutex& other)
69
  {
70
    OpenMPMutex();
71
    return *this;
72
  }
73

74
  //! Lock the mutex.
75
  //
76
  //! This function blocks execution until the lock succeeds.
77
  void lock()
222,367,992✔
78
  {
79
#ifdef _OPENMP
80
    omp_set_lock(&mutex_);
111,183,996✔
81
#endif
82
  }
222,367,992✔
83

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

97
  //! Unlock the mutex.
UNCOV
98
  void unlock() noexcept
×
99
  {
100
#ifdef _OPENMP
101
    omp_unset_lock(&mutex_);
102
#endif
103
  }
104

105
private:
106
#ifdef _OPENMP
107
  omp_lock_t mutex_;
108
#endif
109
};
110

111
} // namespace openmc
112
#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