26 #include "sion_error_handler.h" 38 #include "sion_hints.h" 41 #include "sion_generic_buddy.h" 72 sion_int64 *chunksize,
73 sion_int32 *fsblksize,
90 sion_int64 lchunksize, lstartpointer, lglobalrank, new_fsblocksize, helpint64, apiflag;
91 sion_int64 *sion_tmpintfield = NULL;
92 sion_int32 *sion_tmpintfield_map = NULL, helpint32;
93 sion_int32 *sion_tmpintfield_buddy32 = NULL;
94 sion_int64 *sion_tmpintfield_buddy64 = NULL;
95 void *comm_group=NULL;
103 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));
104 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),
105 sizeof(
long long),
sizeof(sion_int32),
sizeof(sion_int64)));
109 filenum = *filenumber;
112 if(flag& _SION_INTERNAL_FLAG_NORMAL ) comm_group=sion_gendata->comm_data_local;
113 if(flag& _SION_INTERNAL_FLAG_BUDDY_NORMAL ) comm_group=sion_gendata->comm_data_local;
114 if(flag& _SION_INTERNAL_FLAG_BUDDY_SEND ) comm_group=buddy_data->buddy_send.commgroup;
115 if(flag& _SION_INTERNAL_FLAG_BUDDY_COLL ) comm_group=buddy_data->buddy_coll.commgroup;
116 if(flag& _SION_INTERNAL_FLAG_BUDDY_READ ) comm_group=buddy_data->groups[buddy_data->currentgroup]->commgroup;
120 if (flag&_SION_INTERNAL_FLAG_BUDDY_SEND) do_open_file=0;
121 if ( (flag&_SION_INTERNAL_FLAG_BUDDY_COLL) && (rank>0) ) do_open_file=0;
122 if ( (flag&_SION_INTERNAL_FLAG_BUDDY_READ) && (rank>0) ) do_open_file=0;
124 DPRINTFP((2,
"_sion_paropen_generic_one_file", rank,
"do_open_file=%d\n", do_open_file));
127 if (sion_filedesc == NULL) {
128 _sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_ABORT,
"_sion_paropen_omp: cannot allocate filedescriptor structure of size %lu (sion_filedesc), aborting ...\n",
129 (
unsigned long)
sizeof(sion_filedesc));
132 sion_filedesc->
fname = strdup(fname);
135 sion_filedesc->
sid=sid;
142 if (flags_store->mask&_SION_FMODE_WRITE) {
145 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
" starting open for write #tasks=%d\n", ntasks));
149 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen: wrong number of tasks specific: ntasks=%d (<0), returning ...\n", (
int) ntasks));
153 if ((chunksize != NULL) && (*chunksize<0)) {
154 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen: ((chunksize != NULL) && (*chunksize<0)), returning ...\n"));
158 if ((flag & _SION_INTERNAL_FLAG_NORMAL ) && (globalrank != NULL) && (*globalrank<0)) {
159 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen: ((globalrank != NULL) && (*globalrank<0)), returning ...\n"));
167 sion_filedesc->
rank = rank;
169 sion_filedesc->
ntasks = ntasks;
170 sion_filedesc->
nfiles = nfiles;
172 sion_filedesc->
prefix = strdup(prefix);
173 sion_filedesc->
compress = flags_store->mask&_SION_FMODE_COMPRESS;
174 sion_filedesc->
usecoll = (flags_store->mask&_SION_FMODE_COLLECTIVE)>0;
175 sion_filedesc->
collmergemode = (flags_store->mask&_SION_FMODE_COLLECTIVE_MERGE)>0;
176 sion_filedesc->
usebuddy = (flags_store->mask&_SION_FMODE_BUDDY)>0;
178 sion_filedesc->
buddylevel = atoi(_sion_flags_get(flags_store,
"buddy")->val);
186 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_generic: cannot open %s for writing, aborting ...\n", fname));
191 if((new_fsblocksize<0) || (new_fsblocksize>SION_MAX_FSBLOCKSIZE)) new_fsblocksize=SION_DEFAULT_FSBLOCKSIZE;
195 sion_gendata->apidesc->barrier_cb(comm_group);
200 sion_gendata->apidesc->bcastr_cb(&new_fsblocksize, comm_group, _SION_INT64, 1, 0);
201 *fsblksize=new_fsblocksize;
204 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
"setting fsblksize to %lld\n", new_fsblocksize));
213 _sion_keyval_check_env(sion_filedesc, flags_store->mask);
215 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
keyvalmode, comm_group, _SION_INT32, 1, 0);
219 if ((flags_entry = _sion_flags_get(flags_store,
"collsize"))) {
220 sion_filedesc->
collsize = atoi(flags_entry->val);
222 _sion_coll_check_env(sion_filedesc);
226 ( flag&_SION_INTERNAL_FLAG_BUDDY_NORMAL )
227 || ( flag&_SION_INTERNAL_FLAG_BUDDY_SEND )
228 || ( flag&_SION_INTERNAL_FLAG_BUDDY_COLL )
238 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
usecoll, comm_group, _SION_INT32, 1, 0);
239 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
collsize, comm_group, _SION_INT32, 1, 0);
240 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
collmergemode, comm_group, _SION_INT32, 1, 0);
244 if(sion_gendata->apidesc->level!=SION_GENERIC_API_LEVEL_FULL) {
245 _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");
252 _sion_hints_check_env(sion_filedesc);
254 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
usehints, comm_group, _SION_INT32, 1, 0);
255 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
hinttype, comm_group, _SION_INT32, 1, 0);
257 DPRINTFTS(rank,
"before alloc");
263 DPRINTFTS(rank,
"after alloc");
266 lchunksize = (sion_int64) *chunksize;
267 lglobalrank = (sion_int64) *globalrank;
269 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
"lchunksize=%lld lglobalrank=%lld\n", lchunksize,lglobalrank));
271 DPRINTFTS2(rank,
"before gather");
272 sion_gendata->apidesc->gatherr_cb(&lchunksize, sion_filedesc->
all_chunksizes, comm_group, _SION_INT64, 1, 0);
273 sion_gendata->apidesc->gatherr_cb(&lglobalrank, sion_filedesc->
all_globalranks, comm_group, _SION_INT64, 1, 0);
277 sion_filedesc->
coll_capability=sion_gendata->apidesc->get_capability_cb(comm_group);
281 DPRINTFTS2(rank,
"after gather");
283 DPRINTFTS(rank,
"before calculate");
284 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
"chunksizes[%d - 1]=%ld\n", ntasks,(
long) sion_filedesc->
all_chunksizes[ntasks - 1]));
285 if (!sion_filedesc->
usecoll) _sion_calculate_startpointers(sion_filedesc);
287 if (!sion_filedesc->
collmergemode) _sion_calculate_startpointers_collective(sion_filedesc);
288 else _sion_calculate_startpointers_collective_merge(sion_filedesc);
290 DPRINTFTS(rank,
"after calculate");
293 DPRINTFTS(rank,
"before open");
300 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_generic: cannot open %s for writing, aborting ...\n", fname));
303 sion_filedesc->
fileptr = sion_fileptr;
305 sion_gendata->apidesc->barrier_cb(comm_group);
306 DPRINTFTS(rank,
"after open");
313 _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_METADATABLOCK1);
315 DPRINTFTS(rank,
"before writeh");
317 DPRINTFTS(rank,
"after writeh");
325 DPRINTFTS(rank,
"before setp(0)");
328 DPRINTFTS(rank,
"after setp(0)");
333 DPRINTFTS(rank,
"before scatter");
334 sion_gendata->apidesc->scatterr_cb(sion_filedesc->
all_startpointers, &sion_filedesc->
startpos, comm_group, _SION_INT64, 1, 0);
335 DPRINTFTS(rank,
"after scatter");
338 DPRINTFTS(rank,
"before scatter");
339 sion_gendata->apidesc->scatterr_cb(sion_filedesc->
all_chunksizes, &sion_filedesc->
chunksize, comm_group, _SION_INT64, 1, 0);
340 DPRINTFTS(rank,
"after scatter");
344 sion_gendata->apidesc->scatterr_cb(sion_filedesc->
all_coll_collsize, &sion_filedesc->
collsize, comm_group, _SION_INT32, 1, 0);
351 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
globalskip, comm_group, _SION_INT64, 1, 0);
353 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
" start position is %10lld %10.4f MB chunksize=%10lld %10.4f MB\n",
359 DPRINTFTS(rank,
"before setp");
360 sion_gendata->apidesc->barrier_cb(comm_group);
369 sion_gendata->apidesc->barrier_cb(comm_group);
372 _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_CHUNK);
374 DPRINTFTS(rank,
"after setp");
375 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)));
378 else if (flags_store->mask&_SION_FMODE_READ) {
381 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
" starting open for read #tasks=%d\n", ntasks));
385 DPRINTFTS(rank,
"before openR");
387 DPRINTFTS(rank,
"after openR");
389 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
" cannot open %s for reading, aborting ...\n", fname));
390 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_generic_one_file: cannot open %s for reading, aborting ...\n", fname));
395 sion_gendata->apidesc->barrier_cb(comm_group);
398 sion_filedesc->
fileptr = sion_fileptr;
399 sion_filedesc->
rank = rank;
400 sion_filedesc->
ntasks = ntasks;
403 sion_filedesc->
nfiles = nfiles;
404 sion_filedesc->
usebuddy = (flags_store->mask&_SION_FMODE_BUDDY)>0;
406 sion_filedesc->
buddylevel = atoi(_sion_flags_get(flags_store,
"buddy")->val);
411 if ( flag&_SION_INTERNAL_FLAG_BUDDY_READ ) {
419 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
" create buddy mapping ntasks=%d filentasks=%d\n",ntasks,sion_filedesc->
ntasks));
422 sion_tmpintfield_buddy32 = (sion_int32 *) malloc(ntasks *
sizeof(sion_int32));
423 if (sion_tmpintfield_buddy32 == NULL) {
424 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",
425 (
unsigned long) ntasks *
sizeof(sion_int32)));
427 for (j = 0; j < ntasks; j++) sion_tmpintfield_buddy32[j]=-1;
428 sion_tmpintfield_buddy64 = (sion_int64 *) malloc(ntasks *
sizeof(sion_int64));
429 if (sion_tmpintfield_buddy64 == NULL) {
430 free(sion_tmpintfield_buddy32);
431 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",
432 (
unsigned long) ntasks *
sizeof(sion_int64)));
434 for (j = 0; j < ntasks; j++) sion_tmpintfield_buddy64[j]=-1;
435 sion_tmpintfield_map = (sion_int32 *) malloc(ntasks *
sizeof(sion_int32));
436 if (sion_tmpintfield_map == NULL) {
437 free(sion_tmpintfield_buddy32);
438 free(sion_tmpintfield_buddy64);
439 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",
440 (
unsigned long) ntasks *
sizeof(sion_int32)));
442 for (j = 0; j < ntasks; j++) sion_tmpintfield_map[j]=-1;
445 helpint32=buddy_data->groups[buddy_data->currentgroup]->filelrank;
446 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_tmpintfield_map, comm_group, _SION_INT32, 1, 0);
450 for (j = 0; j < ntasks; j++)
451 DPRINTFP((64,
"_sion_paropen_generic_one_file", rank,
" buddy map[%d]=%d\n", j, (
int) sion_tmpintfield_map[j]));
458 if (rc!=SION_SUCCESS) {
459 free(sion_tmpintfield_buddy32);
460 free(sion_tmpintfield_buddy64);
461 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_generic_one_file: cannot read header from file %s, aborting ...\n", fname));
463 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
464 " read, after read of fix header part endianness=0x%x blksize=%d ntasks=%d\n", sion_filedesc->
endianness, sion_filedesc->
fsblksize, sion_filedesc->
ntasks));
466 DPRINTFTS(rank,
"before alloc");
469 DPRINTFTS(rank,
"after alloc");
472 if (rc!=SION_SUCCESS) {
473 free(sion_tmpintfield_buddy32);
474 free(sion_tmpintfield_buddy64);
475 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_generic_one_file: cannot read header from file %s, aborting ...\n", fname));
478 if ((flags_entry = _sion_flags_get(flags_store,
"collsize"))) {
479 sion_filedesc->
collsize = atoi(flags_entry->val);
481 _sion_coll_check_env(sion_filedesc);
485 if (!sion_filedesc->
usecoll) _sion_calculate_startpointers(sion_filedesc);
487 if (!sion_filedesc->
collmergemode) _sion_calculate_startpointers_collective(sion_filedesc);
488 else _sion_calculate_startpointers_collective_merge(sion_filedesc);
490 DPRINTFTS(rank,
"after calculate");
493 _sion_keyval_check_env(sion_filedesc, flags_store->mask);
498 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
keyvalmode, comm_group, _SION_INT32, 1, 0);
501 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
usecoll, comm_group, _SION_INT32, 1, 0);
502 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
collsize, comm_group, _SION_INT32, 1, 0);
505 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
" usecoll=%d\n", sion_filedesc->
usecoll));
509 if (! (flag&_SION_INTERNAL_FLAG_BUDDY_READ) ) {
510 sion_gendata->apidesc->scatterr_cb(sion_filedesc->
all_coll_collsize, &sion_filedesc->
collsize, comm_group, _SION_INT32, 1, 0);
515 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]];
516 sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy32, &sion_filedesc->
collsize, comm_group, _SION_INT32, 1, 0);
518 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]];
519 sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy32, &sion_filedesc->
collector, comm_group, _SION_INT32, 1, 0);
527 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
globalskip, comm_group, _SION_INT64, 1, 0);
530 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
endianness, comm_group, _SION_INT32, 1, 0);
531 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
swapbytes, comm_group, _SION_INT32, 1, 0);
532 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
fsblksize, comm_group, _SION_INT32, 1, 0);
533 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
ntasks, comm_group, _SION_INT32, 1, 0);
534 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
fileversion, comm_group, _SION_INT32, 1, 0);
535 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
nfiles, comm_group, _SION_INT32, 1, 0);
536 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
filenumber, comm_group, _SION_INT32, 1, 0);
537 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
flag1, comm_group, _SION_INT32, 1, 0);
538 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
flag2, comm_group, _SION_INT32, 1, 0);
539 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
maxusedchunks, comm_group, _SION_INT32, 1, 0);
541 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
544 DPRINTFTS(rank,
"after bcast");
547 DPRINTFTS(rank,
"before scatter");
548 if (! (flag&_SION_INTERNAL_FLAG_BUDDY_READ) ) {
549 sion_gendata->apidesc->scatterr_cb(sion_filedesc->
all_chunksizes, &sion_filedesc->
chunksize, comm_group, _SION_INT64, 1, 0);
550 sion_gendata->apidesc->scatterr_cb(sion_filedesc->
all_startpointers, &sion_filedesc->
startpos, comm_group, _SION_INT64, 1, 0);
551 sion_gendata->apidesc->scatterr_cb(sion_filedesc->
all_globalranks, &helpint64, comm_group, _SION_INT64, 1, 0);sion_filedesc->
globalrank=(sion_int32) helpint64;
554 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]];
555 sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy64, &sion_filedesc->
chunksize, comm_group, _SION_INT64, 1, 0);
557 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]];
558 sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy64, &sion_filedesc->
startpos, comm_group, _SION_INT64, 1, 0);
560 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]];
561 sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy64, &helpint64, comm_group, _SION_INT64, 1, 0);sion_filedesc->
globalrank=(sion_int32) helpint64;
564 DPRINTFTS(rank,
"after scatter");
568 sion_tmpintfield = (sion_int64 *) malloc(sion_filedesc->
ntasks *
sizeof(sion_int64));
569 if (sion_tmpintfield == NULL) {
570 free(sion_tmpintfield_buddy32);
571 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",
572 (
unsigned long) ntasks *
sizeof(sion_int64)));
576 for (j = 0; j < sion_filedesc->
ntasks; j++)
577 DPRINTFP((2048,
"_sion_paropen_generic_one_file", rank,
" read, blockcount on task %02d is %10ld\n", j, (
long) sion_tmpintfield[j]));
581 DPRINTFTS(rank,
"before scatter");
582 if (! (flag&_SION_INTERNAL_FLAG_BUDDY_READ) ) {
583 sion_gendata->apidesc->scatterr_cb(sion_tmpintfield, &helpint64, comm_group, _SION_INT64, 1, 0);
586 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]];
587 sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy64, &helpint64, comm_group, _SION_INT64, 1, 0);
589 DPRINTFTS(rank,
"after scatter");
591 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
" lastchunknr on task %02d is %10ld\n", rank, (
long) sion_filedesc->
lastchunknr));
595 DPRINTFTS(rank,
"before scatter");
596 if (! (flag&_SION_INTERNAL_FLAG_BUDDY_READ) ) {
597 sion_gendata->apidesc->scatterr_cb(sion_tmpintfield, &helpint64, comm_group, _SION_INT64, 1, 0);
600 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]];
601 sion_gendata->apidesc->scatterr_cb(sion_tmpintfield_buddy64, &helpint64, comm_group, _SION_INT64, 1, 0);
603 DPRINTFTS(rank,
"after scatter");
614 DPRINTFTS(rank,
"before setp");
615 sion_gendata->apidesc->barrier_cb(comm_group);
629 if(sion_tmpintfield) free(sion_tmpintfield);
630 if(sion_tmpintfield_map) free(sion_tmpintfield_map);
631 if(sion_tmpintfield_buddy32) free(sion_tmpintfield_buddy32);
632 if(sion_tmpintfield_buddy64) free(sion_tmpintfield_buddy64);
634 sion_gendata->apidesc->barrier_cb(comm_group);
635 DPRINTFTS(rank,
"after setp");
638 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_multi_mpi: unknown file mode"));
644 *fileptr=sion_filedesc->
fileptr->fileptr;
652 if(fileptr!=NULL) *fileptr=NULL;
663 DPRINTFP((32,
"_sion_paropen_generic_one_file", rank,
" start position on task %02d is at end of sion_paropen_generic %10lld\n", rank,
666 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));
699 int rc = SION_SUCCESS;
701 sion_int64 helpint64;
702 sion_int64 *sion_tmpintfield = NULL;
704 void *comm_group=NULL;
708 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: invalid sion_filedesc, aborting %d ...\n", sid));
712 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));
715 DPRINTFP((2,
"_sion_parclose_generic", rank,
"enter parallel close sid=%d\n", sid));
718 if(flag& _SION_INTERNAL_FLAG_NORMAL ) comm_group=sion_gendata->comm_data_local;
719 if(flag& _SION_INTERNAL_FLAG_BUDDY_SEND ) comm_group=buddy_data->buddy_send.commgroup;
720 if(flag& _SION_INTERNAL_FLAG_BUDDY_COLL ) comm_group=buddy_data->buddy_coll.commgroup;
721 if(flag& _SION_INTERNAL_FLAG_BUDDY_READ ) comm_group=buddy_data->groups[buddy_data->currentgroup]->commgroup;
725 if (flag&_SION_INTERNAL_FLAG_BUDDY_SEND) do_close_file=0;
726 if ( (flag&_SION_INTERNAL_FLAG_BUDDY_COLL) && (rank>0) ) do_close_file=0;
727 if ( (flag&_SION_INTERNAL_FLAG_BUDDY_READ) && (rank>0) ) do_close_file=0;
734 DPRINTFP((32,
"_sion_parclose_generic", rank,
" parallel close (read mode) sid=%d, call fclose on file\n", sid));
758 DPRINTFP((32,
"_sion_parclose_generic", rank,
" parallel close (write mode) sid=%d, call fclose on file\n", sid));
767 sion_gendata->apidesc->barrier_cb(comm_group);
769 DPRINTFP((32,
"_sion_parclose_generic", rank,
" parallel close sid=%d: lastchunknr=%d globalskip=%lld\n", sid, sion_filedesc->
lastchunknr,
771 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
772 DPRINTFP((1024,
"_sion_parclose_generic", rank,
" parallel close sid=%d: local block %02d -> %10lld bytes\n", sid, blknum,
777 sion_tmpintfield = (sion_int64 *) malloc(sion_filedesc->
ntasks *
sizeof(sion_int64));
778 if (sion_tmpintfield == NULL) {
779 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield), aborting ...\n",
780 (
unsigned long) sion_filedesc->
ntasks *
sizeof(sion_int64)));
785 DPRINTFTS2(rank,
"before gather");
787 sion_gendata->apidesc->gatherr_cb(&helpint64, sion_tmpintfield, comm_group, _SION_INT64, 1, 0);
791 for (blknum = 0; blknum < sion_filedesc->
ntasks; blknum++)
793 sion_filedesc->
maxusedchunks = (int) sion_tmpintfield[blknum];
795 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
maxusedchunks, comm_group, _SION_INT32, 1, 0);
796 DPRINTFTS2(rank,
"after gather");
810 for (blknum = 0; blknum < sion_filedesc->
maxusedchunks; blknum++) {
811 if (blknum <= sion_filedesc->lastchunknr) {
812 helpint64 = sion_filedesc->
blocksizes[blknum];
818 DPRINTFTS2(rank,
"before gather");
819 sion_gendata->apidesc->gatherr_cb(&helpint64, sion_tmpintfield, comm_group, _SION_INT64, 1, 0);
820 DPRINTFTS2(rank,
"after gather");
823 for (lrank = 0; lrank < ntasks; lrank++)
824 DPRINTFP((2048,
"_sion_parclose_generic", rank,
" parallel close sid=%d: write total chunksize for block %d: %2lld rank=%d\n", sid, blknum,
825 sion_tmpintfield[lrank], lrank));
833 if (mapping != NULL) {
839 DPRINTFP((32,
"_sion_parclose_generic", rank,
" parallel close (write mode) sid=%d, call fclose on file\n", sid));
847 if(sion_tmpintfield) free(sion_tmpintfield);
852 _sion_free_filedesc(sion_filedesc);
853 sion_filedesc = NULL;
856 DPRINTFP((2,
"_sion_parclose_generic", rank,
"leave parallel close sid=%d\n", sid));
867 sion_int64 chunksize,
873 int rc = SION_SUCCESS;
875 sion_int64 lchunksize, lstartpointer, lglobalrank;
876 void *comm_group=NULL;
879 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parreinit_generic: invalid sion_filedesc, aborting %d ...\n", sid));
883 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));
886 DPRINTFP((2,
"_sion_parreinit_generic", sion_filedesc->
rank,
"enter parallel reinit sid=%d\n", sid));
888 comm_group=sion_gendata->comm_data_local;
891 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));
894 DPRINTFTS(sion_filedesc->
rank,
"before alloc");
895 if (sion_filedesc->
rank == 0) {
899 DPRINTFTS(sion_filedesc->
rank,
"after alloc");
902 lchunksize = (sion_int64) chunksize;
903 lglobalrank = (sion_int64) sion_filedesc->
globalrank;
905 DPRINTFTS2(sion_filedesc->
rank,
"before gather");
906 sion_gendata->apidesc->gatherr_cb(&lchunksize, sion_filedesc->
all_chunksizes, comm_group, _SION_INT64, 1, 0);
907 sion_gendata->apidesc->gatherr_cb(&lglobalrank, sion_filedesc->
all_globalranks, comm_group, _SION_INT64, 1, 0);
909 DPRINTFTS2(sion_filedesc->
rank,
"after gather");
913 if (sion_filedesc->
rank == 0) {
914 DPRINTFTS(sion_filedesc->
rank,
"before calculate");
915 if (!sion_filedesc->
usecoll) _sion_calculate_startpointers(sion_filedesc);
916 else _sion_calculate_startpointers_collective(sion_filedesc);
917 DPRINTFTS(sion_filedesc->
rank,
"after calculate");
921 if (sion_filedesc->
rank == 0) {
924 _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_METADATABLOCK1);
930 DPRINTFTS(sion_filedesc->
rank,
"before writeh");
932 DPRINTFTS(sion_filedesc->
rank,
"after writeh");
941 DPRINTFTS(sion_filedesc->
rank,
"before setp(0)");
944 DPRINTFTS(sion_filedesc->
rank,
"after setp(0)");
949 DPRINTFTS(sion_filedesc->
rank,
"before scatter");
950 sion_gendata->apidesc->scatterr_cb(sion_filedesc->
all_startpointers, &sion_filedesc->
startpos, comm_group, _SION_INT64, 1, 0);
951 DPRINTFTS(sion_filedesc->
rank,
"after scatter");
955 sion_gendata->apidesc->scatterr_cb(sion_filedesc->
all_coll_collsize, &sion_filedesc->
collsize, comm_group, _SION_INT32, 1, 0);
962 sion_gendata->apidesc->bcastr_cb(&sion_filedesc->
globalskip, comm_group, _SION_INT64, 1, 0);
964 DPRINTFP((32,
"_sion_parreinit_generic", sion_filedesc->
rank,
" start position is %10lld %10.4f MB\n",
968 DPRINTFTS(sion_filedesc->
rank,
"before setp");
969 sion_gendata->apidesc->barrier_cb(comm_group);
973 sion_filedesc->
chunksize = (sion_int64) chunksize;
974 sion_gendata->apidesc->barrier_cb(comm_group);
977 _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_CHUNK);
979 if (sion_filedesc->
rank == 0) {
984 DPRINTFTS(sion_filedesc->
rank,
"after setp");
985 DPRINTFP((32,
"_sion_parreinit_generic", sion_filedesc->
rank,
" ending open for write #tasks=%d filepos=%lld\n",
988 DPRINTFP((2,
"_sion_parreinit_generic", sion_filedesc->
rank,
"leave parallel reinit of file %s in #tasks=%d\n",
1001 #define DFUNCTION "_sion_generic_collect_mapping" 1002 int _sion_generic_collect_mapping(
_sion_filedesc *sion_filedesc,
1004 sion_int32 **mapping ) {
1005 int rc=SION_SUCCESS;
1009 sion_int32 lpos[2], *receivemap=NULL, iamreceiver, receiver = -1;
1012 sion_gendata=sion_filedesc->
dataptr;
1013 sion_apidesc=sion_gendata->apidesc;
1015 *mapping = NULL; *mapping_size = 0;
1023 *mapping_size=sion_gendata->gsize;
1024 *mapping = (sion_int32 *) malloc(*mapping_size * 2 *
sizeof(sion_int32));
1025 if (*mapping == NULL) {
1026 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_parclose: Cannot allocate memory for mapping"));
1031 if(sion_gendata->grank==0) {
1032 receivemap = (sion_int32 *) malloc(sion_gendata->gsize *
sizeof(sion_int32));
1033 if (receivemap == NULL) {
1034 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_generic_parclose: Cannot allocate memory for receivemap"));
1038 if((sion_filedesc->
filenumber==0) && (sion_filedesc->
rank==0)) iamreceiver=sion_gendata->grank;
1039 else iamreceiver=-1;
1040 sion_apidesc->gatherr_cb(&iamreceiver, receivemap, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
1041 if(sion_gendata->grank==0) {
1042 for(t=0;t<sion_gendata->gsize;t++) {
1043 if(receivemap[t]>=0) {
1044 receiver=receivemap[t];
1048 DPRINTFP((1,
DFUNCTION, sion_gendata->grank,
"receiver of mapping grank=%d\n", receiver));
1050 sion_apidesc->bcastr_cb(&receiver, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
1054 lpos[1] = sion_filedesc->
rank;
1055 sion_apidesc->gatherr_cb(&lpos, *mapping, sion_gendata->comm_data_global, _SION_INT32, 2, receiver);
1058 if(receivemap!=NULL) free(receivemap);
long _sion_file_get_opt_blksize(_sion_fileptr *sion_fileptr)
Get optional file system block size for a file.
sion_int64 _sion_file_get_position(_sion_fileptr *sion_fileptr)
Get new position in file.
int _sion_buffer_flush(_sion_filedesc *sion_filedesc)
Flush buffer.
int _sion_flush_block(_sion_filedesc *sion_filedesc)
Update the internal data structure.
sion_int64 _sion_file_set_position(_sion_fileptr *sion_fileptr, sion_int64 startpointer)
Set new position in file.
_sion_filedesc * _sion_alloc_filedesc()
Allocates memory for internal sion structure.
int _sion_reassignvcd(int sid, void *data, int type)
_sion_fileptr * _sion_file_open(const char *fname, unsigned int flags, unsigned int addflags)
Create and open a new file for writing.
Sion File Descriptor Structure.
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.
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.
#define SION_FILE_FLAG_WRITE
int _sion_file_purge(_sion_fileptr *sion_fileptr)
Purge data to file.
sion_int64 * all_globalranks
int _sion_alloc_filedesc_arrays(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion arrays.
int _sion_free_filedesc_arrays(_sion_filedesc *sion_filedesc)
free memory for the internal sion arrays
#define SION_FILE_FLAG_READ
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_vcdtype(int sid)
sion_int32 * all_coll_collector
sion_int32 fileptr_exported
sion_int32 _sion_get_endianness_with_flags(sion_int64 flags)
Return endianness including possible choice via flags.
#define SION_FILE_FLAG_POSIX
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)
sion_int32 * all_coll_capability
void * _sion_vcdtovcon(int sid)
#define SION_FILE_FLAG_ANSI
#define SION_FILE_FLAG_CREATE
#define SION_FILEMODE_READ
sion_int64 * all_startpointers
int _sion_file_close(_sion_fileptr *sion_fileptr)
Close file and destroys fileptr structure.
#define SION_FILESTATE_PAROPEN
int _sion_free_filedesc_coll_arrays(_sion_filedesc *sion_filedesc)
free memory for the internal sion arrays
int _sion_buffer_check_env(_sion_filedesc *sion_filedesc)
Checks if environment variables are set to use buffer.
sion_int32 coll_capability
sion_int32 currentblocknr
int _sion_cache_check_env(_sion_filedesc *sion_filedesc)
Check if environment variables are set to use cache.
#define SION_FILEDESCRIPTOR
sion_int64 * all_chunksizes
int _sion_print_filedesc(_sion_filedesc *sion_filedesc, int level, char *desc, int flag)
Print the initialized sion file description.
#define SION_FILESTATE_CLOSE
int _sion_alloc_filedesc_coll_arrays(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion arrays.
int _sion_init_filedesc(_sion_filedesc *sion_filedesc)
Initialize the sion file description.
#define SION_FILEMODE_WRITE
#define DFUNCTION
collect mapping information on rank 0 of first file, mapping=NULL for all others
sion_int32 * all_coll_collsize
sion_int64 start_of_varheader
int _sion_file_flush(_sion_fileptr *sion_fileptr)
Flush data to file.