-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathglobal.hpp
More file actions
104 lines (93 loc) · 3.4 KB
/
global.hpp
File metadata and controls
104 lines (93 loc) · 3.4 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// ***********************************************************************************
// Idefix MHD astrophysical code
// Copyright(C) Geoffroy R. J. Lesur <[email protected]>
// and other code contributors
// Licensed under CeCILL 2.1 License, see COPYING for more information
// ***********************************************************************************
#ifndef GLOBAL_HPP_
#define GLOBAL_HPP_
#include <iostream>
#include <string>
#include <vector>
#include "arrays.hpp"
#include "npy.hpp"
namespace idfx {
int initialize(); // Initialisation routine for idefix
real randm(); // Custom random number generator
void safeExit(int ); // Exit the code
class IdefixOutStream;
class IdefixErrStream;
class Profiler;
class Units;
extern int prank; //< parallel rank
extern int psize;
extern IdefixOutStream cout; //< custom cout for idefix
extern IdefixErrStream cerr; //< custom cerr for idefix
extern Profiler prof; //< profiler (for memory & performance usage)
extern double mpiCallsTimer; //< time significant MPI calls
extern LoopPattern defaultLoopPattern; //< default loop patterns (for idefix_for loops)
extern bool warningsAreErrors; //< whether warnings should be considered as errors
extern Units units; //< Units for the run
void pushRegion(const std::string&);
void popRegion();
template<typename T>
IdefixArray1D<T> ConvertVectorToIdefixArray(std::vector<T> &inputVector) {
IdefixArray1D<T> outArr = IdefixArray1D<T>("Vector",inputVector.size());
IdefixHostArray1D<T> outArrHost;
outArrHost = Kokkos::create_mirror_view(Kokkos::HostSpace(), outArr);
for(int i = 0; i < inputVector.size() ; i++) {
outArrHost(i) = inputVector[i];
}
Kokkos::deep_copy(outArr, outArrHost);
return(outArr);
}
///< dump Idefix array to a numpy array on disk
template<typename ArrayType>
void DumpArray(std::string filename, ArrayType array) {
auto hArray = Kokkos::create_mirror(array);
Kokkos::deep_copy(hArray, array);
std::array<uint64_t, ArrayType::rank> shape;
bool fortran_order{false};
for (size_t i = 0; i < ArrayType::rank; ++i) {
shape[i] = array.extent(i);
}
npy::SaveArrayAsNumpy(filename, fortran_order, ArrayType::rank, shape.data(), hArray.data());
}
} // namespace idfx
class idfx::IdefixOutStream {
public:
void init(int);
void enableLogFile();
// for regular output of variables and stuff
template<typename T> IdefixOutStream& operator<<(const T& something) {
if(toscreen) std::cout << something;
if(logFileEnabled) my_fstream << something;
return *this;
}
// for manipulators like std::endl
typedef std::ostream& (*stream_function)(std::ostream&);
IdefixOutStream& operator<<(stream_function func) {
if(toscreen) func(std::cout);
if(logFileEnabled) func(my_fstream);
return *this;
}
private:
std::ofstream my_fstream;
bool toscreen;
bool logFileEnabled{false}; //< whether streams are also written to a log file
};
class idfx::IdefixErrStream {
public:
// for error output of variables and stuff
template<typename T> IdefixErrStream& operator<<(const T& something) {
std::cerr << something;
return *this;
}
// for manipulators like std::endl
typedef std::ostream& (*stream_function)(std::ostream&);
IdefixErrStream& operator<<(stream_function func) {
func(std::cerr);
return *this;
}
};
#endif // GLOBAL_HPP_