CHAMELEON 1.4.0
Loading...
Searching...
No Matches
control.c
Go to the documentation of this file.
1
31#include "control/common.h"
32#include "chameleon/runtime.h"
33
54int __chameleon_init(int cores, int gpus)
55{
56 return __chameleon_initpar(cores, gpus, -1);
57}
58
82int __chameleon_initpar(int ncpus, int ngpus, int nthreads_per_worker)
83{
84 return __chameleon_initparcomm( ncpus, ngpus, nthreads_per_worker, MPI_COMM_WORLD );
85}
86
113int __chameleon_initparcomm(int ncpus, int ngpus, int nthreads_per_worker, MPI_Comm comm)
114{
115 CHAM_context_t *chamctxt;
116
117 /* Create context and insert in the context map */
118 chamctxt = chameleon_context_create();
119 if (chamctxt == NULL) {
120 chameleon_fatal_error("CHAMELEON_Init", "chameleon_context_create() failed");
121 return CHAMELEON_ERR_OUT_OF_RESOURCES;
122 }
123
124#if defined(CHAMELEON_USE_MPI)
125# if defined(CHAMELEON_SIMULATION)
126 /* Assuming that we don't initialize MPI ourself (which SMPI doesn't support anyway) */
127 chamctxt->mpi_outer_init = 1;
128# else
129 {
130 int flag = 0, provided = 0;
131 MPI_Initialized( &flag );
132 chamctxt->mpi_outer_init = flag;
133 if ( !flag ) {
134 /* MPI_THREAD_SERIALIZED should be enough.
135 * In testings, only StarPU's internal thread performs
136 * communications, and *then* Chameleon performs communications in
137 * the check step. */
138 const int required = MPI_THREAD_MULTIPLE;
139 if ( MPI_Init_thread( NULL, NULL, required, &provided ) != MPI_SUCCESS) {
140 chameleon_fatal_error("CHAMELEON_Init", "MPI_Init_thread() failed");
141 }
142 if ( provided < required ) {
143 chameleon_fatal_error("CHAMELEON_Init",
144 "MPI_Init_thread() was not able to provide the requested thread support (MPI_THREAD_MULTIPLE),\n"
145 "this may be an issue if the level provided is not enough for the underlying runtime system." );
146 }
147 }
148 }
149# endif
150#endif
151
152#if !defined(CHAMELEON_USE_CUDA) && !defined(CHAMELEON_USE_HIP)
153 if ( ngpus != 0 ) {
154 chameleon_warning("CHAMELEON_Init", "CHAMELEON_USE_CUDA or CHAMELEON_USE_HIP are not defined, ngpus is forced to 0");
155 ngpus = 0;
156 }
157#endif
158
159 chamctxt->ncudas = ngpus;
160 chamctxt->comm = comm;
161 return RUNTIME_init( chamctxt, ncpus, ngpus, nthreads_per_worker );
162}
163
176{
177 CHAM_context_t *chamctxt = chameleon_context_self();
178 if (chamctxt == NULL) {
179 chameleon_error("CHAMELEON_Finalize", "CHAMELEON not initialized");
180 return CHAMELEON_ERR_NOT_INITIALIZED;
181 }
182
183 /* Make sure all data are flushed */
184 RUNTIME_flush( chamctxt );
185
186 /* Wait for anything running */
187# if !defined(CHAMELEON_SIMULATION)
188 RUNTIME_barrier(chamctxt);
189# endif
190
191 /* Stop the runtime system */
192 RUNTIME_finalize( chamctxt );
193
194#if defined(CHAMELEON_USE_MPI)
195 /* Finalize MPI if initialized by Chameleon */
196 if ( !chamctxt->mpi_outer_init ) {
197 MPI_Finalize();
198 }
199#endif
200
202 return CHAMELEON_SUCCESS;
203}
204
216{
217 CHAM_context_t *chamctxt = chameleon_context_self();
218 if ( chamctxt == NULL ) {
219 return 0;
220 }
221 else {
222 return 1;
223 }
224}
225
238{
239 CHAM_context_t *chamctxt = chameleon_context_self();
240 if (chamctxt == NULL) {
241 chameleon_error("CHAMELEON_Pause", "CHAMELEON not initialized");
242 return CHAMELEON_ERR_NOT_INITIALIZED;
243 }
244 if ( chamctxt->runtime_paused ) {
245 chameleon_warning("CHAMELEON_Pause", "CHAMELEON already paused");
246 return CHAMELEON_SUCCESS;
247 }
248 chamctxt->runtime_paused = CHAMELEON_TRUE;
249 RUNTIME_pause(chamctxt);
250 return CHAMELEON_SUCCESS;
251}
252
266{
267 CHAM_context_t *chamctxt = chameleon_context_self();
268 if (chamctxt == NULL) {
269 chameleon_error("CHAMELEON_Resume", "CHAMELEON not initialized");
270 return CHAMELEON_ERR_NOT_INITIALIZED;
271 }
272 if ( !chamctxt->runtime_paused ) {
273 chameleon_warning("CHAMELEON_Resume", "CHAMELEON was already resumed");
274 return CHAMELEON_SUCCESS;
275 }
276 chamctxt->runtime_paused = CHAMELEON_FALSE;
277 RUNTIME_resume(chamctxt);
278 return CHAMELEON_SUCCESS;
279}
280
293{
294 CHAM_context_t *chamctxt = chameleon_context_self();
295 if (chamctxt == NULL) {
296 chameleon_error("CHAMELEON_Finalize", "CHAMELEON not initialized");
297 return CHAMELEON_ERR_NOT_INITIALIZED;
298 }
299 RUNTIME_barrier( chamctxt );
300 return CHAMELEON_SUCCESS;
301}
302
315{
316 CHAM_context_t *chamctxt = chameleon_context_self();
317 if (chamctxt == NULL) {
318 chameleon_error("CHAMELEON_Finalize", "CHAMELEON not initialized");
319 return CHAMELEON_ERR_NOT_INITIALIZED;
320 }
321 RUNTIME_barrier( chamctxt );
322 return CHAMELEON_SUCCESS;
323}
324
338{
339 CHAM_context_t *chamctxt = chameleon_context_self();
340 if (chamctxt == NULL) {
341 chameleon_error("CHAMELEON_Comm_size", "CHAMELEON not initialized");
342 return -1;
343 }
344
345 return RUNTIME_comm_size( chamctxt );
346}
347
361{
362 CHAM_context_t *chamctxt = chameleon_context_self();
363 if (chamctxt == NULL) {
364 chameleon_error("CHAMELEON_Comm_rank", "CHAMELEON not initialized");
365 return -1;
366 }
367
368 return RUNTIME_comm_rank( chamctxt );
369}
370
384{
385 CHAM_context_t *chamctxt = chameleon_context_self();
386 if (chamctxt == NULL) {
387 chameleon_error("CHAMELEON_GetThreadNbr", "CHAMELEON not initialized");
388 return -1;
389 }
390
391 return RUNTIME_thread_size( chamctxt );
392}
void chameleon_error(const char *func_name, const char *msg_text)
Definition auxiliary.c:101
void chameleon_warning(const char *func_name, const char *msg_text)
Definition auxiliary.c:74
void chameleon_fatal_error(const char *func_name, const char *msg_text)
Definition auxiliary.c:119
CHAM_context_t * chameleon_context_self()
Definition context.c:169
CHAM_context_t * chameleon_context_create()
Definition context.c:112
int chameleon_context_destroy()
Definition context.c:177
int CHAMELEON_Resume(void)
Definition control.c:265
int CHAMELEON_Comm_rank()
Definition control.c:360
int __chameleon_init(int cores, int gpus)
Initialize CHAMELEON with number of cpus and gpus (using MPI_COMM_WORLD).
Definition control.c:54
int CHAMELEON_Comm_size()
Definition control.c:337
int CHAMELEON_Distributed_stop(void)
Definition control.c:314
int __chameleon_initparcomm(int ncpus, int ngpus, int nthreads_per_worker, MPI_Comm comm)
Initialize CHAMELEON with number of cpus and gpus and threads per worker and using a given MPI commun...
Definition control.c:113
int CHAMELEON_GetThreadNbr()
Definition control.c:383
int __chameleon_initpar(int ncpus, int ngpus, int nthreads_per_worker)
Initialize CHAMELEON with number of cpus and gpus and threads per worker (using MPI_COMM_WORLD).
Definition control.c:82
int CHAMELEON_Distributed_start(void)
Definition control.c:292
int __chameleon_finalize(void)
Finalize CHAMELEON.
Definition control.c:175
int CHAMELEON_Pause(void)
Definition control.c:237
int CHAMELEON_Initialized(void)
Check if the CHAMELEON library is initialized or not.
Definition control.c:215