summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/pomp.h
blob: 26dd6072c3dfb1d1fbe24e3f58725eead0e285c2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// license:GPL-2.0+
// copyright-holders:Couriersud

#ifndef POMP_H_
#define POMP_H_

///
/// \file pomp.h
///
/// Wrap all OPENMP stuff here in a hopefully c++ compliant way.
///

#include "pconfig.h"
#include "ptypes.h"

#include <cstdint>

#if PHAS_OPENMP
#include "omp.h"
#endif

namespace plib {
namespace omp {

template <typename I, class T>
void for_static(std::size_t numops, const I start, const I end, const T &what)  noexcept(noexcept(what))
{
	if (numops>1000)
	{
	#if PHAS_OPENMP && PUSE_OPENMP
		#pragma omp parallel for schedule(static)
	#endif
		for (I i = start; i <  end; i++)
			what(i);
	}
	else
		for (I i = start; i <  end; i++)
			what(i);
}

template <typename I, class T>
void for_static(const I start, const I end, const T &what) noexcept(noexcept(what))
{
#if PHAS_OPENMP && PUSE_OPENMP
	#pragma omp parallel for schedule(static)
#endif
	for (I i = start; i <  end; i++)
		what(i);
}

template <typename I, class T>
void for_static_np(const I start, const I end, const T &what) noexcept(noexcept(what))
{
	for (I i = start; i <  end; i++)
		what(i);
}


inline void set_num_threads(const std::size_t threads) noexcept
{
#if PHAS_OPENMP && PUSE_OPENMP
	omp_set_num_threads(threads);
#else
	plib::unused_var(threads);
#endif
}

inline std::size_t get_max_threads() noexcept
{
#if PHAS_OPENMP && PUSE_OPENMP
	return omp_get_max_threads();
#else
	return 1;
#endif
}


// ----------------------------------------------------------------------------------------
// pdynlib: dynamic loading of libraries  ...
// ----------------------------------------------------------------------------------------

} // namespace omp
} // namespace plib

#endif // PSTRING_H_