15 #define _XOPEN_SOURCE 700
25 #include <sys/types.h>
34 #include "sion_error_handler.h"
50 int _sion_mpi_api_aid = -1;
86 const char* file_mode,
89 const MPI_Comm* lComm,
90 sion_int64* chunksize,
91 sion_int32* fsblksize,
97 int rc = SION_NOT_SUCCESS, sid = SION_ID_UNDEF;
98 int filenumber, gtasks, gRank, lRank, lSize;
104 MPI_Comm_size(gComm, >asks);
105 MPI_Comm_rank(gComm, &gRank);
107 DPRINTFP((1,
"sion_paropen_mpi", gRank,
"enter parallel open of file %s\n", fname));
111 return(_sion_errorprint_mpi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_mpi: No lComm variable given"));
113 if (numFiles == NULL) {
114 return(_sion_errorprint_mpi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_mpi: No numFiles variable given"));
119 if ( ! flags_store ) {
120 return(_sion_errorprint_mpi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_mpi: could not parse file mode in %s, aborting ...\n", file_mode));
124 if(_sion_mpi_api_aid<0) _sion_mpi_api_aid=_sion_register_callbacks_mpi();
127 if (flags_store->mask&_SION_FMODE_WRITE) {
130 if (*numFiles <= 0) {
132 if (_sion_flags_get(flags_store,
"collmsa")) {
133 _sion_flags_destroy_store(&flags_store);
134 return _sion_errorprint_mpi(SION_ID_NOT_VALID, _SION_ERROR_RETURN,
"sion_paropen_mpi: numFiles <= 0 not supported with MSA aware collectives enabled");
137 rc = _sion_get_info_from_splitted_comm_mpi(gComm, *lComm, numFiles, &filenumber, &lRank, &lSize);
138 if(rc != SION_SUCCESS) {
139 _sion_flags_destroy_store(&flags_store);
140 return(_sion_errorprint_mpi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_mpi: error in _sion_get_info_from_splitted_comm_mpi"));
142 DPRINTFP((1,
"sion_paropen_mpi", gRank,
"%d local communicators found\n", *numFiles));
146 if (_sion_flags_get(flags_store,
"collmsa")) {
153 if(rc != SION_SUCCESS) {
154 _sion_flags_destroy_store(&flags_store);
155 return(_sion_errorprint_mpi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_mpi: error in _sion_gen_info_from_gcomm_mpi"));
157 DPRINTFP((1,
"sion_paropen_mpi", gRank,
"Global communicator divided in %d local communicators\n", *numFiles));
163 }
else if (flags_store->mask&_SION_FMODE_READ) {
173 if(! (flags_store->mask&_SION_FMODE_BUDDY) ) {
177 rc = _sion_get_info_from_splitted_comm_mpi(gComm, *lComm, numFiles, &filenumber, &lRank, &lSize);
178 if(rc != SION_SUCCESS)
return(_sion_errorprint_mpi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_mpi: error in _sion_get_info_from_splitted_comm_mpi"));
179 DPRINTFP((1,
"sion_paropen_mpi", gRank,
"%d local communicators found\n", *numFiles));
184 _sion_flags_destroy_store(&flags_store);
185 return(_sion_errorprint_mpi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_mpi: unknown file mode"));
190 if (gen_gcomm == NULL) {
191 _sion_flags_destroy_store(&flags_store);
192 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate mpi internal data structure of size %lu (_mpi_api_commdata), aborting ...\n",
195 gen_gcomm->comm=gComm;
196 gen_gcomm->commset=1;
198 gen_gcomm->rank=gRank;
199 gen_gcomm->size=gtasks;
200 gen_gcomm->lcommgroup=NULL;
202 _sion_flags_destroy_store(&flags_store);
204 DPRINTFP((1,
"sion_paropen_mpi", gRank,
"enter parallel open of %d files (current name %s) in %s mode\n", *numFiles, fname, file_mode));
205 sid =
sion_generic_paropen(_sion_mpi_api_aid, fname, file_mode, chunksize, fsblksize, gen_gcomm, gRank, gtasks, &filenumber, numFiles, &lRank, &lSize,
207 DPRINTFP((1,
"sion_paropen_mpi", gRank,
"leave parallel open of %d files in %s mode #tasks=%d sid=%d\n", *numFiles, file_mode, lSize, sid));
210 if ( sid == SION_ID_NOT_VALID ) {
211 return(_sion_errorprint_mpi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_mpi: invalid return code from internal open %d", rc));
214 DPRINTFP((1,
"sion_paropen_mpi", gRank,
"leave parallel open of file %s sid=%d\n", fname, sid));
234 DPRINTFP((1,
"sion_parclose_mpi", _SION_DEFAULT_RANK,
"enter parallel close of sid %d\n", sid));
236 rc = sion_generic_parclose(sid);
238 DPRINTFP((1,
"sion_parclose_mpi", _SION_DEFAULT_RANK,
"leave parallel close of sid %d rc=%d\n", sid, rc));
243 int sion_parreinit_mpi(
int sid,
244 sion_int64 chunksize )
248 DPRINTFP((1,
"sion_parreinit_mpi", _SION_DEFAULT_RANK,
"enter parallel reinit of sid %d\n", sid));
250 rc = sion_generic_parreinit(sid, chunksize);
252 DPRINTFP((1,
"sion_parreinit_mpi", _SION_DEFAULT_RANK,
"leave parallel reinit of sid %d rc=%d\n", sid, rc));
257 int sion_paropen_mapped_mpi(
char *fname,
258 const char *file_mode,
263 sion_int64 **chunksizes,
264 int **mapping_filenrs,
265 int **mapping_lranks,
266 sion_int32 *fsblksize,
269 int sid=SION_ID_UNDEF;
275 MPI_Comm_size(gComm, >asks);
276 MPI_Comm_rank(gComm, &gRank);
278 DPRINTFP((1,
"sion_paropen_mapped_mpi", gRank,
"enter parallel open of file %s\n", fname));
281 if (numFiles == NULL) {
282 return(_sion_errorprint_mpi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_mapped_mpi: No numFiles variable given"));
285 lprefix = calloc(SION_FILENAME_LENGTH,1);
286 if (lprefix == NULL) {
287 return(_sion_errorprint_mpi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_mapped_mpi: cannot allocate temporary memory of size %lu (lprefix), aborting ...\n", (
unsigned long) SION_FILENAME_LENGTH));
291 if ( ! flags_store ) {
293 return(_sion_errorprint_mpi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_mapped_mpi: could not parse file mode in %s, aborting ...\n", file_mode));
297 if(_sion_mpi_api_aid<0) _sion_mpi_api_aid=_sion_register_callbacks_mpi();
299 if (flags_store->mask&_SION_FMODE_WRITE) {
302 if (*numFiles <= 0) {
303 _sion_flags_destroy_store(&flags_store);
305 return(_sion_errorprint_mpi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_mapped_mpi: numFiles variable <= 0 not allowed for mapped files in write mode"));
309 strcpy(lprefix, fname);
312 else if (flags_store->mask&_SION_FMODE_READ) {
317 _sion_flags_destroy_store(&flags_store);
319 return(_sion_errorprint_mpi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_mapped_mpi: unknown file mode"));
321 _sion_flags_destroy_store(&flags_store);
325 if (gen_gcomm == NULL) {
327 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate mpi internal data structure of size %lu (_mpi_api_commdata), aborting ...\n",
330 gen_gcomm->comm=gComm;
331 gen_gcomm->commset=1;
333 gen_gcomm->rank=gRank;
334 gen_gcomm->size=gtasks;
335 gen_gcomm->lcommgroup=NULL;
338 DPRINTFP((1,
"sion_paropen_mapped_mpi", gRank,
"enter parallel open of %d files (current name %s) in %s mode (sid=%d)\n", *numFiles, fname, file_mode, sid));
339 sid=sion_generic_paropen_mapped(_sion_mpi_api_aid, fname, file_mode, numFiles, gen_gcomm, gRank, gtasks, nlocaltasks, globalranks, chunksizes,
340 mapping_filenrs, mapping_lranks, fsblksize, fileptr);
341 DPRINTFP((1,
"sion_paropen_mapped_mpi", gRank,
"leave parallel open of %d files in %s mode #tasks=%d sid=%d\n", *numFiles, file_mode, *nlocaltasks, sid));
344 if ( sid == SION_ID_NOT_VALID ) {
346 return(_sion_errorprint_mpi(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_mapped_mpi: invalid return code from internal open %d", sid));
349 if(lprefix) free(lprefix);
350 DPRINTFP((1,
"sion_paropen_mapped_mpi", gRank,
"leave parallel open of file %s sid=%d\n", fname, sid));
356 int sion_parclose_mapped_mpi(
int sid ) {
359 DPRINTFP((1,
"sion_parclose_mapped_mpi", _SION_DEFAULT_RANK,
"enter parallel close of sid %d\n", sid));
361 rc = sion_generic_parclose_mapped(sid);
363 DPRINTFP((1,
"sion_parclose_mapped_mpi", _SION_DEFAULT_RANK,
"leave parallel close of sid %d rc=%d\n", sid, rc));
_sion_flags_store * _sion_parse_flags(const char *flags)
Parse flags and return a flags store with key value pairs.
int sion_generic_paropen(int aid, const char *fname, const char *file_mode, sion_int64 *chunksize, sion_int32 *fsblksize, void *gcommgroup, int grank, int gsize, int *filenumber, int *numfiles, const int *lrank, const int *lsize, FILE **fileptr, char **newfname)
Open a sion file a generic interface.
int sion_paropen_mpi(const char *fname, const char *file_mode, int *numFiles, MPI_Comm gComm, const MPI_Comm *lComm, sion_int64 *chunksize, sion_int32 *fsblksize, int *globalrank, FILE **fileptr, char **newfname)
Open a sion file using MPI.
int sion_parclose_mpi(int sid)
Close a sion file using MPI.
int _sion_gen_info_from_gcomm_mpi(int numFiles, MPI_Comm gComm, int *filenumber, int *lrank, int *lsize)
Splits a Communicator in numfiles different communicators.