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_parclose_mapped_mpi(
int sid)
152 DPRINTFP((1,
"sion_parclose_mapped_mpi", _SION_DEFAULT_RANK,
"enter parallel close of sid %d\n", sid));
154 rc = sion_generic_parclose_mapped(sid);
156 DPRINTFP((1,
"sion_parclose_mapped_mpi", _SION_DEFAULT_RANK,
"leave parallel close of sid %d rc=%d\n", sid, rc));
165 *options = SION_MPI_OPTIONS_INIT;
187 options->multifile_mode = _SION_MPI_MULTIFILE_NUMBER;
188 options->multifile.number = multifile_number;
193 options->multifile_mode = _SION_MPI_MULTIFILE_COMMUNICATOR;
194 options->multifile.communicator = multifile_communicator;
242 MPI_Comm_size(communicator, &gsize);
243 MPI_Comm_rank(communicator, &grank);
245 DPRINTFP((1,
"sion_paropen_mpi", grank,
"enter parallel open of file %s\n", filename));
248 if (_sion_mpi_api_aid < 0) {
249 _sion_mpi_api_aid = _sion_register_callbacks_mpi();
253 int nfiles, filenumber, lrank, lsize;
255 switch (options.multifile_mode) {
257 case _SION_MPI_MULTIFILE_COMMUNICATOR:
258 lcomm = options.multifile.communicator;
259 rc = _sion_get_info_from_splitted_comm_mpi(communicator, lcomm, &nfiles, &filenumber, &lrank, &lsize);
260 if (rc != SION_SUCCESS) {
261 return _sion_errorprint_mpi(
262 SION_ID_NOT_VALID, _SION_ERROR_RETURN,
"sion_paropen_mpi: error in _sion_get_info_from_splitted_comm_mpi");
264 DPRINTFP((1,
"sion_paropen_mpi", grank,
"%d local communicators found\n", nfiles));
266 case _SION_MPI_MULTIFILE_NUMBER:
268 nfiles = options.multifile.number;
269 rc = _sion_gen_info_from_gcomm_mpi(nfiles, communicator, &filenumber, &lrank, &lsize);
270 if (rc != SION_SUCCESS) {
271 return _sion_errorprint_mpi(
272 SION_ID_NOT_VALID, _SION_ERROR_RETURN,
"sion_paropen_mpi: error in _sion_gen_info_from_gcomm_mpi");
274 DPRINTFP((1,
"sion_paropen_mpi", grank,
"Global communicator divided in %d local communicators\n", nfiles));
277 if (options.generic_options.buddylevel > 0) {
280 assert(options.multifile_mode == _SION_MPI_MULTIFILE_COMMUNICATOR);
281 lcomm = options.multifile.communicator;
282 int rc = _sion_get_info_from_splitted_comm_mpi(communicator, lcomm, &nfiles, &filenumber, &lrank, &lsize);
283 if (rc != SION_SUCCESS) {
284 return _sion_errorprint_mpi(
285 SION_ID_NOT_VALID, _SION_ERROR_RETURN,
"sion_paropen_mpi: error in _sion_get_info_from_splitted_comm_mpi");
287 DPRINTFP((1,
"sion_paropen_mpi", grank,
"%d local communicators found\n", nfiles));
292 return _sion_errorprint_mpi(SION_ID_NOT_VALID, _SION_ERROR_RETURN,
"sion_paropen_mpi: unknown file mode");
296 _mpi_api_commdata *gen_gcomm = malloc(
sizeof(_mpi_api_commdata));
298 return _sion_errorprint(SION_ID_NOT_VALID, _SION_ERROR_RETURN,
299 "cannot allocate mpi internal data structure of size %lu (_mpi_api_commdata), aborting ...\n",
300 (
unsigned long)
sizeof(_mpi_api_commdata));
302 gen_gcomm->comm = communicator;
303 gen_gcomm->commset = 1;
304 gen_gcomm->local = 0;
305 gen_gcomm->rank = grank;
306 gen_gcomm->size = gsize;
307 gen_gcomm->lcommgroup = NULL;
311 DPRINTFP((1,
"sion_paropen_mpi", grank,
"enter parallel open of %d files (current name %s)\n", nfiles, filename));
313 _sion_mpi_api_aid, filename, mode, gen_gcomm, grank, gsize, filenumber, nfiles, lrank, lsize, &options.generic_options);
316 DPRINTFP((1,
"sion_paropen_mpi", grank,
"leave parallel open of %d files #tasks=%d sid=%d\n", nfiles, lsize, sid));
319 if (sid == SION_ID_NOT_VALID) {
320 return _sion_errorprint_mpi(
321 SION_ID_NOT_VALID, _SION_ERROR_RETURN,
"sion_paropen_mpi: invalid return code from internal open %d", sid);
324 DPRINTFP((1,
"sion_paropen_mpi", grank,
"leave parallel open of file %s sid=%d\n", filename, sid));
sion_lowlevel_api
specifies a low-level API to use for file system access
sion_mpi_options * sion_mpi_options_new()
Allocates and initializes an instance of sion_mpi_options
void sion_mpi_options_set_collective(sion_mpi_options *options)
Enable collective I/O.
void sion_mpi_options_set_buddy(sion_mpi_options *options)
Enable buddy checkpointing mechanism.
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_collective_size(sion_generic_options *options, int32_t size)
Enable collective I/O.
void sion_mpi_options_set_collective_size(sion_mpi_options *options, int32_t size)
Enable collective I/O.
void sion_mpi_options_delete(sion_mpi_options *options)
Delete an instance of sion_mpi_options
void sion_mpi_options_set_chunksize(sion_mpi_options *options, int64_t chunksize)
Set the chunk size of a logical file in the 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_options_set_fsblksize(sion_mpi_options *options, int32_t fsblksize)
Set the file system block size to assume.
void sion_generic_options_set_collective_merge(sion_generic_options *options)
Use collective merging.
void sion_generic_options_set_endianness(sion_generic_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_generic_options_set_keyval_mode(sion_generic_options *options, sion_keyval_mode keyval_mode)
Set the key-value mode to use for a container.
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_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_generic_options_set_fsblksize(sion_generic_options *options, int32_t fsblksize)
Set the file system block size to assume.
void sion_generic_options_set_chunksize(sion_generic_options *options, int64_t chunksize)
Set the chunk size of a logical file in the container.
open the file for reading only
void sion_mpi_options_set_endianness(sion_mpi_options *options, sion_endianness endianness)
Set the endianness for the contents of a container.
sion_keyval_mode
specifies whether to use SIONlib's key-value mechanism for accessing file content and if so in what m...
void sion_mpi_options_set_multifile_number(sion_mpi_options *options, int multifile_number)
Set the number of physical files to use.
int sion_generic_parclose(int sid)
Close a SIONlib file.
sion_endianness
declares the endianness of user data written to a file
sion_open_mode
specifies for what type of access to open a file
void sion_generic_options_set_buddylevel(sion_generic_options *options, int32_t buddylevel)
Enable buddy checkpointing mechanism.
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.
open the file for writing only
void sion_mpi_options_set_collective_merge(sion_mpi_options *options)
Use collective merging.
void sion_mpi_options_set_buddylevel(sion_mpi_options *options, int32_t buddylevel)
Enable buddy checkpointing mechanism.
struct sion_mpi_options sion_mpi_options
Holds non-essential arguments for sion_paropen_mpi().
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.