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

openmc-dev / openmc / 9617074623

21 Jun 2024 04:53PM UTC coverage: 84.715% (+0.03%) from 84.688%
9617074623

Pull #3042

github

web-flow
Merge 47e50a3a9 into 4bd0b09e6
Pull Request #3042: Rely on std::filesystem for file_utils

26 of 31 new or added lines in 5 files covered. (83.87%)

921 existing lines in 34 files now uncovered.

48900 of 57723 relevant lines covered (84.71%)

31496763.14 hits per line

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

90.91
/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
  OpenMPMutex()
183,786✔
40
  {
100,060✔
41
#ifdef _OPENMP
42
    omp_init_lock(&mutex_);
100,060✔
43
#endif
44
  }
183,786✔
45

46
  ~OpenMPMutex()
183,784✔
47
  {
48
#ifdef _OPENMP
49
    omp_destroy_lock(&mutex_);
100,058✔
50
#endif
51
  }
183,784✔
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()
61,223,376✔
78
  {
79
#ifdef _OPENMP
80
    omp_set_lock(&mutex_);
30,611,688✔
81
#endif
82
  }
61,223,376✔
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