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

openmc-dev / openmc / 9966309227

17 Jul 2024 12:53AM UTC coverage: 84.815% (+0.008%) from 84.807%
9966309227

push

github

web-flow
Linear Source Random Ray (#3072)

Co-authored-by: John Tramm <john.tramm@gmail.com>
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>

336 of 369 new or added lines in 9 files covered. (91.06%)

36 existing lines in 4 files now uncovered.

49336 of 58169 relevant lines covered (84.81%)

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

22
inline int thread_num()
1,402,744✔
23
{
24
#ifdef _OPENMP
25
  return omp_get_thread_num();
1,402,744✔
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()
49,763,532✔
78
  {
79
#ifdef _OPENMP
80
    omp_set_lock(&mutex_);
24,881,766✔
81
#endif
82
  }
49,763,532✔
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

© 2026 Coveralls, Inc