MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
MAIA Class Reference

#include <maia.h>

Collaboration diagram for MAIA:
[legend]

Public Member Functions

 MAIA (int argc, char **argv)
 
int run ()
 Main controlling method for MAIA. Calls everything else. More...
 

Private Attributes

NullBuffer nullBuffer
 
int m_argc = 0
 
char ** m_argv = nullptr
 

Detailed Description

Definition at line 49 of file maia.h.

Constructor & Destructor Documentation

◆ MAIA()

MAIA::MAIA ( int  argc,
char **  argv 
)
inline

Definition at line 51 of file maia.h.

51: m_argc(argc), m_argv(argv) {}
char ** m_argv
Definition: maia.h:59
int m_argc
Definition: maia.h:58

Member Function Documentation

◆ run()

int MAIA::run ( )

Definition at line 56 of file maia.cpp.

56 {
57 // Initialize MPI communication
58 // Profiling uses MPI_Wtime, i.e. the first DEBUG call requires MPI to be initialized already
59#ifdef _OPENMP
60
61 /* If OMP_NUM_THREADS is not set, limit number of threads to one, unless another environment
62 // variable is set appropriately
63 if (!getenv("OMP_NUM_THREADS")) {
64 const char* env = getenv("MAIA_AUTO_NUM_THREADS");
65 if (!env || MString(env) != MString("1")) {
66 omp_set_num_threads(1);
67 m_log << "Set number of openMP-Threads to 1" << endl;
68 cerr0 << "Set number of openMP-Threads to 1" << endl;
69 }
70 }
71 */
72
73 int provided;
74 MPI_Init_thread(&m_argc, &m_argv, MPI_THREAD_FUNNELED, &provided);
75 // The check for the provided thread level is omitted until OpenMPI reports
76 // the correct level and not just MPI_THREAD_SINGLE no matter what
77 // if (provided < MPI_THREAD_FUNNELED) {
78 // cerr << "OpenMP requires a threaded MPI library, but the used library is "
79 // << "not." << endl;
80 // MPI_Finalize();
81 // return EXIT_FAILURE;
82 // }
83#else
84 MPI_Init(&m_argc, &m_argv);
85#endif
86 int domainId, noDomains;
87#ifndef MAIA_WINDOWS
88 fftw_mpi_init();
89#endif
90 MPI_Comm_rank(MPI_COMM_WORLD, &domainId);
91 MPI_Comm_size(MPI_COMM_WORLD, &noDomains);
92 g_mpiInformation.init(domainId, noDomains);
93
94 // Set MPI error handling (return error and handle in code)
95 MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
96
97 // Open cerr0 on MPI root
98 if(domainId == 0) {
99 cerr0.rdbuf(cerr.rdbuf());
100 } else {
101 cerr0.rdbuf(&nullBuffer);
102 }
103
104 // Check type sizes to make sure they have the expected size
105 // If an error is produced but you want to proceed anyways, just comment the
106 // offending line(s) below
107 static_assert(CHAR_BIT == 8, "Unexpected type size: char has " XSTRINGIFY(CHAR_BIT) " bits (expected: 8)");
108 static_assert(sizeof(MChar) == 1, "MChar has unexpected type size");
109#ifndef _SX
110 static_assert(sizeof(MBool) == 1, "MBool has unexpected type size");
111#endif
112 static_assert(sizeof(MInt) == 4, "MInt has unexpected type size");
113 static_assert(sizeof(MInt) == 4, "MInt has unexpected type size");
114 static_assert(sizeof(MLong) == 8, "MLong has unexpected type size");
115 static_assert(sizeof(MFloat) == 8, "MFloat has unexpected type size");
116
117 // Needed for m_log
120
121 // Open log file
122#if(MAIA_INFOOUT_FILE_TYPE == 1 && MAIA_INFOOUT_ROOT_ONLY == false)
123 m_log.open("m_log_" + to_string(globalDomainId()), MAIA_INFOOUT_PROJECT_NAME, MAIA_INFOOUT_FILE_TYPE, MPI_COMM_WORLD,
124 MAIA_INFOOUT_ROOT_ONLY);
125#else
126 m_log.open("m_log", MAIA_INFOOUT_PROJECT_NAME, MAIA_INFOOUT_FILE_TYPE, MPI_COMM_WORLD, MAIA_INFOOUT_ROOT_ONLY);
127#endif
128
129 // Set root-only writing property
130 m_log.setRootOnly(MAIA_INFOOUT_ROOT_ONLY);
131
132 // Set minimum flush size
133 m_log.setMinFlushSize(MAIA_INFOOUT_MIN_FLUSH_SIZE);
134
135 // Reset global debug level (may be overridden using the "-d <lvl>" command line parameter (cf. debug.h)
136 SET_DEBUG_LEVEL(0);
137 // SET_DEBUG_LEVEL(MAIA_DEBUG_TRACE_IN | MAIA_DEBUG_TRACE_OUT | MAIA_DEBUG_TRACE);
138 // Note: do not trace this, since m_log is closed before this trace is finished the output to m_log results in a
139 // segmentation fault!
140 // TRACE();
141 DEBUG("main:: domainId " << globalDomainId(), MAIA_DEBUG_LEVEL1);
142 DEBUG("main:: noDomains " << globalNoDomains(), MAIA_DEBUG_LEVEL1);
143
144 // Initialize likwid if likwid is enabled
145#ifdef WITH_LIKWID
146 LIKWID_MARKER_INIT;
147 LIKWID_MARKER_THREADINIT;
148#endif
149
150 // Reset all timers
151 DEBUG("main:: reset timer", MAIA_DEBUG_LEVEL1);
152 RESET_TIMERS();
153
154 NEW_TIMER_GROUP(tg, "MAIA");
155
156 // Start timer for the total program execution
157 NEW_TIMER(timertotal, "Total", tg);
158 RECORD_TIMER_START(timertotal);
159
160 // Create environment
161 NEW_SUB_TIMER(timer1, "New Environment", timertotal);
162 RECORD_TIMER_START(timer1);
163
164 DEBUG("main:: new Environment", MAIA_DEBUG_LEVEL1);
166 RECORD_TIMER_STOP(timer1);
167
168 // Run MAIA... YEHAW!
169 DEBUG("main:: mEnvironment->run", MAIA_DEBUG_LEVEL1);
170 NEW_SUB_TIMER(timer2, "Run Environment", timertotal);
171 RECORD_TIMER_START(timer2);
172 mEnvironment->run();
173 RECORD_TIMER_STOP(timer2);
174
175 // Once mEnvironment has finished, call the cleanup function
176 NEW_SUB_TIMER(timer3, "End Environment", timertotal);
177 DEBUG("main:: mEnvironment->end", MAIA_DEBUG_LEVEL1);
178 RECORD_TIMER_START(timer3);
179 mEnvironment->end();
180 RECORD_TIMER_STOP(timer3);
181
182 // Finalize likwid if likwid is enabled
183#ifdef WITH_LIKWID
184 LIKWID_MARKER_CLOSE;
185#endif
186
187 // Delete mEnvironment
188 DEBUG("main:: delete environment", MAIA_DEBUG_LEVEL1);
189 if(mEnvironment != nullptr) {
190 delete mEnvironment;
191 mEnvironment = nullptr;
192 }
193
194 // Stop the timer for total program execution
195 RECORD_TIMER_STOP(timertotal);
196
197 // Show timer output
198 DEBUG("main:: display all timers", MAIA_DEBUG_LEVEL1);
199 STOP_ALL_RECORD_TIMERS();
200 DISPLAY_ALL_TIMERS();
201
202 // Save memory report to log file
204
205 // Deallocate all memory
206 DEBUG("main:: mDealloc", MAIA_DEBUG_LEVEL1);
207 mDealloc();
208
209 // Close log file streams
210 DEBUG("main:: close streams", MAIA_DEBUG_LEVEL1);
211 m_log.close();
212 maia_res.close();
213
214 // Stop MPI - after MPI_Finalize, no more calls to any MPI-related functions are allowed!
215 // Note: do not use DEBUG() after m_log has been closed!
216 // DEBUG("main:: MPI_Finalize", MAIA_DEBUG_LEVEL1);
217#ifndef MAIA_WINDOWS
218 fftw_mpi_cleanup();
219#endif
220 MPI_Finalize();
221
222 return EXIT_SUCCESS;
223}
void mDealloc()
Deallocates all memory allocated previously by mAlloc(...)
Definition: alloc.cpp:20
Environment for the program.
Definition: environment.h:21
static MChar ** m_argv
Definition: environment.h:29
MInt run()
Runs the Environment, makes the Application run.
MInt end()
Ends the Environment.
static MInt m_argc
Reads the name of the property-file and creates a new Application.
Definition: environment.h:28
void init(const MInt domainId, const MInt noDomains)
Definition: globalmpiinfo.h:24
void open(const MString &filename, const MString &projectName, MInt fileType=0, MPI_Comm mpiComm=MPI_COMM_WORLD, MBool rootOnlyHardwired=false)
Opens a file by passing the parameters to InfoOut_<xyz>FileBuffer::open(...).
Definition: infoout.cpp:975
void close(MBool forceClose=false)
Pass the close call to the respective internal buffer.
Definition: infoout.cpp:1011
MBool setRootOnly(MBool rootOnly=true)
Sets interal state of whether only the root domain (rank 0) should write to file.
Definition: infoout.cpp:1043
MInt setMinFlushSize(MInt minFlushSize)
Sets the minimum buffer length that has to be reached before the buffer is flushed.
Definition: infoout.cpp:1055
NullBuffer nullBuffer
Definition: maia.h:56
static MString printSelfReport()
Returns a shortened string summing up the scratch space state information.
Definition: scratch.cpp:129
GlobalMpiInformation g_mpiInformation
MInt globalNoDomains()
Return global number of domains.
MInt globalDomainId()
Return global domain id.
InfoOutFile maia_res
InfoOutFile m_log
std::ostream cerr0
Environment * mEnvironment
Definition: maia.cpp:42
int32_t MInt
Definition: maiatypes.h:62
double MFloat
Definition: maiatypes.h:52
int64_t MLong
Definition: maiatypes.h:64
bool MBool
Definition: maiatypes.h:58
char MChar
Definition: maiatypes.h:56

Member Data Documentation

◆ m_argc

int MAIA::m_argc = 0
private

Definition at line 58 of file maia.h.

◆ m_argv

char** MAIA::m_argv = nullptr
private

Definition at line 59 of file maia.h.

◆ nullBuffer

NullBuffer MAIA::nullBuffer
private

Definition at line 56 of file maia.h.


The documentation for this class was generated from the following files: