10 #define _XOPEN_SOURCE 700
20 #include "sion_const.h"
21 #include "sion_debug.h"
22 #include "sion_enums.h"
23 #include "sion_error_handler.h"
24 #include "sion_flags.h"
25 #include "sion_generic.h"
26 #include "sion_generic_internal.h"
27 #include "sion_internal.h"
29 #include "sion_mpi_cb_gen.h"
30 #include "sion_mpi_internal_gen.h"
32 int _sion_mpi_api_aid = -1;
38 DPRINTFP((1,
"sion_parclose_mpi", _SION_DEFAULT_RANK,
"enter parallel close of sid %d\n", sid));
42 DPRINTFP((1,
"sion_parclose_mpi", _SION_DEFAULT_RANK,
"leave parallel close of sid %d rc=%d\n", sid, rc));
47 int sion_parreinit_mpi(
int sid, int64_t chunksize)
51 DPRINTFP((1,
"sion_parreinit_mpi", _SION_DEFAULT_RANK,
"enter parallel reinit of sid %d\n", sid));
53 rc = sion_generic_parreinit(sid, chunksize);
55 DPRINTFP((1,
"sion_parreinit_mpi", _SION_DEFAULT_RANK,
"leave parallel reinit of sid %d rc=%d\n", sid, rc));
60 int sion_paropen_mapped_mpi(
char *fname,
const char *file_mode,
int *numFiles, MPI_Comm gComm,
int *nlocaltasks,
61 int **globalranks, int64_t **chunksizes,
int **mapping_filenrs,
int **mapping_lranks, int32_t *fsblksize, FILE **fileptr)
64 _sion_flags_store *flags_store = _sion_parse_flags(file_mode);
66 return _sion_errorprint_mpi(SION_ID_NOT_VALID, _SION_ERROR_RETURN,
67 "sion_paropen_mapped_mpi: could not parse file mode in %s, aborting ...\n", file_mode);
69 sid = _sion_paropen_mapped_mpi(fname, flags_store, numFiles, gComm, nlocaltasks, globalranks, chunksizes, mapping_filenrs,
70 mapping_lranks, fsblksize, fileptr);
71 _sion_flags_destroy_store(&flags_store);
75 int _sion_paropen_mapped_mpi(
char *fname,
const _sion_flags_store *flags_store,
int *numFiles, MPI_Comm gComm,
int *nlocaltasks,
76 int **globalranks, int64_t **chunksizes,
int **mapping_filenrs,
int **mapping_lranks, int32_t *fsblksize, FILE **fileptr)
78 int sid = SION_ID_UNDEF;
80 _mpi_api_commdata *gen_gcomm;
82 MPI_Comm_size(gComm, >asks);
83 MPI_Comm_rank(gComm, &gRank);
85 DPRINTFP((1,
"sion_paropen_mapped_mpi", gRank,
"enter parallel open of file %s\n", fname));
88 if (numFiles == NULL) {
89 return _sion_errorprint_mpi(SION_ID_NOT_VALID, _SION_ERROR_RETURN,
"sion_paropen_mapped_mpi: No numFiles variable given");
93 if (_sion_mpi_api_aid < 0) {
94 _sion_mpi_api_aid = _sion_register_callbacks_mpi();
97 if (flags_store->mask & _SION_FMODE_WRITE) {
100 if (*numFiles <= 0) {
101 return _sion_errorprint_mpi(SION_ID_NOT_VALID, _SION_ERROR_RETURN,
102 "sion_paropen_mapped_mpi: numFiles variable <= 0 not allowed for mapped files in write mode");
104 }
else if (flags_store->mask & _SION_FMODE_READ) {
109 return _sion_errorprint_mpi(SION_ID_NOT_VALID, _SION_ERROR_RETURN,
"sion_paropen_mapped_mpi: unknown file mode");
113 gen_gcomm = malloc(
sizeof(_mpi_api_commdata));
114 if (gen_gcomm == NULL) {
115 return _sion_errorprint(SION_ID_NOT_VALID, _SION_ERROR_RETURN,
116 "cannot allocate mpi internal data structure of size %lu (_mpi_api_commdata), aborting ...\n",
117 (
unsigned long)
sizeof(_mpi_api_commdata));
119 gen_gcomm->comm = gComm;
120 gen_gcomm->commset = 1;
121 gen_gcomm->local = 0;
122 gen_gcomm->rank = gRank;
123 gen_gcomm->size = gtasks;
124 gen_gcomm->lcommgroup = NULL;
129 (1,
"sion_paropen_mapped_mpi", gRank,
"enter parallel open of %d files (current name %s) (sid=%d)\n", *numFiles, fname, sid));
130 sid = _sion_generic_paropen_mapped(_sion_mpi_api_aid, fname, flags_store, numFiles, gen_gcomm, gRank, gtasks, nlocaltasks,
131 globalranks, chunksizes, mapping_filenrs, mapping_lranks, fsblksize, fileptr);
135 (1,
"sion_paropen_mapped_mpi", gRank,
"leave parallel open of %d files #tasks=%d sid=%d\n", *numFiles, *nlocaltasks, sid));
138 if (sid == SION_ID_NOT_VALID) {
139 return _sion_errorprint_mpi(
140 SION_ID_NOT_VALID, _SION_ERROR_RETURN,
"sion_paropen_mapped_mpi: invalid return code from internal open %d", sid);
143 DPRINTFP((1,
"sion_paropen_mapped_mpi", gRank,
"leave parallel open of file %s sid=%d\n", fname, sid));
148 int sion_paropen_mapped_mpi_with_options(
const char *filename,
sion_open_mode mode,
int numfiles, MPI_Comm gcomm,
int ntasks,
149 const int *globalranks,
const int *filenumbers,
const int *localranks,
const sion_mpi_mapped_options *options_)
154 MPI_Comm_size(gcomm, &size);
155 MPI_Comm_rank(gcomm, &rank);
157 DPRINTFP((1,
"sion_paropen_mapped_mpi", rank,
"enter parallel open of file %s\n", filename));
160 if (_sion_mpi_api_aid < 0) {
161 _sion_mpi_api_aid = _sion_register_callbacks_mpi();
168 return _sion_errorprint_mpi(SION_ID_NOT_VALID, _SION_ERROR_RETURN,
169 "sion_paropen_mapped_mpi: numfiles variable <= 0 not allowed for mapped files in write mode");
176 return _sion_errorprint_mpi(SION_ID_NOT_VALID, _SION_ERROR_RETURN,
"sion_paropen_mapped_mpi: unknown file mode");
180 _mpi_api_commdata *gen_gcomm = malloc(
sizeof(_mpi_api_commdata));
181 if (gen_gcomm == NULL) {
182 return _sion_errorprint(SION_ID_NOT_VALID, _SION_ERROR_RETURN,
183 "cannot allocate mpi internal data structure of size %lu (_mpi_api_commdata), aborting ...\n",
184 (
unsigned long)
sizeof(_mpi_api_commdata));
186 *gen_gcomm = (_mpi_api_commdata){.comm = gcomm, .commset = 1, .local = 0, .rank = rank, .size = size, .lcommgroup = NULL};
190 DPRINTFP((1,
"sion_paropen_mapped_mpi", rank,
"enter parallel open of %d files (current name %s)\n", numfiles, filename));
191 int sid = sion_generic_paropen_mapped_with_options(_sion_mpi_api_aid, filename, mode, numfiles, gen_gcomm, rank, size, ntasks,
192 globalranks, filenumbers, localranks, &options.generic_options);
195 DPRINTFP((1,
"sion_paropen_mapped_mpi", rank,
"leave parallel open of %d files #tasks=%d sid=%d\n", numfiles, ntasks, sid));
198 if (sid == SION_ID_NOT_VALID) {
199 return _sion_errorprint_mpi(
200 SION_ID_NOT_VALID, _SION_ERROR_RETURN,
"sion_paropen_mapped_mpi: invalid return code from internal open %d", sid);
203 DPRINTFP((1,
"sion_paropen_mapped_mpi", rank,
"leave parallel open of file %s sid=%d\n", filename, sid));
208 int sion_parclose_mapped_mpi(
int sid)
212 DPRINTFP((1,
"sion_parclose_mapped_mpi", _SION_DEFAULT_RANK,
"enter parallel close of sid %d\n", sid));
214 rc = sion_generic_parclose_mapped(sid);
216 DPRINTFP((1,
"sion_parclose_mapped_mpi", _SION_DEFAULT_RANK,
"leave parallel close of sid %d rc=%d\n", sid, rc));
225 *options = SION_MPI_OPTIONS_INIT;
247 options->multifile_mode = _SION_MPI_MULTIFILE_NUMBER;
248 options->multifile.number = multifile_number;
253 options->multifile_mode = _SION_MPI_MULTIFILE_COMMUNICATOR;
254 options->multifile.communicator = multifile_communicator;
301 *options = SION_MPI_MAPPED_OPTIONS_INIT;
341 MPI_Comm_size(communicator, &gsize);
342 MPI_Comm_rank(communicator, &grank);
344 DPRINTFP((1,
"sion_paropen_mpi", grank,
"enter parallel open of file %s\n", filename));
347 if (_sion_mpi_api_aid < 0) {
348 _sion_mpi_api_aid = _sion_register_callbacks_mpi();
352 int nfiles, filenumber, lrank, lsize;
354 switch (options.multifile_mode) {
356 case _SION_MPI_MULTIFILE_COMMUNICATOR:
357 lcomm = options.multifile.communicator;
358 rc = _sion_get_info_from_splitted_comm_mpi(communicator, lcomm, &nfiles, &filenumber, &lrank, &lsize);
359 if (rc != SION_SUCCESS) {
360 return _sion_errorprint_mpi(
361 SION_ID_NOT_VALID, _SION_ERROR_RETURN,
"sion_paropen_mpi: error in _sion_get_info_from_splitted_comm_mpi");
363 DPRINTFP((1,
"sion_paropen_mpi", grank,
"%d local communicators found\n", nfiles));
365 case _SION_MPI_MULTIFILE_NUMBER:
367 nfiles = options.multifile.number;
368 rc = _sion_gen_info_from_gcomm_mpi(nfiles, communicator, &filenumber, &lrank, &lsize);
369 if (rc != SION_SUCCESS) {
370 return _sion_errorprint_mpi(
371 SION_ID_NOT_VALID, _SION_ERROR_RETURN,
"sion_paropen_mpi: error in _sion_gen_info_from_gcomm_mpi");
373 DPRINTFP((1,
"sion_paropen_mpi", grank,
"Global communicator divided in %d local communicators\n", nfiles));
376 if (options.generic_options.buddylevel > 0) {
379 assert(options.multifile_mode == _SION_MPI_MULTIFILE_COMMUNICATOR);
380 lcomm = options.multifile.communicator;
381 int rc = _sion_get_info_from_splitted_comm_mpi(communicator, lcomm, &nfiles, &filenumber, &lrank, &lsize);
382 if (rc != SION_SUCCESS) {
383 return _sion_errorprint_mpi(
384 SION_ID_NOT_VALID, _SION_ERROR_RETURN,
"sion_paropen_mpi: error in _sion_get_info_from_splitted_comm_mpi");
386 DPRINTFP((1,
"sion_paropen_mpi", grank,
"%d local communicators found\n", nfiles));
391 return _sion_errorprint_mpi(SION_ID_NOT_VALID, _SION_ERROR_RETURN,
"sion_paropen_mpi: unknown file mode");
395 _mpi_api_commdata *gen_gcomm = malloc(
sizeof(_mpi_api_commdata));
397 return _sion_errorprint(SION_ID_NOT_VALID, _SION_ERROR_RETURN,
398 "cannot allocate mpi internal data structure of size %lu (_mpi_api_commdata), aborting ...\n",
399 (
unsigned long)
sizeof(_mpi_api_commdata));
401 gen_gcomm->comm = communicator;
402 gen_gcomm->commset = 1;
403 gen_gcomm->local = 0;
404 gen_gcomm->rank = grank;
405 gen_gcomm->size = gsize;
406 gen_gcomm->lcommgroup = NULL;
410 DPRINTFP((1,
"sion_paropen_mpi", grank,
"enter parallel open of %d files (current name %s)\n", nfiles, filename));
412 _sion_mpi_api_aid, filename, mode, gen_gcomm, grank, gsize, filenumber, nfiles, lrank, lsize, &options.generic_options);
415 DPRINTFP((1,
"sion_paropen_mpi", grank,
"leave parallel open of %d files #tasks=%d sid=%d\n", nfiles, lsize, sid));
418 if (sid == SION_ID_NOT_VALID) {
419 return _sion_errorprint_mpi(
420 SION_ID_NOT_VALID, _SION_ERROR_RETURN,
"sion_paropen_mpi: invalid return code from internal open %d", sid);
423 DPRINTFP((1,
"sion_paropen_mpi", grank,
"leave parallel open of file %s sid=%d\n", filename, sid));
sion_open_mode
specifies for what type of access to open a file
sion_lowlevel_api
specifies a low-level API to use for file system access
sion_endianness
declares the endianness of user data written to a file
sion_keyval_mode
specifies whether to use SIONlib's key-value mechanism for accessing file content and if so in what m...
@ SION_OPEN_WRITE
open the file for writing only
@ SION_OPEN_READ
open the file for reading only
void sion_generic_mapped_options_set_endianness(sion_generic_mapped_options *options, sion_endianness endianness)
Set the endianness for the contents of a container.
void sion_generic_options_set_collective_size(sion_generic_options *options, int32_t size)
Enable collective I/O.
void sion_generic_options_set_fsblksize(sion_generic_options *options, int32_t fsblksize)
Set the file system block size to assume.
void sion_generic_mapped_options_set_lowlevel_api(sion_generic_mapped_options *options, sion_lowlevel_api lowlevel_api)
Set the low-level API to use for opening a container.
void sion_generic_mapped_options_set_chunksizes(sion_generic_mapped_options *options, int64_t *chunksizes)
Set the chunk size of all logical files opened by a task.
void sion_generic_options_set_collective_merge(sion_generic_options *options)
Use collective merging.
int sion_generic_paropen(int aid, const char *fname, sion_open_mode mode, void *gcommgroup, int grank, int gsize, int filenumber, int numfiles, int lrank, int lsize, const sion_generic_options *options_)
Open a SIONlib file through a generic interface.
void sion_generic_options_set_endianness(sion_generic_options *options, sion_endianness endianness)
Set the endianness for the contents of a container.
void sion_generic_options_set_chunksize(sion_generic_options *options, int64_t chunksize)
Set the chunk size of a logical file in the container.
void sion_generic_options_set_buddylevel(sion_generic_options *options, int32_t buddylevel)
Enable buddy checkpointing mechanism.
void sion_generic_mapped_options_set_fsblksize(sion_generic_mapped_options *options, int32_t fsblksize)
Set the file system block size to assume.
void sion_generic_options_set_lowlevel_api(sion_generic_options *options, sion_lowlevel_api lowlevel_api)
Set the low-level API to use for opening a container.
void sion_generic_mapped_options_set_keyval_mode(sion_generic_mapped_options *options, sion_keyval_mode keyval_mode)
Set the key-value mode to use for a container.
void sion_generic_options_set_keyval_mode(sion_generic_options *options, sion_keyval_mode keyval_mode)
Set the key-value mode to use for a container.
int sion_generic_parclose(int sid)
Close a SIONlib file.
void sion_mpi_mapped_options_set_lowlevel_api(sion_mpi_mapped_options *options, sion_lowlevel_api lowlevel_api)
Set the low-level API to use for opening a container.
void sion_mpi_mapped_options_set_endianness(sion_mpi_mapped_options *options, sion_endianness endianness)
Set the endianness for the contents of a container.
int sion_paropen_mpi(const char *filename, sion_open_mode mode, MPI_Comm communicator, const sion_mpi_options *options_)
Open a SIONlib file from multiple MPI processes.
void sion_mpi_mapped_options_delete(sion_mpi_mapped_options *options)
Delete an instance of sion_mpi_mapped_options
void sion_mpi_options_set_lowlevel_api(sion_mpi_options *options, sion_lowlevel_api lowlevel_api)
Set the low-level API to use for opening a container.
void sion_mpi_options_set_buddy(sion_mpi_options *options)
Enable buddy checkpointing mechanism.
void sion_mpi_mapped_options_set_fsblksize(sion_mpi_mapped_options *options, int32_t fsblksize)
Set the file system block size to assume.
sion_mpi_mapped_options * sion_mpi_mapped_options_new()
Allocates and initializes an instance of sion_mpi_mapped_options
void sion_mpi_options_set_multifile_communicator(sion_mpi_options *options, MPI_Comm multifile_communicator)
Create multiple physical files based on disjunct communicators.
void sion_mpi_mapped_options_set_keyval_mode(sion_mpi_mapped_options *options, sion_keyval_mode keyval_mode)
Set the key-value mode to use for a container.
void sion_mpi_options_set_chunksize(sion_mpi_options *options, int64_t chunksize)
Set the chunk size of a logical file in the container.
void sion_mpi_options_set_fsblksize(sion_mpi_options *options, int32_t fsblksize)
Set the file system block size to assume.
sion_mpi_options * sion_mpi_options_new()
Allocates and initializes an instance of sion_mpi_options
void sion_mpi_options_delete(sion_mpi_options *options)
Delete an instance of sion_mpi_options
void sion_mpi_options_set_collective_merge(sion_mpi_options *options)
Use collective merging.
struct sion_mpi_options sion_mpi_options
Holds non-essential arguments for sion_paropen_mpi().
void sion_mpi_mapped_options_set_chunksizes(sion_mpi_mapped_options *options, int64_t *chunksizes)
Set the chunk size of all logical files opened by a task.
void sion_mpi_options_set_collective_size(sion_mpi_options *options, int32_t size)
Enable collective I/O.
void sion_mpi_options_set_collective(sion_mpi_options *options)
Enable collective I/O.
struct sion_mpi_mapped_options sion_mpi_mapped_options
Holds non-essential arguments for sion_paropen_mapped_mpi().
void sion_mpi_options_set_endianness(sion_mpi_options *options, sion_endianness endianness)
Set the endianness for the contents of a container.
int sion_parclose_mpi(int sid)
Close a SIONlib file using MPI.
void sion_mpi_options_set_keyval_mode(sion_mpi_options *options, sion_keyval_mode keyval_mode)
Set the key-value mode to use for a container.
void sion_mpi_options_set_buddylevel(sion_mpi_options *options, int32_t buddylevel)
Enable buddy checkpointing mechanism.
void sion_mpi_options_set_multifile_number(sion_mpi_options *options, int multifile_number)
Set the number of physical files to use.