Morpheus 1.0.0
Dynamic matrix type and algorithms for sparse matrices
Loading...
Searching...
No Matches
Morpheus_OpenMPUtils.hpp
1
24#ifndef MORPHEUS_OPENMP_UTILS_HPP
25#define MORPHEUS_OPENMP_UTILS_HPP
26
27#include <Morpheus_Macros.hpp>
28#if defined(MORPHEUS_ENABLE_OPENMP)
29
30#include <omp.h>
31
32namespace Morpheus {
33namespace Impl {
34
35template <typename T>
36T _split_work(const T load, const T workers, const T worker_id) {
37 const T unifload = load / workers; // uniform distribution
38 const T rem = load - unifload * workers;
39 T bound;
40
41 // round-robin assignment of the remaining work
42 if (worker_id <= rem) {
43 bound = (unifload + 1) * worker_id;
44 } else {
45 bound = (unifload + 1) * rem + unifload * (worker_id - rem);
46 }
47
48 return bound;
49}
50
51template <typename T>
52void atomic_add(T* out, T val) {
53#pragma omp atomic
54 *out += val;
55}
56
57template <typename T = int>
58T threads() {
59 T t = 1;
60#pragma omp parallel
61 { t = omp_get_num_threads(); }
62
63 return t;
64}
65
66} // namespace Impl
67} // namespace Morpheus
68
69#endif // MORPHEUS_ENABLE_OPENMP
70#endif // MORPHEUS_OPENMP_UTILS_HPP
Generic Morpheus interfaces.
Definition: dummy.cpp:24