22 #define _XOPEN_SOURCE 700
25 #if defined(_SION_MSA_HOSTNAME_REGEX)
35 #include "sion_error_handler.h"
48 #include "sion_hints.h"
51 #include "sion_generic_buddy.h"
83 sion_int64 *chunksize,
84 sion_int32 *fsblksize,
101 sion_int64 lchunksize, lstartpointer, lglobalrank, new_fsblocksize, helpint64, apiflag;
102 sion_int64 *sion_tmpintfield = NULL;
103 sion_int32 *sion_tmpintfield_map = NULL, helpint32;
104 sion_int32 *sion_tmpintfield_buddy32 = NULL;
105 sion_int64 *sion_tmpintfield_buddy64 = NULL;
106 void *comm_group=NULL;
112 #if defined(_SION_SIONFWD)
113 else if (flags_store->mask&_SION_FMODE_SIONFWD) apiflag=SION_FILE_FLAG_SIONFWD;
115 #ifdef _SION_IME_NATIVE
116 else if (file_mode_flags&_SION_FMODE_IME_NATIVE) apiflag=SION_FILE_FLAG_IME_NATIVE;
120 DPRINTFP((2,
"_sion_paropen_generic_one_file", rank,
"enter parallel open of file %s in mode %d #tasks=%d\n", fname, (
int) flags_store->mask, ntasks));
121 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
"sizeof: int=%d long=%d longlong=%d sion_int32=%d sion_int64=%d\n",
sizeof(
int),
sizeof(
long),
122 sizeof(
long long),
sizeof(sion_int32),
sizeof(sion_int64)));
126 filenum = *filenumber;
129 if(flag& _SION_INTERNAL_FLAG_NORMAL ) comm_group=sion_gendata->comm_data_local;
130 if(flag& _SION_INTERNAL_FLAG_BUDDY_NORMAL ) comm_group=sion_gendata->comm_data_local;
131 if(flag& _SION_INTERNAL_FLAG_BUDDY_SEND ) comm_group=buddy_data->buddy_send.commgroup;
132 if(flag& _SION_INTERNAL_FLAG_BUDDY_COLL ) comm_group=buddy_data->buddy_coll.commgroup;
133 if(flag& _SION_INTERNAL_FLAG_BUDDY_READ ) comm_group=buddy_data->groups[buddy_data->currentgroup]->commgroup;
137 if (flag&_SION_INTERNAL_FLAG_BUDDY_SEND) do_open_file=0;
138 if ( (flag&_SION_INTERNAL_FLAG_BUDDY_COLL) && (rank>0) ) do_open_file=0;
139 if ( (flag&_SION_INTERNAL_FLAG_BUDDY_READ) && (rank>0) ) do_open_file=0;
141 DPRINTFP((2,
"_sion_paropen_generic_one_file", rank,
"do_open_file=%d\n", do_open_file));
144 if (sion_filedesc == NULL) {
145 _sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_ABORT,
"_sion_paropen_omp: cannot allocate filedescriptor structure of size %lu (sion_filedesc), aborting ...\n",
146 (
unsigned long)
sizeof(sion_filedesc));
149 sion_filedesc->
fname = strdup(fname);
152 sion_filedesc->
sid=sid;
159 if (flags_store->mask&_SION_FMODE_WRITE) {
162 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
" starting open for write #tasks=%d\n", ntasks));
166 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen: wrong number of tasks specific: ntasks=%d (<0), returning ...\n", (
int) ntasks));
170 if ((chunksize != NULL) && (*chunksize<0)) {
171 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen: ((chunksize != NULL) && (*chunksize<0)), returning ...\n"));
175 if ((flag & _SION_INTERNAL_FLAG_NORMAL ) && (globalrank != NULL) && (*globalrank<0)) {
176 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen: ((globalrank != NULL) && (*globalrank<0)), returning ...\n"));
184 sion_filedesc->
rank = rank;
186 sion_filedesc->
ntasks = ntasks;
187 sion_filedesc->
nfiles = nfiles;
189 sion_filedesc->
prefix = strdup(prefix);
190 sion_filedesc->
compress = flags_store->mask&_SION_FMODE_COMPRESS;
191 sion_filedesc->
usecoll = (flags_store->mask&_SION_FMODE_COLLECTIVE)>0;
192 sion_filedesc->
collmergemode = (flags_store->mask&_SION_FMODE_COLLECTIVE_MERGE)>0;
193 sion_filedesc->
collmsa = !!_sion_flags_get(flags_store,
"collmsa");
194 sion_filedesc->
usebuddy = (flags_store->mask&_SION_FMODE_BUDDY)>0;
196 sion_filedesc->
buddylevel = atoi(_sion_flags_get(flags_store,
"buddy")->val);
204 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_generic: cannot open %s for writing, aborting ...\n", fname));
209 if((new_fsblocksize<0) || (new_fsblocksize>SION_MAX_FSBLOCKSIZE)) new_fsblocksize=SION_DEFAULT_FSBLOCKSIZE;
213 sion_gendata->apidesc->barrier_cb(comm_group);
218 sion_gendata->apidesc->bcastr_cb(&new_fsblocksize, comm_group, _SION_INT64, 1, 0);
219 *fsblksize=new_fsblocksize;
222 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
"setting fsblksize to %lld\n", new_fsblocksize));
231 _sion_keyval_check_env(sion_filedesc, flags_store->mask);
233 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
keyvalmode, comm_group, _SION_INT32, 1, 0);
237 if ((flags_entry = _sion_flags_get(flags_store,
"collsize"))) {
238 sion_filedesc->
collsize = atoi(flags_entry->val);
240 _sion_coll_check_env(sion_filedesc);
244 ( flag&_SION_INTERNAL_FLAG_BUDDY_NORMAL )
245 || ( flag&_SION_INTERNAL_FLAG_BUDDY_SEND )
246 || ( flag&_SION_INTERNAL_FLAG_BUDDY_COLL )
256 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
usecoll, comm_group, _SION_INT32, 1, 0);
257 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
collsize, comm_group, _SION_INT32, 1, 0);
258 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
collmergemode, comm_group, _SION_INT32, 1, 0);
262 if(sion_gendata->apidesc->level!=SION_GENERIC_API_LEVEL_FULL) {
263 _sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_WARN,
"sion_paropen_generic: requested coalescing I/O but API does not support this mode, falling back to individual mode ...\n");
270 _sion_hints_check_env(sion_filedesc);
272 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
usehints, comm_group, _SION_INT32, 1, 0);
273 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
hinttype, comm_group, _SION_INT32, 1, 0);
275 DPRINTFTS(rank,
"before alloc");
281 DPRINTFTS(rank,
"after alloc");
284 lchunksize = (sion_int64) *chunksize;
285 lglobalrank = (sion_int64) *globalrank;
287 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
"lchunksize=%lld lglobalrank=%lld\n", lchunksize,lglobalrank));
289 DPRINTFTS2(rank,
"before gather");
290 sion_gendata->apidesc->gatherr_cb(&lchunksize, sion_filedesc->
all_chunksizes, comm_group, _SION_INT64, 1, 0);
291 sion_gendata->apidesc->gatherr_cb(&lglobalrank, sion_filedesc->
all_globalranks, comm_group, _SION_INT64, 1, 0);
295 sion_filedesc->
coll_capability=sion_gendata->apidesc->get_capability_cb(comm_group);
299 DPRINTFTS2(rank,
"after gather");
301 DPRINTFTS(rank,
"before calculate");
302 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
"chunksizes[%d - 1]=%ld\n", ntasks,(
long) sion_filedesc->
all_chunksizes[ntasks - 1]));
303 if (!sion_filedesc->
usecoll) _sion_calculate_startpointers(sion_filedesc);
305 if (sion_filedesc->
collmergemode) _sion_calculate_startpointers_collective_merge(sion_filedesc);
306 else if (sion_filedesc->
collmsa) _sion_calculate_startpointers_collective_msa(sion_filedesc);
307 else _sion_calculate_startpointers_collective(sion_filedesc);
309 DPRINTFTS(rank,
"after calculate");
312 DPRINTFTS(rank,
"before open");
319 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_generic: cannot open %s for writing, aborting ...\n", fname));
322 sion_filedesc->
fileptr = sion_fileptr;
324 sion_gendata->apidesc->barrier_cb(comm_group);
325 DPRINTFTS(rank,
"after open");
332 _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_METADATABLOCK1);
334 DPRINTFTS(rank,
"before writeh");
336 DPRINTFTS(rank,
"after writeh");
344 DPRINTFTS(rank,
"before setp(0)");
347 DPRINTFTS(rank,
"after setp(0)");
352 DPRINTFTS(rank,
"before scatter");
353 sion_gendata->apidesc->scatterr_cb(sion_filedesc->
all_startpointers, &sion_filedesc->
startpos, comm_group, _SION_INT64, 1, 0);
354 DPRINTFTS(rank,
"after scatter");
357 DPRINTFTS(rank,
"before scatter");
358 sion_gendata->apidesc->scatterr_cb(sion_filedesc->
all_chunksizes, &sion_filedesc->
chunksize, comm_group, _SION_INT64, 1, 0);
359 DPRINTFTS(rank,
"after scatter");
363 sion_gendata->apidesc->scatterr_cb(sion_filedesc->
all_coll_collsize, &sion_filedesc->
collsize, comm_group, _SION_INT32, 1, 0);
370 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
globalskip, comm_group, _SION_INT64, 1, 0);
372 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
" start position is %10lld %10.4f MB chunksize=%10lld %10.4f MB\n",
378 DPRINTFTS(rank,
"before setp");
379 sion_gendata->apidesc->barrier_cb(comm_group);
388 sion_gendata->apidesc->barrier_cb(comm_group);
391 _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_CHUNK);
393 DPRINTFTS(rank,
"after setp");
394 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
" ending open for write #tasks=%d filepos=%lld\n", ntasks,
_sion_file_get_position(sion_filedesc->
fileptr)));
397 else if (flags_store->mask&_SION_FMODE_READ) {
400 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
" starting open for read #tasks=%d\n", ntasks));
404 DPRINTFTS(rank,
"before openR");
406 DPRINTFTS(rank,
"after openR");
408 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
" cannot open %s for reading, aborting ...\n", fname));
409 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_generic_one_file: cannot open %s for reading, aborting ...\n", fname));
414 sion_gendata->apidesc->barrier_cb(comm_group);
417 sion_filedesc->
fileptr = sion_fileptr;
418 sion_filedesc->
rank = rank;
419 sion_filedesc->
ntasks = ntasks;
422 sion_filedesc->
nfiles = nfiles;
423 sion_filedesc->
collmsa = !!_sion_flags_get(flags_store,
"collmsa");
424 sion_filedesc->
usebuddy = (flags_store->mask&_SION_FMODE_BUDDY)>0;
426 sion_filedesc->
buddylevel = atoi(_sion_flags_get(flags_store,
"buddy")->val);
431 if ( flag&_SION_INTERNAL_FLAG_BUDDY_READ ) {
439 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
" create buddy mapping ntasks=%d filentasks=%d\n",ntasks,sion_filedesc->
ntasks));
442 sion_tmpintfield_buddy32 = (sion_int32 *) malloc(ntasks *
sizeof(sion_int32));
443 if (sion_tmpintfield_buddy32 == NULL) {
444 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_generic_one_file: cannot allocate temporary memory of size %lu (sion_tmpintfield_buddy), aborting ...\n",
445 (
unsigned long) ntasks *
sizeof(sion_int32)));
447 for (j = 0; j < ntasks; j++) sion_tmpintfield_buddy32[j]=-1;
448 sion_tmpintfield_buddy64 = (sion_int64 *) malloc(ntasks *
sizeof(sion_int64));
449 if (sion_tmpintfield_buddy64 == NULL) {
450 free(sion_tmpintfield_buddy32);
451 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_generic_one_file: cannot allocate temporary memory of size %lu (sion_tmpintfield_buddy), aborting ...\n",
452 (
unsigned long) ntasks *
sizeof(sion_int64)));
454 for (j = 0; j < ntasks; j++) sion_tmpintfield_buddy64[j]=-1;
455 sion_tmpintfield_map = (sion_int32 *) malloc(ntasks *
sizeof(sion_int32));
456 if (sion_tmpintfield_map == NULL) {
457 free(sion_tmpintfield_buddy32);
458 free(sion_tmpintfield_buddy64);
459 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_generic_one_file: cannot allocate temporary memory of size %lu (sion_tmpintfield_map), aborting ...\n",
460 (
unsigned long) ntasks *
sizeof(sion_int32)));
462 for (j = 0; j < ntasks; j++) sion_tmpintfield_map[j]=-1;
465 helpint32=buddy_data->groups[buddy_data->currentgroup]->filelrank;
466 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_tmpintfield_map, comm_group, _SION_INT32, 1, 0);
470 for (j = 0; j < ntasks; j++)
471 DPRINTFP((64,
"_sion_paropen_generic_one_file", rank,
" buddy map[%d]=%d\n", j, (
int) sion_tmpintfield_map[j]));
478 if (rc!=SION_SUCCESS) {
479 free(sion_tmpintfield_buddy32);
480 free(sion_tmpintfield_buddy64);
481 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_generic_one_file: cannot read header from file %s, aborting ...\n", fname));
483 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
484 " read, after read of fix header part endianness=0x%x blksize=%d ntasks=%d\n", sion_filedesc->
endianness, sion_filedesc->
fsblksize, sion_filedesc->
ntasks));
486 DPRINTFTS(rank,
"before alloc");
489 DPRINTFTS(rank,
"after alloc");
492 if (rc!=SION_SUCCESS) {
493 free(sion_tmpintfield_buddy32);
494 free(sion_tmpintfield_buddy64);
495 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_generic_one_file: cannot read header from file %s, aborting ...\n", fname));
498 if ((flags_entry = _sion_flags_get(flags_store,
"collsize"))) {
499 sion_filedesc->
collsize = atoi(flags_entry->val);
501 _sion_coll_check_env(sion_filedesc);
505 if (!sion_filedesc->
usecoll) _sion_calculate_startpointers(sion_filedesc);
507 if (sion_filedesc->
collmergemode) _sion_calculate_startpointers_collective_merge(sion_filedesc);
508 else if (sion_filedesc->
collmsa) _sion_calculate_startpointers_collective_msa(sion_filedesc);
509 else _sion_calculate_startpointers_collective(sion_filedesc);
511 DPRINTFTS(rank,
"after calculate");
514 _sion_keyval_check_env(sion_filedesc, flags_store->mask);
519 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
keyvalmode, comm_group, _SION_INT32, 1, 0);
522 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
usecoll, comm_group, _SION_INT32, 1, 0);
523 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
collsize, comm_group, _SION_INT32, 1, 0);
526 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
" usecoll=%d\n", sion_filedesc->
usecoll));
530 if (! (flag&_SION_INTERNAL_FLAG_BUDDY_READ) ) {
531 sion_gendata->apidesc->scatterr_cb(sion_filedesc->
all_coll_collsize, &sion_filedesc->
collsize, comm_group, _SION_INT32, 1, 0);
536 if(rank==0)
for (j = 0; j < ntasks; j++)
if(sion_tmpintfield_map[j]>=0) sion_tmpintfield_buddy32[j]=sion_filedesc->
all_coll_collsize[sion_tmpintfield_map[j]];
537 sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy32, &sion_filedesc->
collsize, comm_group, _SION_INT32, 1, 0);
539 if(rank==0)
for (j = 0; j < ntasks; j++)
if(sion_tmpintfield_map[j]>=0) sion_tmpintfield_buddy32[j]=sion_filedesc->
all_coll_collector[sion_tmpintfield_map[j]];
540 sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy32, &sion_filedesc->
collector, comm_group, _SION_INT32, 1, 0);
548 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
globalskip, comm_group, _SION_INT64, 1, 0);
551 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
endianness, comm_group, _SION_INT32, 1, 0);
552 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
swapbytes, comm_group, _SION_INT32, 1, 0);
553 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
fsblksize, comm_group, _SION_INT32, 1, 0);
554 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
ntasks, comm_group, _SION_INT32, 1, 0);
555 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
fileversion, comm_group, _SION_INT32, 1, 0);
556 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
nfiles, comm_group, _SION_INT32, 1, 0);
557 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
filenumber, comm_group, _SION_INT32, 1, 0);
558 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
flag1, comm_group, _SION_INT32, 1, 0);
559 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
flag2, comm_group, _SION_INT32, 1, 0);
560 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
maxusedchunks, comm_group, _SION_INT32, 1, 0);
562 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
565 DPRINTFTS(rank,
"after bcast");
568 DPRINTFTS(rank,
"before scatter");
569 if (! (flag&_SION_INTERNAL_FLAG_BUDDY_READ) ) {
570 sion_gendata->apidesc->scatterr_cb(sion_filedesc->
all_chunksizes, &sion_filedesc->
chunksize, comm_group, _SION_INT64, 1, 0);
571 sion_gendata->apidesc->scatterr_cb(sion_filedesc->
all_startpointers, &sion_filedesc->
startpos, comm_group, _SION_INT64, 1, 0);
572 sion_gendata->apidesc->scatterr_cb(sion_filedesc->
all_globalranks, &helpint64, comm_group, _SION_INT64, 1, 0);sion_filedesc->
globalrank=(sion_int32) helpint64;
575 if(rank==0)
for (j = 0; j < ntasks; j++)
if(sion_tmpintfield_map[j]>=0) sion_tmpintfield_buddy64[j]=sion_filedesc->
all_chunksizes[sion_tmpintfield_map[j]];
576 sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy64, &sion_filedesc->
chunksize, comm_group, _SION_INT64, 1, 0);
578 if(rank==0)
for (j = 0; j < ntasks; j++)
if(sion_tmpintfield_map[j]>=0) sion_tmpintfield_buddy64[j]=sion_filedesc->
all_startpointers[sion_tmpintfield_map[j]];
579 sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy64, &sion_filedesc->
startpos, comm_group, _SION_INT64, 1, 0);
581 if(rank==0)
for (j = 0; j < ntasks; j++)
if(sion_tmpintfield_map[j]>=0) sion_tmpintfield_buddy64[j]=sion_filedesc->
all_globalranks[sion_tmpintfield_map[j]];
582 sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy64, &helpint64, comm_group, _SION_INT64, 1, 0);sion_filedesc->
globalrank=(sion_int32) helpint64;
585 DPRINTFTS(rank,
"after scatter");
589 sion_tmpintfield = (sion_int64 *) malloc(sion_filedesc->
ntasks *
sizeof(sion_int64));
590 if (sion_tmpintfield == NULL) {
591 free(sion_tmpintfield_buddy32);
592 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_generic_one_file: cannot allocate temporary memory of size %lu (sion_tmpintfield), aborting ...\n",
593 (
unsigned long) ntasks *
sizeof(sion_int64)));
597 for (j = 0; j < sion_filedesc->
ntasks; j++)
598 DPRINTFP((2048,
"_sion_paropen_generic_one_file", rank,
" read, blockcount on task %02d is %10ld\n", j, (
long) sion_tmpintfield[j]));
602 DPRINTFTS(rank,
"before scatter");
603 if (! (flag&_SION_INTERNAL_FLAG_BUDDY_READ) ) {
604 sion_gendata->apidesc->scatterr_cb(sion_tmpintfield, &helpint64, comm_group, _SION_INT64, 1, 0);
607 if(rank==0)
for (j = 0; j < ntasks; j++)
if(sion_tmpintfield_map[j]>=0) sion_tmpintfield_buddy64[j]=sion_tmpintfield[sion_tmpintfield_map[j]];
608 sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy64, &helpint64, comm_group, _SION_INT64, 1, 0);
610 DPRINTFTS(rank,
"after scatter");
612 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
" lastchunknr on task %02d is %10ld\n", rank, (
long) sion_filedesc->
lastchunknr));
616 DPRINTFTS(rank,
"before scatter");
617 if (! (flag&_SION_INTERNAL_FLAG_BUDDY_READ) ) {
618 sion_gendata->apidesc->scatterr_cb(sion_tmpintfield, &helpint64, comm_group, _SION_INT64, 1, 0);
621 if(rank==0)
for (j = 0; j < ntasks; j++)
if(sion_tmpintfield_map[j]>=0) sion_tmpintfield_buddy64[j]=sion_tmpintfield[sion_tmpintfield_map[j]];
622 sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy64, &helpint64, comm_group, _SION_INT64, 1, 0);
624 DPRINTFTS(rank,
"after scatter");
635 DPRINTFTS(rank,
"before setp");
636 sion_gendata->apidesc->barrier_cb(comm_group);
650 if(sion_tmpintfield) free(sion_tmpintfield);
651 if(sion_tmpintfield_map) free(sion_tmpintfield_map);
652 if(sion_tmpintfield_buddy32) free(sion_tmpintfield_buddy32);
653 if(sion_tmpintfield_buddy64) free(sion_tmpintfield_buddy64);
655 sion_gendata->apidesc->barrier_cb(comm_group);
656 DPRINTFTS(rank,
"after setp");
659 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_multi_mpi: unknown file mode"));
665 *fileptr=sion_filedesc->
fileptr->fileptr;
673 if(fileptr!=NULL) *fileptr=NULL;
684 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
" start position on task %02d is at end of sion_paropen_generic %10lld\n", rank,
687 DPRINTFP((2,
"_sion_paropen_generic_one_file", rank,
"leave parallel open of file %s in mode 0x%lx #tasks=%d\n", fname, (
long) flags_store->mask, ntasks));
720 int rc = SION_SUCCESS;
722 sion_int64 helpint64;
723 sion_int64 *sion_tmpintfield = NULL;
725 void *comm_group=NULL;
729 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: invalid sion_filedesc, aborting %d ...\n", sid));
733 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: sion file with sid=%d was not opened by a sion_paropen\n", sid));
736 DPRINTFP((2,
"_sion_parclose_generic", rank,
"enter parallel close sid=%d\n", sid));
739 if(flag& _SION_INTERNAL_FLAG_NORMAL ) comm_group=sion_gendata->comm_data_local;
740 if(flag& _SION_INTERNAL_FLAG_BUDDY_SEND ) comm_group=buddy_data->buddy_send.commgroup;
741 if(flag& _SION_INTERNAL_FLAG_BUDDY_COLL ) comm_group=buddy_data->buddy_coll.commgroup;
742 if(flag& _SION_INTERNAL_FLAG_BUDDY_READ ) comm_group=buddy_data->groups[buddy_data->currentgroup]->commgroup;
746 if (flag&_SION_INTERNAL_FLAG_BUDDY_SEND) do_close_file=0;
747 if ( (flag&_SION_INTERNAL_FLAG_BUDDY_COLL) && (rank>0) ) do_close_file=0;
748 if ( (flag&_SION_INTERNAL_FLAG_BUDDY_READ) && (rank>0) ) do_close_file=0;
755 DPRINTFP((32,
"_sion_parclose_generic", rank,
" parallel close (read mode) sid=%d, call fclose on file\n", sid));
779 DPRINTFP((32,
"_sion_parclose_generic", rank,
" parallel close (write mode) sid=%d, call fclose on file\n", sid));
788 sion_gendata->apidesc->barrier_cb(comm_group);
790 DPRINTFP((32,
"_sion_parclose_generic", rank,
" parallel close sid=%d: lastchunknr=%d globalskip=%lld\n", sid, sion_filedesc->
lastchunknr,
792 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
793 DPRINTFP((1024,
"_sion_parclose_generic", rank,
" parallel close sid=%d: local block %02d -> %10lld bytes\n", sid, blknum,
798 sion_tmpintfield = (sion_int64 *) malloc(sion_filedesc->
ntasks *
sizeof(sion_int64));
799 if (sion_tmpintfield == NULL) {
800 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield), aborting ...\n",
801 (
unsigned long) sion_filedesc->
ntasks *
sizeof(sion_int64)));
806 DPRINTFTS2(rank,
"before gather");
808 sion_gendata->apidesc->gatherr_cb(&helpint64, sion_tmpintfield, comm_group, _SION_INT64, 1, 0);
812 for (blknum = 0; blknum < sion_filedesc->
ntasks; blknum++)
814 sion_filedesc->
maxusedchunks = (int) sion_tmpintfield[blknum];
816 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
maxusedchunks, comm_group, _SION_INT32, 1, 0);
817 DPRINTFTS2(rank,
"after gather");
831 for (blknum = 0; blknum < sion_filedesc->
maxusedchunks; blknum++) {
832 if (blknum <= sion_filedesc->lastchunknr) {
833 helpint64 = sion_filedesc->
blocksizes[blknum];
839 DPRINTFTS2(rank,
"before gather");
840 sion_gendata->apidesc->gatherr_cb(&helpint64, sion_tmpintfield, comm_group, _SION_INT64, 1, 0);
841 DPRINTFTS2(rank,
"after gather");
844 for (lrank = 0; lrank < ntasks; lrank++)
845 DPRINTFP((2048,
"_sion_parclose_generic", rank,
" parallel close sid=%d: write total chunksize for block %d: %2lld rank=%d\n", sid, blknum,
846 sion_tmpintfield[lrank], lrank));
854 if (mapping != NULL) {
860 DPRINTFP((32,
"_sion_parclose_generic", rank,
" parallel close (write mode) sid=%d, call fclose on file\n", sid));
868 if(sion_tmpintfield) free(sion_tmpintfield);
873 _sion_free_filedesc(sion_filedesc);
874 sion_filedesc = NULL;
877 DPRINTFP((2,
"_sion_parclose_generic", rank,
"leave parallel close sid=%d\n", sid));
888 sion_int64 chunksize,
894 int rc = SION_SUCCESS;
896 sion_int64 lchunksize, lstartpointer, lglobalrank;
897 void *comm_group=NULL;
900 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parreinit_generic: invalid sion_filedesc, aborting %d ...\n", sid));
904 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parreinit_generic: sion file with sid=%d was not opened by a sion_paropen\n", sid));
907 DPRINTFP((2,
"_sion_parreinit_generic", sion_filedesc->
rank,
"enter parallel reinit sid=%d\n", sid));
909 comm_group=sion_gendata->comm_data_local;
912 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parreinit_generic: sion file with sid=%d only allowed for files openend for write\n", sid));
915 DPRINTFTS(sion_filedesc->
rank,
"before alloc");
916 if (sion_filedesc->
rank == 0) {
920 DPRINTFTS(sion_filedesc->
rank,
"after alloc");
923 lchunksize = (sion_int64) chunksize;
924 lglobalrank = (sion_int64) sion_filedesc->
globalrank;
926 DPRINTFTS2(sion_filedesc->
rank,
"before gather");
927 sion_gendata->apidesc->gatherr_cb(&lchunksize, sion_filedesc->
all_chunksizes, comm_group, _SION_INT64, 1, 0);
928 sion_gendata->apidesc->gatherr_cb(&lglobalrank, sion_filedesc->
all_globalranks, comm_group, _SION_INT64, 1, 0);
930 DPRINTFTS2(sion_filedesc->
rank,
"after gather");
934 if (sion_filedesc->
rank == 0) {
935 DPRINTFTS(sion_filedesc->
rank,
"before calculate");
936 if (!sion_filedesc->
usecoll) _sion_calculate_startpointers(sion_filedesc);
937 else _sion_calculate_startpointers_collective(sion_filedesc);
938 DPRINTFTS(sion_filedesc->
rank,
"after calculate");
942 if (sion_filedesc->
rank == 0) {
945 _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_METADATABLOCK1);
951 DPRINTFTS(sion_filedesc->
rank,
"before writeh");
953 DPRINTFTS(sion_filedesc->
rank,
"after writeh");
962 DPRINTFTS(sion_filedesc->
rank,
"before setp(0)");
965 DPRINTFTS(sion_filedesc->
rank,
"after setp(0)");
970 DPRINTFTS(sion_filedesc->
rank,
"before scatter");
971 sion_gendata->apidesc->scatterr_cb(sion_filedesc->
all_startpointers, &sion_filedesc->
startpos, comm_group, _SION_INT64, 1, 0);
972 DPRINTFTS(sion_filedesc->
rank,
"after scatter");
976 sion_gendata->apidesc->scatterr_cb(sion_filedesc->
all_coll_collsize, &sion_filedesc->
collsize, comm_group, _SION_INT32, 1, 0);
983 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
globalskip, comm_group, _SION_INT64, 1, 0);
985 DPRINTFP((32,
"_sion_parreinit_generic", sion_filedesc->
rank,
" start position is %10lld %10.4f MB\n",
989 DPRINTFTS(sion_filedesc->
rank,
"before setp");
990 sion_gendata->apidesc->barrier_cb(comm_group);
994 sion_filedesc->
chunksize = (sion_int64) chunksize;
995 sion_gendata->apidesc->barrier_cb(comm_group);
998 _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_CHUNK);
1000 if (sion_filedesc->
rank == 0) {
1005 DPRINTFTS(sion_filedesc->
rank,
"after setp");
1006 DPRINTFP((32,
"_sion_parreinit_generic", sion_filedesc->
rank,
" ending open for write #tasks=%d filepos=%lld\n",
1009 DPRINTFP((2,
"_sion_parreinit_generic", sion_filedesc->
rank,
"leave parallel reinit of file %s in #tasks=%d\n",
1022 #define DFUNCTION "_sion_generic_collect_mapping"
1023 int _sion_generic_collect_mapping(
_sion_filedesc *sion_filedesc,
1025 sion_int32 **mapping ) {
1026 int rc=SION_SUCCESS;
1030 sion_int32 lpos[2], *receivemap=NULL, iamreceiver, receiver = -1;
1033 sion_gendata=sion_filedesc->
dataptr;
1034 sion_apidesc=sion_gendata->apidesc;
1036 *mapping = NULL; *mapping_size = 0;
1044 *mapping_size=sion_gendata->gsize;
1045 *mapping = (sion_int32 *) malloc(*mapping_size * 2 *
sizeof(sion_int32));
1046 if (*mapping == NULL) {
1047 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_parclose: Cannot allocate memory for mapping"));
1052 if(sion_gendata->grank==0) {
1053 receivemap = (sion_int32 *) malloc(sion_gendata->gsize *
sizeof(sion_int32));
1054 if (receivemap == NULL) {
1055 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_parclose: Cannot allocate memory for receivemap"));
1059 if((sion_filedesc->
filenumber==0) && (sion_filedesc->
rank==0)) iamreceiver=sion_gendata->grank;
1060 else iamreceiver=-1;
1061 sion_apidesc->gatherr_cb(&iamreceiver, receivemap, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
1062 if(sion_gendata->grank==0) {
1063 for(t=0;t<sion_gendata->gsize;t++) {
1064 if(receivemap[t]>=0) {
1065 receiver=receivemap[t];
1069 DPRINTFP((1,
DFUNCTION, sion_gendata->grank,
"receiver of mapping grank=%d\n", receiver));
1071 sion_apidesc->bcastr_cb(&receiver, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
1075 lpos[1] = sion_filedesc->
rank;
1076 sion_apidesc->gatherr_cb(&lpos, *mapping, sion_gendata->comm_data_global, _SION_INT32, 2, receiver);
1079 if(receivemap!=NULL) free(receivemap);
1095 int grank = comm->grank;
1096 int gsize = comm->gsize;
1098 DPRINTFP((2, __func__, grank,
"enter\n"));
1100 if (0 != strcmp(comm->apidesc->name,
"SIONlib_MPI_API")) {
1101 return _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_RETURN,
"MSA Collectives: not supported for generic API \"%s\"\n", comm->apidesc->name);
1109 fd.
collsize = atoi(flags_entry->val);
1111 _sion_coll_check_env(&fd);
1114 return _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_RETURN,
"MSA Collectives: size of collective groups should be 2 or more, but is %d\n", collsize);
1116 sion_int32 n_groups = gsize / collsize + ((gsize % collsize) ? 1 : 0);
1119 return _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_RETURN,
"MSA Collectives: usecoll == false\n");
1122 int is_candidate = _sion_generic_is_candidate(comm);
1123 int n_candidates = 0;
1124 int candidates_before = 0;
1127 int *candidates = NULL;
1128 if (0 == comm->grank) {
1129 candidates = calloc(gsize,
sizeof(
int));
1131 _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_ABORT,
"MSA Collectives: malloc returned NULL\n");
1135 comm->apidesc->gatherr_cb(&is_candidate, candidates, comm->comm_data_global, _SION_INT32, 1, 0);
1137 if (0 == comm->grank) {
1138 for (
size_t i = 0; i < gsize; i++) {
1139 int tmp = candidates[i];
1140 candidates[i] = n_candidates;
1141 n_candidates += tmp;
1145 comm->apidesc->bcastr_cb(&n_candidates, comm->comm_data_global, _SION_INT32, 1, 0);
1146 comm->apidesc->scatterr_cb(candidates, &candidates_before, comm->comm_data_global, _SION_INT32, 1, 0);
1148 if (0 == comm->grank) {
1153 if ((n_candidates < n_groups) || (n_candidates < comm->numfiles)) {
1154 return _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_RETURN,
"MSA Collectives: insufficient number of candidates %d, number of groups %d, number of files %d\n", n_groups, comm->numfiles);
1158 int groups_per_file = n_groups / comm->numfiles;
1159 int is_collector = is_candidate && (candidates_before < n_groups);
1161 int rank_collector = candidates_before;
1162 comm->filenumber = rank_collector % comm->numfiles;
1163 comm->lrank = (rank_collector / comm->numfiles) * collsize;
1165 int collectors_before = (candidates_before < n_groups) ? candidates_before : n_groups;
1166 int rank_sender = grank - collectors_before;
1167 int group_number = rank_sender / (collsize - 1);
1168 comm->filenumber = group_number % comm->numfiles;
1169 comm->lrank = (group_number / comm->numfiles) * collsize + rank_sender % (collsize - 1) + 1;
1171 comm->lsize = collsize * (groups_per_file + ((comm->filenumber < n_groups % comm->numfiles) ? 1 : 0));
1172 if (comm->filenumber == comm->numfiles - 1) {
1173 comm->lsize += gsize - n_groups * collsize;
1176 DPRINTFP((32, __func__, grank,
"MSA Collectives: global rank %d of %d, is candidate %d, is collector %d, file no %d, local rank %d, local size %d\n", grank, gsize, is_candidate, is_collector, comm->filenumber, comm->lrank, comm->lsize));
1177 DPRINTFP((2, __func__, grank,
"exit\n"));
1178 return SION_SUCCESS;
1182 #if defined(_SION_MSA_DEEP_EST_SDV)
1183 char hostname[1024];
1184 if (0 == gethostname(hostname, 1024)) {
1185 if (0 == strncmp(
"knl", hostname, 3)) {
1193 #elif defined(_SION_MSA_HOSTNAME_REGEX)
1197 if ((regex =
_sion_getenv(
"SION_MSA_COLLECTOR_HOSTNAME_EREGEX"))) {
1198 compile_error = regcomp(&compiled, regex, REG_EXTENDED|REG_ICASE|REG_NOSUB);
1199 }
else if ((regex =
_sion_getenv(
"SION_MSA_COLLECTOR_HOSTNAME_REGEX"))) {
1200 compile_error = regcomp(&compiled, regex, REG_ICASE|REG_NOSUB);
1204 if (compile_error) {
1205 char error_msg[1024];
1206 size_t error_size = regerror(compile_error, &compiled, error_msg, 1024);
1208 _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_ABORT,
"MSA Collectives: error compiling regex \"%s\": %s%s\n", regex, error_msg, (error_size > 1024) ?
"..." :
"");
1211 char hostname[1024];
1212 int hostname_error = gethostname(hostname, 1023);
1213 hostname[1023] =
'\0';
1214 if (hostname_error) {
1216 _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_ABORT,
"MSA Collectives: error getting host name\n");
1219 int exec_status = regexec(&compiled, hostname, 0, NULL, 0);
1220 if (exec_status == 0) {
1223 }
else if (exec_status == REG_NOMATCH) {
1227 char error_msg[1024];
1228 size_t error_size = regerror(exec_status, &compiled, error_msg, 1024);
1230 _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_ABORT,
"MSA Collectives: error matching regex \"%s\": %s%s\n", regex, error_msg, (error_size > 1024) ?
"..." :
"");
1233 #elif defined(_SION_MSA_TEST)
1234 return comm->grank %2;
int _sion_buffer_check_env(_sion_filedesc *sion_filedesc)
Checks if environment variables are set to use buffer.
int _sion_buffer_flush(_sion_filedesc *sion_filedesc)
Flush buffer.
int _sion_cache_check_env(_sion_filedesc *sion_filedesc)
Check if environment variables are set to use cache.
int _sion_reassignvcd(int sid, void *data, int type)
void * _sion_vcdtovcon(int sid)
int _sion_vcdtype(int sid)
#define SION_FILEDESCRIPTOR
long _sion_file_get_opt_blksize(_sion_fileptr *sion_fileptr)
Get optional file system block size for a file.
int _sion_file_flush(_sion_fileptr *sion_fileptr)
Flush data to file.
int _sion_file_close(_sion_fileptr *sion_fileptr)
Close file and destroys fileptr structure.
sion_int64 _sion_file_set_position(_sion_fileptr *sion_fileptr, sion_int64 startpointer)
Set new position in file.
int _sion_file_purge(_sion_fileptr *sion_fileptr)
Purge data to file.
sion_int64 _sion_file_get_position(_sion_fileptr *sion_fileptr)
Get new position in file.
_sion_fileptr * _sion_file_open(const char *fname, unsigned int flags, unsigned int addflags)
Create and open a new file for writing.
#define SION_FILE_FLAG_READ
#define SION_FILE_FLAG_CREATE
#define SION_FILE_FLAG_ANSI
#define SION_FILE_FLAG_WRITE
#define SION_FILE_FLAG_POSIX
int _sion_init_filedesc(_sion_filedesc *sion_filedesc)
Initialize the sion file description.
int _sion_realloc_filedesc_blocklist(_sion_filedesc *sion_filedesc, sion_int32 maxchunks)
Increase the memory used by the internal sion structure for the blocklist.
int _sion_alloc_filedesc_coll_arrays(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion arrays.
int _sion_alloc_filedesc_arrays(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion arrays.
int _sion_print_filedesc(_sion_filedesc *sion_filedesc, int level, char *desc, int flag)
Print the initialized sion file description.
int _sion_free_filedesc_arrays(_sion_filedesc *sion_filedesc)
free memory for the internal sion arrays
_sion_filedesc * _sion_alloc_filedesc(void)
Allocates memory for internal sion structure.
int _sion_free_filedesc_coll_arrays(_sion_filedesc *sion_filedesc)
free memory for the internal sion arrays
#define SION_FILEMODE_WRITE
#define SION_FILEMODE_READ
#define SION_FILESTATE_PAROPEN
#define SION_FILESTATE_CLOSE
#define DFUNCTION
collect mapping information on rank 0 of first file, mapping=NULL for all others
int _sion_parclose_generic(int sid, int rank, int ntasks, int mapping_size, sion_int32 *mapping, int flag, _sion_generic_gendata *sion_gendata, _sion_generic_buddy *buddy_data)
Internal function to close parallel opened SION file.
int _sion_generic_renumber_collmsa(_sion_generic_gendata *comm, _sion_flags_store *flags)
Splits a Communicator in numfiles different communicators.
int _sion_parreinit_generic(int sid, sion_int64 chunksize, int rank, int ntasks, _sion_generic_gendata *sion_gendata)
change chunksize for an already opened SION file (write)
int _sion_paropen_generic_one_file(int sid, char *fname, _sion_flags_store *flags_store, char *prefix, int *numFiles, int *filenumber, sion_int64 *chunksize, sion_int32 *fsblksize, int rank, int ntasks, int *globalrank, int flag, FILE **fileptr, _sion_generic_gendata *sion_gendata, _sion_generic_buddy *buddy_data)
Generic parallel open of one direct access file.
char * _sion_getenv(const char *name)
int _sion_flush_block(_sion_filedesc *sion_filedesc)
Update the internal data structure.
sion_int32 _sion_get_endianness_with_flags(sion_int64 flags)
Return endianness including possible choice via flags.
Sion File Descriptor Structure.
sion_int32 * all_coll_collsize
sion_int32 * all_coll_collector
sion_int64 start_of_varheader
sion_int64 * all_chunksizes
sion_int32 fileptr_exported
sion_int64 * all_globalranks
sion_int32 currentblocknr
sion_int32 * all_coll_capability
sion_int32 coll_capability
sion_int64 * all_startpointers