18 #define _XOPEN_SOURCE 700
27 #include "sion_error_handler.h"
44 #define _SION_CONST_MAX_INT32 2147483647
72 sion_int64 file_mode_flags,
77 sion_int64 **chunksizes,
78 int **mapping_filenrs,
80 sion_int32 *fsblksize,
87 int filenr, root, task;
91 sion_int64 helpint64, apiflag, new_fsblocksize, lstartpointer;
93 sion_int32 *sion_count = NULL;
95 sion_int64 *sion_tmpintfield2 = NULL;
96 sion_int64 *sion_tmpintfield3 = NULL;
99 int *lfilecounter,*lfilemanager, ltask, tmpsize, blknum;
102 #if defined(_SION_SIONFWD)
103 else if (file_mode_flags&_SION_FMODE_SIONFWD) apiflag=SION_FILE_FLAG_SIONFWD;
105 #ifdef _SION_IME_NATIVE
106 else if (file_mode_flags&_SION_FMODE_IME_NATIVE) apiflag=SION_FILE_FLAG_IME_NATIVE;
110 DPRINTFP((2,
"_sion_paropen_mapped_generic", rank,
"enter parallel open sid=%d\n", sid));
113 if (sion_filedesc_master == NULL) {
114 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate filedescriptor structure of size %lu (sion_filedesc_master), aborting ...\n",
115 (
unsigned long)
sizeof(sion_filedesc_master)));
119 sion_filedesc_master->
fname = strdup(fname);
123 if (file_mode_flags&_SION_FMODE_WRITE) {
126 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" starting open for write #tasks=%d\n", ntasks));
129 for(ltask=0;ltask<*nlocaltasks;ltask++) {
130 DPRINTFP((128,
"_sion_paropen_mapped_generic", rank,
"input: %2d: f=%d gtask=%2d ltask=%d --> %d\n", ltask,
131 (
int) (*mapping_filenrs)[ltask],
132 (
int) (*globalranks)[ltask],
133 (
int) (*mapping_lranks)[ltask],
134 (
int) (*chunksizes)[ltask]
142 sion_filedesc_master->
sid=sid;
143 sion_filedesc_master->
nfiles=*numFiles;
146 if (sion_filedesc_master->
multifiles == NULL) {
147 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure vector of size %lu (chunksizes), aborting ...\n",
157 lfilecounter = (
int *) malloc(*numFiles *
sizeof(
int));
158 if (lfilecounter == NULL) {
159 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (lfilecounter), aborting ...\n",
160 (
unsigned long) *numFiles *
sizeof(int)));
162 lfilemanager = (
int *) malloc(*numFiles *
sizeof(
int));
163 if (lfilemanager == NULL) {
165 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (lfilemanager), aborting ...\n",
166 (
unsigned long) *numFiles *
sizeof(
int)));
169 sion_count = (sion_int32 *) malloc(ntasks *
sizeof(sion_int32));
170 if (sion_count == NULL) {
173 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (sion_count), aborting ...\n",
174 (
unsigned long) ntasks *
sizeof(sion_int32)));
179 for(filenr=0;filenr<*numFiles;filenr++) lfilecounter[filenr]=lfilemanager[filenr]=0;
180 for(ltask=0;ltask<*nlocaltasks;ltask++) {
181 filenr=(*mapping_filenrs)[ltask];
182 if((filenr<0) || (filenr>=*numFiles)){
186 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: on task %d: wrong file number index (%d) in mapping for task %d, aborting ...\n",
189 lfilecounter[filenr]++;
190 if((*mapping_lranks)[ltask]==0) {
191 lfilemanager[filenr]=1;
198 _sion_keyval_check_env(sion_filedesc_master, file_mode_flags);
201 for(filenr=0;filenr<*numFiles;filenr++) {
203 DPRINTFP((4,
"_sion_paropen_mapped_generic", rank,
" starting init of SION #%d of %d (%d local tasks) \n", filenr,*numFiles,lfilecounter[filenr]));
207 helpint32 = lfilemanager[filenr];
208 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
210 for(task=0;task<ntasks;task++) {
211 if(sion_count[task]==1) root=task;
215 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64,1 , 0); root=helpint64;
217 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: on task %d: local rank 0 of file number index (%d) will not used by any tasks, aborting ...\n",
221 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" file #%d will be managed by task %d \n", filenr,root));
225 if (sion_filedesc_sub == NULL) {
226 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate filedescriptor structure of size %lu (sion_filedesc), aborting ...\n",
227 (
unsigned long)
sizeof(sion_filedesc_sub)));
229 sion_filedesc_master->
multifiles[filenr]=sion_filedesc_sub;
233 sion_filedesc_sub->
fname = (sion_gendata->apidesc->get_multi_filename_cb?sion_gendata->apidesc->get_multi_filename_cb:
_sion_get_multi_filename)(fname, filenr);
242 sion_filedesc_sub->
fsblksize = *fsblksize;
244 sion_filedesc_sub->
nfiles = *numFiles;
246 sion_filedesc_sub->
prefix = strdup(prefix);
247 sion_filedesc_sub->
compress = file_mode_flags&_SION_FMODE_COMPRESS;
248 sion_filedesc_sub->
usecoll = file_mode_flags&_SION_FMODE_COLLECTIVE;
252 _sion_keyval_check_env(sion_filedesc_sub, file_mode_flags);
265 helpint32 = lfilecounter[filenr];
267 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, root);
270 for(task=0;task<ntasks;task++) helpint64 += sion_count[task];
272 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64, 1, root);
275 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
"mapping size increased to %d\n",sion_filedesc_master->
mapping_size));
279 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" file #%d (%s) will store chunks from %d tasks (%d local) \n",
280 filenr,sion_filedesc_sub->
fname,
285 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" create file #%d (%s) \n", filenr,sion_filedesc_sub->
fname));
288 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_generic: cannot open %s for writing, aborting ...\n", fname));
293 if((new_fsblocksize<0) || (new_fsblocksize>SION_MAX_FSBLOCKSIZE)) new_fsblocksize=SION_DEFAULT_FSBLOCKSIZE;
294 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" found new_fsblksize of %d\n", (
int) new_fsblocksize));
301 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
303 sion_gendata->apidesc->bcastr_cb(&new_fsblocksize, sion_gendata->comm_data_global, _SION_INT64, 1, root);
304 sion_filedesc_sub->
fsblksize = new_fsblocksize;
305 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" setting fsblksize to %d\n", (
int) new_fsblocksize));
312 sion_tmpintfield2 = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
313 if (sion_tmpintfield2 == NULL) {
314 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield2), aborting ...\n",
315 (
unsigned long) tmpsize *
sizeof(sion_int64)));
319 sion_tmpintfield3 = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
320 if (sion_tmpintfield3 == NULL) {
321 free(sion_tmpintfield2);
322 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield3), aborting ...\n",
323 (
unsigned long) tmpsize *
sizeof(sion_int64)));
325 }
else sion_tmpintfield3 = NULL;
329 for(ltask=0;ltask<*nlocaltasks;ltask++) {
330 lfilenr=(int) (*mapping_filenrs)[ltask];
331 if(lfilenr==filenr) {
332 sion_tmpintfield2[p*3+0]=(sion_int64) (*mapping_lranks)[ltask];
333 sion_tmpintfield2[p*3+1]=(sion_int64) (*globalranks)[ltask];
334 sion_tmpintfield2[p*3+2]=(sion_int64) (*chunksizes)[ltask];
335 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" prepare %d --> lrank=%d %d %d\n", p,(
int) sion_tmpintfield2[p*3+0],(
int) sion_tmpintfield2[p*3+1],(
int) sion_tmpintfield2[p*3+2]));
344 if (rank == root)
for(task=0;task<ntasks;task++) sion_count[task]*=3;
345 sion_gendata->apidesc->gathervr_cb(sion_tmpintfield2, sion_tmpintfield3, sion_gendata->comm_data_global, _SION_INT64,sion_count,3*sion_filedesc_sub->
nlocaltasksinfile, root);
346 if (rank == root)
for(task=0;task<ntasks;task++) sion_count[task]/=3;
363 lrank=(int) sion_tmpintfield3[ltask*3+0];
364 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" sort in ltask=%d --> lrank=%d\n", ltask,lrank));
365 sion_filedesc_sub->
all_globalranks[lrank]=sion_tmpintfield3[ltask*3+1];
366 sion_filedesc_sub->
all_chunksizes[lrank] =sion_tmpintfield3[ltask*3+2];
370 _sion_calculate_startpointers(sion_filedesc_sub);
375 DPRINTFTS(rank,
"before open");
378 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_generic: cannot open %s for reading, aborting ...\n", fname));
380 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
381 DPRINTFTS(rank,
"after open");
384 sion_filedesc_sub->
fileptr = sion_fileptr;
386 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" store for file %s fileprt=%x\n",sion_filedesc_sub->
fname, sion_fileptr ));
391 DPRINTFTS(rank,
"before writeh");
394 DPRINTFTS(rank,
"after writeh");
403 DPRINTFTS(rank,
"before setp(0)");
406 DPRINTFTS(rank,
"after setp(0)");
409 _sion_free_filedesc_all_globalranks(sion_filedesc_sub);
413 _sion_alloc_filedesc_all_globalranks(sion_filedesc_sub);
414 _sion_alloc_filedesc_all_localranks(sion_filedesc_sub);
422 _sion_alloc_filedesc_all_localranks(sion_filedesc_sub);
427 _sion_alloc_filedesc_all_keyvalptr(sion_filedesc_sub);
432 sion_filedesc_sub->
all_localranks[ltask] = sion_tmpintfield2[ltask*3+0];
433 sion_filedesc_sub->
all_globalranks[ltask] = sion_tmpintfield2[ltask*3+1];
441 lrank=(int) sion_tmpintfield3[ltask*3+0];
443 sion_tmpintfield3[ltask*3+2]=sion_filedesc_sub->
all_chunksizes[lrank];
444 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" sort out ltask=%d --> lrank=%d startptr=%ld chunksize=%ld\n",
445 ltask,lrank,(
long) sion_tmpintfield3[ltask*3+1],sion_tmpintfield3[ltask*3+2]));
448 if (rank == root)
for(task=0;task<ntasks;task++) sion_count[task]*=3;
449 sion_gendata->apidesc->scattervr_cb(sion_tmpintfield2, sion_tmpintfield3, sion_gendata->comm_data_global, _SION_INT64,sion_count,3*sion_filedesc_sub->
nlocaltasksinfile, root);
450 if (rank == root)
for(task=0;task<ntasks;task++) sion_count[task]/=3;
454 _sion_free_filedesc_all_startpointers(sion_filedesc_sub);
455 _sion_free_filedesc_all_chunksizes(sion_filedesc_sub);
457 _sion_alloc_filedesc_all_startpointers(sion_filedesc_sub);
458 _sion_alloc_filedesc_all_chunksizes(sion_filedesc_sub);
463 sion_filedesc_sub->
all_chunksizes[ltask] = sion_tmpintfield2[ltask*3+2];
464 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" get startpointer[%d] --> %ld\n", ltask, sion_filedesc_sub->
all_startpointers[ltask]));
468 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
globalskip, sion_gendata->comm_data_global, _SION_INT64, 1, root);
472 DPRINTFTS(rank,
"before setp");
473 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
476 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" allocating block arrays of size %d\n", sion_filedesc_sub->
ntasks));
481 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" set all_currentpos[%d]=%d\n",ltask,sion_filedesc_sub->
all_currentpos[ltask] ));
487 sion_filedesc_sub->
rank = 0;
498 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
500 if(sion_tmpintfield2) free(sion_tmpintfield2);
501 if(sion_tmpintfield3) free(sion_tmpintfield3);
503 DPRINTFP((4,
"_sion_paropen_mapped_generic", rank,
" ending init of SION #%d of %d \n", filenr,*numFiles));
512 {
int lfile=-1, lrank=-1, blknum;
513 sion_filedesc_sub=NULL;
514 for(filenr=0;filenr<*numFiles;filenr++) {
515 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
525 if((sion_filedesc_sub) && (lrank>=0) && (lfile>=0)) {
530 sion_filedesc_master->
rank = lrank;
547 for (blknum = 0; blknum < sion_filedesc_sub->
all_blockcount[lrank]; blknum++) {
557 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"set startpointer to %d\n",(
int) sion_filedesc_master->
currentpos));
562 *fileptr=sion_filedesc_master->
fileptr->fileptr;
574 if(sion_count) free(sion_count);
576 if(lfilecounter) free(lfilecounter);
577 if(lfilemanager) free(lfilemanager);
581 }
else if (file_mode_flags&_SION_FMODE_READ) {
584 int mapping_size,mapsid=-1, rootcounter;
586 sion_int32 lfsblksize;
590 DPRINTFP((1,
"_sion_paropen_mapped_generic", rank,
"read mode ntasks=%d\n",ntasks));
592 for(ltask=0;ltask<*nlocaltasks;ltask++) {
593 DPRINTFP((128,
"_sion_paropen_mapped_generic", rank,
"input: %2d: gtask=%2d \n", ltask, (
int) (*globalranks)[ltask]));
599 sion_filedesc_master->
sid=sid;
602 sion_count = (sion_int32 *) malloc(ntasks *
sizeof(sion_int32));
603 if (sion_count == NULL) {
604 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (sion_count), aborting ...\n",
605 (
unsigned long) ntasks *
sizeof(sion_int32)));
613 DPRINTFP((1,
"_sion_paropen_mapped_generic", rank,
"before open\n"));
614 mapsid=
_sion_open_read(fname,_SION_FMODE_READ|_SION_FMODE_ANSI,_SION_READ_MASTER_ONLY_OF_MULTI_FILES,
615 &lntasks,&lnfiles,NULL,&lfsblksize,NULL,&lfileptr);
617 DPRINTFP((1,
"_sion_paropen_mapped_generic", rank,
"after open\n"));
619 DPRINTFP((1,
"_sion_paropen_mapped_generic", rank,
"sion file %d files #tasks=%d rc=%d\n", *numFiles,mapping_size,rc));
622 lfilemanager = (
int *) malloc(*numFiles *
sizeof(
int));
623 if (lfilemanager == NULL) {
624 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (lfilemanager), aborting ...\n",
625 (
unsigned long) *numFiles *
sizeof(
int)));
632 for(task=0;task<mapping_size;task++) {
633 if(mapping[task*2+1]==0) {
634 lfilemanager[mapping[task*2+0]]=task;
635 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" manager of file %d is grank=%d\n",mapping[task*2+0],task));
649 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot find file %s , aborting ...\n",fname));
654 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_master->
mapping_size, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
655 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" mapping_size is=%d\n",sion_filedesc_master->
mapping_size));
659 if (mapsid>=0) _sion_close_sid(mapsid);
666 int tasks_per_task = sion_filedesc_master->
mapping_size / ntasks;
667 int startpos = rank*tasks_per_task;
668 int endpos = (rank+1)*tasks_per_task;
671 if(endpos<sion_filedesc_master->mapping_size) endpos=sion_filedesc_master->
mapping_size;
673 *nlocaltasks=endpos-startpos;
674 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"pre-compute distribution: startpos=%d endpos=%d nlocaltasks=%d\n",startpos, endpos, (
int) *nlocaltasks ));
676 if (globalranks == NULL) {
678 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate globalranks, not pointer parameter given, aborting ...\n"));
680 if (mapping_filenrs == NULL) {
682 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate mapping_filenrs, not pointer parameter given, aborting ...\n"));
684 if (mapping_lranks == NULL) {
686 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate mapping_lranks, not pointer parameter given, aborting ...\n"));
688 if ((*globalranks) != NULL) {
690 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate globalranks, memory allready allocated (unknown size), aborting ...\n"));
692 if ((*mapping_filenrs) != NULL) {
694 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate mapping_filenrs, memory allready allocated (unknown size), aborting ...\n"));
696 if ((*mapping_lranks) != NULL) {
698 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate mapping_lranks, memory allready allocated (unknown size), aborting ...\n"));
702 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"allocate globalranks field for parameter size=%d\n",(
int) *nlocaltasks ));
703 *globalranks = (sion_int32 *) malloc(*nlocaltasks *
sizeof(sion_int32));
704 if (*globalranks == NULL) {
706 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate memory of size %lu (globalranks), aborting ...\n", (
unsigned long)
sizeof(sion_int32)));
710 for(task=startpos;task<endpos;task++) {
711 (*globalranks)[ltask]=task;
712 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"set *globalranks[%d]=%d\n",(
int) ltask,(*globalranks)[ltask]));
719 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_master->
keyvalmode, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
720 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" keyvalmode is=%d\n",sion_filedesc_master->
keyvalmode));
723 _sion_keyval_check_env(sion_filedesc_master, file_mode_flags);
726 if (rank == 0) helpint64=*numFiles;
727 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64, 1, 0); *numFiles=helpint64;
728 sion_filedesc_master->
nfiles=*numFiles;
732 if (sion_filedesc_master->
multifiles == NULL) {
733 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure vector of size %lu (chunksizes), aborting ...\n",
739 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
741 DPRINTFP((4,
"_sion_paropen_mapped_generic", rank,
" starting init of SION #%d of %d\n", filenr,*numFiles));
743 #ifdef _SION_FIND_ROOT_LRANK_NULL_DO_NOT_USE
750 helpint64=lfilemanager[filenr];
752 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64, 1, 0);
757 for(task=0;task<*nlocaltasks;task++) {
758 if((*globalranks)[task]==grankroot) helpint32=1;
762 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
764 for(task=0;task<ntasks;task++) {
765 if(sion_count[task]==1) {
776 rootcounter=( (rootcounter+1) % ntasks);
777 helpint64=rootcounter;
780 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64, 1, 0);
782 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" manager of file %d is rank=%d\n",filenr,root));
786 if (sion_filedesc_sub == NULL) {
787 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate filedescriptor structure of size %lu (sion_filedesc), aborting ...\n",
788 (
unsigned long)
sizeof(sion_filedesc_sub)));
790 sion_filedesc_master->
multifiles[filenr]=sion_filedesc_sub;
792 sion_filedesc_sub->
fname = (sion_gendata->apidesc->get_multi_filename_cb?sion_gendata->apidesc->get_multi_filename_cb:
_sion_get_multi_filename)(fname, filenr);
801 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" starting open for read on file %s\n", sion_filedesc_sub->
fname));
802 DPRINTFTS(rank,
"before open");
803 sion_filedesc_sub->
fileptr=NULL;
807 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot open %s for reading, aborting ...\n", fname));
809 sion_filedesc_sub->
fileptr = sion_fileptr;
811 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
812 DPRINTFTS(rank,
"after open root");
817 if (rc!=SION_SUCCESS) {
818 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot read header from file %s, aborting ...\n", fname));
820 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
821 " read, after read of fix header part endianness=0x%x blksize=%d ntasks=%d\n", sion_filedesc_sub->
endianness, sion_filedesc_sub->
fsblksize, sion_filedesc_sub->
ntasks));
823 DPRINTFTS(rank,
"before alloc");
826 DPRINTFTS(rank,
"after alloc");
829 if (rc != SION_SUCCESS) {
830 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot read header from file %s, aborting ...\n", fname));
833 _sion_coll_check_env(sion_filedesc_sub);
837 if (!sion_filedesc_sub->
usecoll) _sion_calculate_startpointers(sion_filedesc_sub);
838 else _sion_calculate_startpointers_collective(sion_filedesc_sub);
839 DPRINTFTS(rank,
"after calculate");
842 _sion_keyval_check_env(sion_filedesc_sub, file_mode_flags);
847 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
globalskip, sion_gendata->comm_data_global, _SION_INT64, 1, root);
850 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
endianness, sion_gendata->comm_data_global, _SION_INT32, 1, root);
851 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
swapbytes, sion_gendata->comm_data_global, _SION_INT32, 1, root);
852 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
fsblksize, sion_gendata->comm_data_global, _SION_INT32, 1, root);
853 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
ntasks, sion_gendata->comm_data_global, _SION_INT32, 1, root);
856 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
fileversion, sion_gendata->comm_data_global, _SION_INT32, 1, root);
857 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
nfiles, sion_gendata->comm_data_global, _SION_INT32, 1, root);
858 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
filenumber, sion_gendata->comm_data_global, _SION_INT32, 1, root);
859 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
flag1, sion_gendata->comm_data_global, _SION_INT64, 1, root);
860 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
flag2, sion_gendata->comm_data_global, _SION_INT64, 1, root);
861 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
maxusedchunks, sion_gendata->comm_data_global, _SION_INT32, 1, root);
862 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
start_of_varheader, sion_gendata->comm_data_global, _SION_INT64, 1, root);
863 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
866 DPRINTFTS(rank,
"after bcast");
873 sion_tmpintfield2 = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
874 if (sion_tmpintfield2 == NULL) {
875 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield2), aborting ...\n",
876 (
unsigned long) tmpsize *
sizeof(sion_int64)));
881 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
886 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" scan for gtask=%d\n", (
int) sion_tmpintfield2[task]));
887 for(ltask=0;ltask<*nlocaltasks;ltask++) {
888 if( (
int) sion_tmpintfield2[task]==(*globalranks)[ltask]) {
889 sion_tmpintfield2[task]=-1 * (sion_tmpintfield2[task] + 1);
894 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" found %d globalranks for file %s\n", sion_filedesc_sub->
nlocaltasksinfile, sion_filedesc_sub->
fname));
896 DPRINTFTS(rank,
"before open non-root");
901 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot open %s for reading, aborting ...\n", fname));
903 sion_filedesc_sub->
fileptr = sion_fileptr;
906 DPRINTFTS(rank,
"after open non-root");
912 _sion_free_filedesc_all_globalranks(sion_filedesc_sub);
915 _sion_alloc_filedesc_all_globalranks(sion_filedesc_sub);
916 _sion_alloc_filedesc_all_localranks(sion_filedesc_sub);
921 _sion_alloc_filedesc_all_localranks(sion_filedesc_sub);
927 if(sion_tmpintfield2[task]<0) {
929 sion_filedesc_sub->
all_globalranks[ltask]= (-1 * sion_tmpintfield2[task]) - 1;
930 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" all_globalranks[%d]=%d all_localranks[%d]=%d\n",
940 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
942 _sion_free_filedesc_all_chunksizes(sion_filedesc_sub);
943 _sion_alloc_filedesc_all_chunksizes(sion_filedesc_sub);
955 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
957 _sion_free_filedesc_all_startpointers(sion_filedesc_sub);
958 _sion_alloc_filedesc_all_startpointers(sion_filedesc_sub);
975 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" got from file blockcount[%d]=%d\n",task,(
int) sion_tmpintfield2[task]));
977 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
982 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" store blockcount task=%d -> ltask=%d cnt=%d\n",task,ltask,(
int) sion_tmpintfield2[task]));
987 for (blknum = 0; blknum < sion_filedesc_sub->
maxusedchunks; blknum++) {
993 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
1002 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
keyvalmode, sion_gendata->comm_data_global, _SION_INT32, 1, root);
1005 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
usecoll, sion_gendata->comm_data_global, _SION_INT32, 1, root);
1006 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
collsize, sion_gendata->comm_data_global, _SION_INT32, 1, root);
1008 if(sion_filedesc_sub->
usecoll) {
1012 sion_tmpintfield2[task]= (sion_int64) (sion_filedesc_sub->
all_coll_collector[task]*_SION_CONST_MAX_INT32) + sion_filedesc_sub->
collsize;
1014 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
1018 _sion_alloc_filedesc_all_chunksizes(sion_filedesc_sub);
1021 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" store collsize+collector for %d elements\n",sion_filedesc_sub->
nlocaltasksinfile));
1036 sion_filedesc_sub->
rank = 0;
1046 _sion_alloc_filedesc_all_keyvalptr(sion_filedesc_sub);
1053 if(sion_tmpintfield2) free(sion_tmpintfield2);
1061 int lfile=-1,lrank=-1, blknum;
1062 sion_filedesc_sub=NULL;
1063 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1064 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1072 DPRINTFP((32,
"sion_paropen_mapped_generic",rank,
"init to first local rank in first file (%d, %d)\n",lfile,lrank));
1074 if((sion_filedesc_sub) && (lrank>=0) && (lfile>=0)) {
1075 DPRINTFP((32,
"sion_paropen_mapped_generic",rank,
"sion_filedesc_master->mapping_size=%d\n",sion_filedesc_master->
mapping_size));
1084 sion_filedesc_master->
rank = lrank;
1102 for(filenr=0;filenr<sion_filedesc_sub->
nfiles;filenr++) {
1107 for (blknum = 0; blknum < sion_filedesc_sub->
all_blockcount[lrank]; blknum++) {
1118 DPRINTFP((32,
"sion_paropen_mapped_generic",rank,
"set startpointer to %d\n",(
int) sion_filedesc_master->
currentpos));
1127 *fileptr=sion_filedesc_master->
fileptr->fileptr;
1136 sion_int64 *helpptr_chunksize = NULL;
1137 sion_int32 *helpptr_mapping_filenrs = NULL;
1138 sion_int32 *helpptr_mapping_lranks = NULL;
1141 if (chunksizes != NULL) {
1142 if ((*chunksizes) == NULL) {
1143 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"allocate chunksizes field for parameter size=%d\n",(
int) *nlocaltasks ));
1144 helpptr_chunksize = (sion_int64 *) malloc(*nlocaltasks *
sizeof(sion_int64));
1145 if (helpptr_chunksize == NULL) {
1146 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure of size %lu (chunksizes), aborting ...\n", (
unsigned long)
sizeof(sion_int64)));
1148 *chunksizes = helpptr_chunksize;
1150 helpptr_chunksize = *chunksizes;
1154 if (mapping_filenrs != NULL) {
1155 if ((*mapping_filenrs) == NULL) {
1156 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"allocate mapping_filenrs field for parameter size=%d\n",(
int) *nlocaltasks ));
1157 helpptr_mapping_filenrs = (sion_int32 *) malloc(*nlocaltasks *
sizeof(sion_int32));
1158 if (helpptr_mapping_filenrs == NULL) {
1159 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure of size %lu (mapping_filenrs), aborting ...\n", (
unsigned long)
sizeof(sion_int32)));
1161 *mapping_filenrs = helpptr_mapping_filenrs;
1163 helpptr_mapping_filenrs = *mapping_filenrs;
1167 if (mapping_lranks != NULL) {
1168 if ((*mapping_lranks) == NULL) {
1169 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"allocate mapping_lranks field for parameter size=%d\n",(
int) *nlocaltasks ));
1170 helpptr_mapping_lranks = (sion_int32 *) malloc(*nlocaltasks *
sizeof(sion_int32));
1171 if (helpptr_mapping_lranks == NULL) {
1172 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure of size %lu (mapping_lranks), aborting ...\n", (
unsigned long)
sizeof(sion_int32)));
1174 *mapping_lranks = helpptr_mapping_lranks;
1176 helpptr_mapping_lranks = *mapping_lranks;
1181 if(helpptr_chunksize || helpptr_mapping_filenrs || helpptr_mapping_lranks) {
1182 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1183 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1185 for(task=0;task<*nlocaltasks;task++) {
1187 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
" set chunksizes[%d]=%4d (filenr=%d, ltask=%d lrank=%d)\n",
1189 if(helpptr_chunksize) helpptr_chunksize[task] = sion_filedesc_sub->
all_chunksizes[ltask];
1190 if(helpptr_mapping_filenrs) helpptr_mapping_filenrs[task] = filenr;
1191 if(helpptr_mapping_lranks) helpptr_mapping_lranks[task] = sion_filedesc_sub->
all_localranks[ltask];
1200 _sion_print_filedesc(sion_filedesc_master, 512,
"_sion_paropen_mapped_generic", _SION_DEBUG_PRINT_ALL|_SION_DEBUG_PRINT_RECURSIVE);
1203 if(sion_count) free(sion_count);
1205 if(lfilemanager) free(lfilemanager);
1210 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_multi_mpi: unknown file mode"));
1217 int _sion_parclose_mapped_generic(
int sid,
1221 int rc=SION_SUCCESS;
1222 int lfile, grank, lrank, blknum, filenr, tmpsize, root, ltask, mappingroot, task;
1225 sion_int64 *sion_tmpintfield_send = NULL;
1226 sion_int64 *sion_tmpintfield_lrank_recv = NULL;
1227 sion_int64 *sion_tmpintfield_data_recv = NULL;
1228 sion_int64 *sion_tmpintfield_data = NULL;
1229 sion_int32 *mapping = NULL;
1230 sion_int32 *sion_tmpint32field_send = NULL;
1231 sion_int32 *sion_tmpint32field_data_recv = NULL;
1232 sion_int32 *sion_count = NULL;
1233 sion_int32 helpint32;
1235 DPRINTFP((2,
"_sion_parclose_mapped_generic", rank,
"enter parallel close sid=%d\n", sid));
1238 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: invalid sion_filedesc_master, aborting %d ...\n", sid));
1243 int numbytes, numfds;
1245 DPRINTFP((2,
"_sion_parclose_mapped_generic", rank,
"internal data size of sid %2d (%d bytes, %d fds) \n", sid,numbytes, numfds));
1253 return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN,sion_filedesc_master->
rank,
"sion_parclose_mapped: invalid file open state (!PAROPENMAPPED), aborting %d ...", sid));
1259 _sion_print_filedesc(sion_filedesc_master, 512,
"_sion_parclose_mapped_generic", _SION_DEBUG_PRINT_ALL|_SION_DEBUG_PRINT_RECURSIVE);
1267 lrank=sion_filedesc_master->
rank;
1268 if((lrank>=0) && (lfile>=0)) {
1269 sion_filedesc_sub=sion_filedesc_master->
multifiles[lfile];
1275 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1276 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1278 DPRINTFP((32,
"_sion_parclose_mapped_generic", rank,
" parallel close (read mode) call fclose on file %s (fileptr=%x)\n", sion_filedesc_sub->
fname,sion_filedesc_sub->
fileptr));
1280 if(sion_filedesc_sub->
fileptr!=NULL) {
1282 sion_filedesc_sub->
fileptr = NULL;
1288 _sion_free_filedesc(sion_filedesc_sub);
1291 _SION_SAFE_FREE(mapping, NULL);
1292 _SION_SAFE_FREE(sion_filedesc_master->
multifiles, NULL);
1297 _sion_free_filedesc(sion_filedesc_master);
1298 sion_filedesc_master = NULL;
1310 _sion_print_filedesc(sion_filedesc_master, 512,
"_sion_parclose_mapped_generic", _SION_DEBUG_PRINT_ALL|_SION_DEBUG_PRINT_RECURSIVE);
1314 lrank=sion_filedesc_master->
rank;
1315 sion_filedesc_sub=sion_filedesc_master->
multifiles[lfile];
1327 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
"on file %d: sub,maxchunk=%d master,maxchunk=%d \n", lfile,sion_filedesc_sub->
maxchunks, sion_filedesc_master->
maxchunks));
1333 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
"store current information lrank=%d lastchunknr=%d\n", lrank,sion_filedesc_sub->
lastchunknr));
1337 for (blknum = 0; blknum <= sion_filedesc_sub->
lastchunknr; blknum++) {
1342 sion_count = (sion_int32 *) malloc(ntasks *
sizeof(sion_int32));
1343 if (sion_count == NULL) {
1344 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (sion_count), aborting ...\n",
1345 (
unsigned long) ntasks *
sizeof(sion_int32)));
1349 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1351 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1352 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" starting close for file %d: %s \n", filenr,sion_filedesc_sub->
fname));
1359 DPRINTFP((32,
"_sion_parclose_mapped_generic", rank,
">parallel close (write mode, not managed) call fclose on file %s (fileptr=%x)\n", sion_filedesc_sub->
fname,sion_filedesc_sub->
fileptr));
1361 DPRINTFP((32,
"_sion_parclose_mapped_generic", rank,
"<parallel close (write mode, not managed) call fclose on file %s (fileptr=%x)\n", sion_filedesc_sub->
fname,sion_filedesc_sub->
fileptr));
1362 sion_filedesc_sub->
fileptr = NULL;
1367 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
1371 sion_tmpintfield_send = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
1372 if (sion_tmpintfield_send == NULL) {
1373 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield_send), aborting ...\n",
1374 (
unsigned long) tmpsize *
sizeof(sion_int64)));
1376 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" file %d: allocate send field for all local tasks of file (%d) --> %x\n", filenr, tmpsize, sion_tmpintfield_send));
1383 sion_tmpintfield_lrank_recv = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
1384 if (sion_tmpintfield_lrank_recv == NULL) {
1385 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield_lrank_recv), aborting ...\n",
1386 (
unsigned long) tmpsize *
sizeof(sion_int64)));
1388 sion_tmpintfield_data_recv = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
1389 if (sion_tmpintfield_data_recv == NULL) {
1390 free(sion_tmpintfield_lrank_recv);
1391 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield_data_recv), aborting ...\n",
1392 (
unsigned long) tmpsize *
sizeof(sion_int64)));
1394 sion_tmpintfield_data = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
1395 if (sion_tmpintfield_data == NULL) {
1396 free(sion_tmpintfield_data_recv);
1397 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield_data), aborting ...\n",
1398 (
unsigned long) tmpsize *
sizeof(sion_int64)));
1400 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" file %d: allocate fields for all tasks of file (%d)\n", filenr,tmpsize));
1403 }
else sion_tmpintfield_lrank_recv=sion_tmpintfield_data_recv=sion_tmpintfield_data=NULL;
1407 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, root);
1411 sion_tmpintfield_send[ltask]=sion_filedesc_sub->
all_localranks[ltask];
1413 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" file %d: before call of gathervr_cb %x %x %x %d %d %d\n",
1414 filenr,sion_tmpintfield_lrank_recv, sion_tmpintfield_send, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
nlocaltasksinfile, root));
1416 sion_gendata->apidesc->gathervr_cb(sion_tmpintfield_send, sion_tmpintfield_lrank_recv, sion_gendata->comm_data_global, _SION_INT64, sion_count, sion_filedesc_sub->
nlocaltasksinfile, root);
1420 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" send all_blockcount[%d]: %d\n", ltask, sion_filedesc_sub->
all_blockcount[ltask]));
1421 sion_tmpintfield_send[ltask]=sion_filedesc_sub->
all_blockcount[ltask];
1423 sion_gendata->apidesc->gathervr_cb(sion_tmpintfield_send, sion_tmpintfield_data_recv, sion_gendata->comm_data_global, _SION_INT64, sion_count, sion_filedesc_sub->
nlocaltasksinfile, root);
1429 if (sion_tmpintfield_data_recv[ltask] > sion_filedesc_sub->
maxusedchunks) {
1430 sion_filedesc_sub->
maxusedchunks = (int) sion_tmpintfield_data_recv[ltask];
1435 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
maxusedchunks, sion_gendata->comm_data_global, _SION_INT32, 1, root);
1436 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" file %d: maxusedchunks=%d\n", filenr,sion_filedesc_sub->
maxusedchunks));
1442 lrank=(int) sion_tmpintfield_lrank_recv[ltask];
1443 DPRINTFP((64,
"_sion_parclose_mapped_generic", rank,
" sort in ltask=%d --> lrank=%d blkcount=%d\n",
1444 ltask,lrank,sion_tmpintfield_data_recv[ltask]));
1445 sion_tmpintfield_data[lrank]=sion_tmpintfield_data_recv[ltask];
1460 for (blknum = 0; blknum < sion_filedesc_sub->
maxusedchunks; blknum++) {
1462 DPRINTFP((32,
"_sion_parclose_mapped_generic", rank,
" collect blocksize step %d of %d\n", blknum+1,sion_filedesc_sub->
maxusedchunks));
1465 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"sion_filedesc_sub->nlocaltasksinfile=%d\n",sion_filedesc_sub->
nlocaltasksinfile));
1468 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"sort in blksize[%d][%d]=%d\n",blknum, ltask, sion_tmpintfield_send[ltask]));
1470 sion_gendata->apidesc->gathervr_cb(sion_tmpintfield_send, sion_tmpintfield_data_recv, sion_gendata->comm_data_global, _SION_INT64, sion_count, sion_filedesc_sub->
nlocaltasksinfile, root);
1477 lrank=(int) sion_tmpintfield_lrank_recv[ltask];
1478 sion_tmpintfield_data[lrank]=sion_tmpintfield_data_recv[ltask];
1479 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"prepare blksize[%d][%d]=%ld\n",blknum,lrank,sion_tmpintfield_data[lrank]));
1488 if(sion_tmpintfield_lrank_recv) free(sion_tmpintfield_lrank_recv);
1489 if(sion_tmpintfield_data_recv) free(sion_tmpintfield_data_recv);
1490 if(sion_tmpintfield_data) free(sion_tmpintfield_data);
1491 if(sion_tmpintfield_send) free(sion_tmpintfield_send);
1493 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" ending close for file %d: %s \n", filenr,sion_filedesc_sub->
fname));
1499 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"mappingroot=%d rank=%d\n", mappingroot, rank ));
1500 if(rank==mappingroot) {
1501 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"allocate mapping of size %d\n",sion_filedesc_master->
mapping_size));
1502 mapping = (sion_int32 *) malloc(sion_filedesc_master->
mapping_size * 2 *
sizeof(sion_int32));
1503 if (mapping == NULL) {
1505 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_ABORT,
"_sion_parclose_generic_mapped: Cannot allocate memory for mapping"));
1510 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1511 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1515 sion_tmpint32field_send = (sion_int32 *) malloc(tmpsize *
sizeof(sion_int32));
1516 if (sion_tmpint32field_send == NULL) {
1518 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic_mapped: cannot allocate temporary memory of size %lu (sion_tmpintfield_send), aborting ...\n",
1519 (
unsigned long) tmpsize *
sizeof(sion_int32)));
1524 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, mappingroot);
1526 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" file %d: allocate send field for all local tasks of file (%d) --> %x\n", filenr, tmpsize, sion_tmpint32field_send));
1528 if(rank==mappingroot) {
1531 sion_tmpint32field_data_recv = (sion_int32 *) malloc(tmpsize *
sizeof(sion_int32));
1532 if (sion_tmpint32field_data_recv == NULL) {
1533 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic_mapped: cannot allocate temporary memory of size %lu (sion_tmpintfield_data_recv), aborting ...\n",
1534 (
unsigned long) tmpsize *
sizeof(sion_int32)));
1536 }
else sion_tmpint32field_data_recv=NULL;
1540 sion_tmpint32field_send[ltask*2+0]= (int) sion_filedesc_sub->
all_localranks[ltask];
1541 sion_tmpint32field_send[ltask*2+1]= (
int) sion_filedesc_sub->
all_globalranks[ltask];
1542 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"local lrank[%d]=%d grank[%d]=%d\n",ltask,(
int) sion_filedesc_sub->
all_localranks[ltask],ltask,(
int) sion_filedesc_sub->
all_globalranks[ltask]));
1546 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
" sion_tmpint32field_send: %d -> %d \n",ltask, sion_tmpint32field_send[ltask]));
1549 if (rank == mappingroot)
for(task=0;task<ntasks;task++) sion_count[task]*=2;
1550 sion_gendata->apidesc->gathervr_cb(sion_tmpint32field_send, sion_tmpint32field_data_recv, sion_gendata->comm_data_global, _SION_INT32, sion_count, 2*sion_filedesc_sub->
nlocaltasksinfile, mappingroot);
1551 if (rank == mappingroot)
for(task=0;task<ntasks;task++) sion_count[task]/=2;
1553 if(rank==mappingroot) {
1556 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
" sion_tmpint32field_send: %d -> %d \n",ltask, sion_tmpint32field_data_recv[ltask]));
1559 lrank=(int) sion_tmpint32field_data_recv[ltask*2+0];
1560 grank=(int) sion_tmpint32field_data_recv[ltask*2+1];
1561 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"store mapping[%d]=(%d,%d)\n",grank,filenr,lrank));
1562 mapping[grank*2+0]=filenr;
1563 mapping[grank*2+1]=lrank;
1567 if(sion_tmpint32field_data_recv) free(sion_tmpint32field_data_recv);
1568 if(sion_tmpint32field_send) free(sion_tmpint32field_send);
1572 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1573 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1579 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"mapping size is %d\n",sion_filedesc_master->
mapping_size));
1583 DPRINTFP((32,
"_sion_parclose_mapped_generic", rank,
" parallel close (write mode, managed) call fclose on file %s (fileptr=%x)\n", sion_filedesc_sub->
fname,sion_filedesc_sub->
fileptr));
1585 sion_filedesc_sub->
fileptr = NULL;
1594 _sion_free_filedesc(sion_filedesc_sub);
1596 if (sion_gendata->apidesc->free_lcg_cb && sion_gendata->comm_data_local) {
1597 sion_gendata->apidesc->free_lcg_cb(sion_gendata->comm_data_local);
1599 _SION_SAFE_FREE(mapping, NULL);
1600 _SION_SAFE_FREE(sion_count, NULL);
1601 _SION_SAFE_FREE(sion_filedesc_master->
multifiles, NULL);
1604 _sion_free_filedesc(sion_filedesc_master);
1605 sion_filedesc_master = NULL;
1609 DPRINTFP((2,
"_sion_parclose_mapped_generic", rank,
"leave parallel close sid=%d\n", sid));
int sion_get_keyval_mode(int sid)
Return selected mode for key value.
int sion_get_mapping(int sid, int *mapping_size, sion_int32 **mapping, int *numfiles)
Returns pointers to the internal field mapping.
int _sion_buffer_flush(_sion_filedesc *sion_filedesc)
Flush buffer.
int sion_get_sizeof(int sid, int *numbytes, int *numfds)
Function returns size of internal data structure for sid.
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.
_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
int _sion_alloc_filedesc_block_arrays(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion structure, fields for all chunksizes of all tasks.
#define SION_FILESTATE_PAROPENMAPPED
#define SION_FILEMODE_WRITE
#define SION_FILESTATE_PAROPENMAPPEDMANAGED
#define SION_FILEMODE_READ
#define SION_FILESTATE_CLOSE
#define SION_FILESTATE_PAROPENMAPPEDMASTER
int _sion_paropen_mapped_generic(int sid, char *fname, sion_int64 file_mode_flags, char *prefix, int *numFiles, int *nlocaltasks, int **globalranks, sion_int64 **chunksizes, int **mapping_filenrs, int **mapping_lranks, sion_int32 *fsblksize, int rank, int ntasks, int flag, FILE **fileptr, _sion_generic_gendata *sion_gendata)
Generic parallel open of one direct access file. Mapping sion files to environment with less tasks.
char * _sion_get_multi_filename(const char *fname, int filenumber)
generates the multi filename
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.
int _sion_open_read(const char *fname, sion_int64 file_mode_flags, int read_all, int *ntasks, int *nfiles, sion_int64 **chunksizes, sion_int32 *fsblksize, int **globalranks, FILE **fileptr)
internal sion serial open function for reading on one or more files
Sion File Descriptor Structure.
sion_int64 * all_localranks
sion_int64 * all_blocksizes
sion_int32 * all_coll_collsize
sion_int32 * all_coll_collector
sion_int32 filesionversion
sion_int32 nlocaltasksinfile
sion_int64 start_of_varheader
sion_int32 filesionpatchlevel
sion_int64 * all_chunksizes
sion_int64 * all_currentpos
sion_int32 filemanagedbytask
sion_int64 * all_currentblocknr
sion_int32 fileptr_exported
_sion_filedesc ** multifiles
sion_int64 * all_globalranks
sion_int32 ntotaltasksinfile
sion_int32 currentblocknr
sion_int64 * all_startpointers
sion_int64 * all_blockcount