22 #include "sion_error_handler.h" 38 #define _SION_CONST_MAX_INT32 2147483647 66 sion_int64 file_mode_flags,
71 sion_int64 **chunksizes,
72 int **mapping_filenrs,
74 sion_int32 *fsblksize,
81 int filenr, root, task;
85 sion_int64 helpint64, apiflag, new_fsblocksize, lstartpointer;
87 sion_int32 *sion_count = NULL;
89 sion_int64 *sion_tmpintfield2 = NULL;
90 sion_int64 *sion_tmpintfield3 = NULL;
93 int *lfilecounter,*lfilemanager, ltask, tmpsize, blknum;
98 DPRINTFP((2,
"_sion_paropen_mapped_generic", rank,
"enter parallel open sid=%d\n", sid));
101 if (sion_filedesc_master == NULL) {
102 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",
103 (
unsigned long)
sizeof(sion_filedesc_master)));
107 sion_filedesc_master->
fname = strdup(fname);
111 if (file_mode_flags&_SION_FMODE_WRITE) {
114 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" starting open for write #tasks=%d\n", ntasks));
117 for(ltask=0;ltask<*nlocaltasks;ltask++) {
118 DPRINTFP((128,
"_sion_paropen_mapped_generic", rank,
"input: %2d: f=%d gtask=%2d ltask=%d --> %d\n", ltask,
119 (
int) (*mapping_filenrs)[ltask],
120 (
int) (*globalranks)[ltask],
121 (
int) (*mapping_lranks)[ltask],
122 (
int) (*chunksizes)[ltask]
130 sion_filedesc_master->
sid=sid;
131 sion_filedesc_master->
nfiles=*numFiles;
134 if (sion_filedesc_master->
multifiles == NULL) {
135 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure vector of size %lu (chunksizes), aborting ...\n",
145 lfilecounter = (
int *) malloc(*numFiles *
sizeof(
int));
146 if (lfilecounter == NULL) {
147 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (lfilecounter), aborting ...\n",
148 (
unsigned long) *numFiles *
sizeof(int)));
150 lfilemanager = (
int *) malloc(*numFiles *
sizeof(
int));
151 if (lfilemanager == NULL) {
153 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (lfilemanager), aborting ...\n",
154 (
unsigned long) *numFiles *
sizeof(
int)));
157 sion_count = (sion_int32 *) malloc(ntasks *
sizeof(sion_int32));
158 if (sion_count == NULL) {
161 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",
162 (
unsigned long) ntasks *
sizeof(sion_int32)));
167 for(filenr=0;filenr<*numFiles;filenr++) lfilecounter[filenr]=lfilemanager[filenr]=0;
168 for(ltask=0;ltask<*nlocaltasks;ltask++) {
169 filenr=(*mapping_filenrs)[ltask];
170 if((filenr<0) || (filenr>=*numFiles)){
174 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",
177 lfilecounter[filenr]++;
178 if((*mapping_lranks)[ltask]==0) {
179 lfilemanager[filenr]=1;
186 _sion_keyval_check_env(sion_filedesc_master, file_mode_flags);
189 for(filenr=0;filenr<*numFiles;filenr++) {
191 DPRINTFP((4,
"_sion_paropen_mapped_generic", rank,
" starting init of SION #%d of %d (%d local tasks) \n", filenr,*numFiles,lfilecounter[filenr]));
195 helpint32 = lfilemanager[filenr];
196 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
198 for(task=0;task<ntasks;task++) {
199 if(sion_count[task]==1) root=task;
203 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64,1 , 0); root=helpint64;
205 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",
209 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" file #%d will be managed by task %d \n", filenr,root));
213 if (sion_filedesc_sub == NULL) {
214 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",
215 (
unsigned long)
sizeof(sion_filedesc_sub)));
217 sion_filedesc_master->
multifiles[filenr]=sion_filedesc_sub;
221 sion_filedesc_sub->
fname = (sion_gendata->apidesc->get_multi_filename_cb?sion_gendata->apidesc->get_multi_filename_cb:
_sion_get_multi_filename)(fname, filenr);
230 sion_filedesc_sub->
fsblksize = *fsblksize;
232 sion_filedesc_sub->
nfiles = *numFiles;
234 sion_filedesc_sub->
prefix = strdup(prefix);
235 sion_filedesc_sub->
compress = file_mode_flags&_SION_FMODE_COMPRESS;
236 sion_filedesc_sub->
usecoll = file_mode_flags&_SION_FMODE_COLLECTIVE;
240 _sion_keyval_check_env(sion_filedesc_sub, file_mode_flags);
253 helpint32 = lfilecounter[filenr];
255 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, root);
258 for(task=0;task<ntasks;task++) helpint64 += sion_count[task];
260 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64, 1, root);
263 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
"mapping size increased to %d\n",sion_filedesc_master->
mapping_size));
267 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" file #%d (%s) will store chunks from %d tasks (%d local) \n",
268 filenr,sion_filedesc_sub->
fname,
273 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" create file #%d (%s) \n", filenr,sion_filedesc_sub->
fname));
276 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_generic: cannot open %s for writing, aborting ...\n", fname));
281 if((new_fsblocksize<0) || (new_fsblocksize>SION_MAX_FSBLOCKSIZE)) new_fsblocksize=SION_DEFAULT_FSBLOCKSIZE;
282 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" found new_fsblksize of %d\n", (
int) new_fsblocksize));
289 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
291 sion_gendata->apidesc->bcastr_cb(&new_fsblocksize, sion_gendata->comm_data_global, _SION_INT64, 1, root);
292 sion_filedesc_sub->
fsblksize = new_fsblocksize;
293 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" setting fsblksize to %d\n", (
int) new_fsblocksize));
300 sion_tmpintfield2 = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
301 if (sion_tmpintfield2 == NULL) {
302 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",
303 (
unsigned long) tmpsize *
sizeof(sion_int64)));
307 sion_tmpintfield3 = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
308 if (sion_tmpintfield3 == NULL) {
309 free(sion_tmpintfield2);
310 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",
311 (
unsigned long) tmpsize *
sizeof(sion_int64)));
313 }
else sion_tmpintfield3 = NULL;
317 for(ltask=0;ltask<*nlocaltasks;ltask++) {
318 lfilenr=(int) (*mapping_filenrs)[ltask];
319 if(lfilenr==filenr) {
320 sion_tmpintfield2[p*3+0]=(sion_int64) (*mapping_lranks)[ltask];
321 sion_tmpintfield2[p*3+1]=(sion_int64) (*globalranks)[ltask];
322 sion_tmpintfield2[p*3+2]=(sion_int64) (*chunksizes)[ltask];
323 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]));
332 if (rank == root)
for(task=0;task<ntasks;task++) sion_count[task]*=3;
333 sion_gendata->apidesc->gathervr_cb(sion_tmpintfield2, sion_tmpintfield3, sion_gendata->comm_data_global, _SION_INT64,sion_count,3*sion_filedesc_sub->
nlocaltasksinfile, root);
334 if (rank == root)
for(task=0;task<ntasks;task++) sion_count[task]/=3;
351 lrank=(int) sion_tmpintfield3[ltask*3+0];
352 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" sort in ltask=%d --> lrank=%d\n", ltask,lrank));
353 sion_filedesc_sub->
all_globalranks[lrank]=sion_tmpintfield3[ltask*3+1];
354 sion_filedesc_sub->
all_chunksizes[lrank] =sion_tmpintfield3[ltask*3+2];
358 _sion_calculate_startpointers(sion_filedesc_sub);
363 DPRINTFTS(rank,
"before open");
366 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_generic: cannot open %s for reading, aborting ...\n", fname));
368 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
369 DPRINTFTS(rank,
"after open");
372 sion_filedesc_sub->
fileptr = sion_fileptr;
374 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" store for file %s fileprt=%x\n",sion_filedesc_sub->
fname, sion_fileptr ));
379 DPRINTFTS(rank,
"before writeh");
382 DPRINTFTS(rank,
"after writeh");
391 DPRINTFTS(rank,
"before setp(0)");
394 DPRINTFTS(rank,
"after setp(0)");
397 _sion_free_filedesc_all_globalranks(sion_filedesc_sub);
401 _sion_alloc_filedesc_all_globalranks(sion_filedesc_sub);
402 _sion_alloc_filedesc_all_localranks(sion_filedesc_sub);
410 _sion_alloc_filedesc_all_localranks(sion_filedesc_sub);
415 _sion_alloc_filedesc_all_keyvalptr(sion_filedesc_sub);
420 sion_filedesc_sub->
all_localranks[ltask] = sion_tmpintfield2[ltask*3+0];
421 sion_filedesc_sub->
all_globalranks[ltask] = sion_tmpintfield2[ltask*3+1];
429 lrank=(int) sion_tmpintfield3[ltask*3+0];
431 sion_tmpintfield3[ltask*3+2]=sion_filedesc_sub->
all_chunksizes[lrank];
432 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" sort out ltask=%d --> lrank=%d startptr=%ld chunksize=%ld\n",
433 ltask,lrank,(
long) sion_tmpintfield3[ltask*3+1],sion_tmpintfield3[ltask*3+2]));
436 if (rank == root)
for(task=0;task<ntasks;task++) sion_count[task]*=3;
437 sion_gendata->apidesc->scattervr_cb(sion_tmpintfield2, sion_tmpintfield3, sion_gendata->comm_data_global, _SION_INT64,sion_count,3*sion_filedesc_sub->
nlocaltasksinfile, root);
438 if (rank == root)
for(task=0;task<ntasks;task++) sion_count[task]/=3;
442 _sion_free_filedesc_all_startpointers(sion_filedesc_sub);
443 _sion_free_filedesc_all_chunksizes(sion_filedesc_sub);
445 _sion_alloc_filedesc_all_startpointers(sion_filedesc_sub);
446 _sion_alloc_filedesc_all_chunksizes(sion_filedesc_sub);
451 sion_filedesc_sub->
all_chunksizes[ltask] = sion_tmpintfield2[ltask*3+2];
452 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" get startpointer[%d] --> %ld\n", ltask, sion_filedesc_sub->
all_startpointers[ltask]));
456 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
globalskip, sion_gendata->comm_data_global, _SION_INT64, 1, root);
460 DPRINTFTS(rank,
"before setp");
461 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
464 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" allocating block arrays of size %d\n", sion_filedesc_sub->
ntasks));
469 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" set all_currentpos[%d]=%d\n",ltask,sion_filedesc_sub->
all_currentpos[ltask] ));
475 sion_filedesc_sub->
rank = 0;
486 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
488 if(sion_tmpintfield2) free(sion_tmpintfield2);
489 if(sion_tmpintfield3) free(sion_tmpintfield3);
491 DPRINTFP((4,
"_sion_paropen_mapped_generic", rank,
" ending init of SION #%d of %d \n", filenr,*numFiles));
500 {
int lfile=-1, lrank=-1, blknum;
501 sion_filedesc_sub=NULL;
502 for(filenr=0;filenr<*numFiles;filenr++) {
503 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
513 if((sion_filedesc_sub) && (lrank>=0) && (lfile>=0)) {
518 sion_filedesc_master->
rank = lrank;
535 for (blknum = 0; blknum < sion_filedesc_sub->
all_blockcount[lrank]; blknum++) {
545 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"set startpointer to %d\n",(
int) sion_filedesc_master->
currentpos));
550 *fileptr=sion_filedesc_master->
fileptr->fileptr;
562 if(sion_count) free(sion_count);
564 if(lfilecounter) free(lfilecounter);
565 if(lfilemanager) free(lfilemanager);
569 }
else if (file_mode_flags&_SION_FMODE_READ) {
572 int mapping_size,mapsid=-1, rootcounter;
574 sion_int32 lfsblksize;
578 DPRINTFP((1,
"_sion_paropen_mapped_generic", rank,
"read mode ntasks=%d\n",ntasks));
580 for(ltask=0;ltask<*nlocaltasks;ltask++) {
581 DPRINTFP((128,
"_sion_paropen_mapped_generic", rank,
"input: %2d: gtask=%2d \n", ltask, (
int) (*globalranks)[ltask]));
587 sion_filedesc_master->
sid=sid;
590 sion_count = (sion_int32 *) malloc(ntasks *
sizeof(sion_int32));
591 if (sion_count == NULL) {
592 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",
593 (
unsigned long) ntasks *
sizeof(sion_int32)));
601 DPRINTFP((1,
"_sion_paropen_mapped_generic", rank,
"before open\n"));
602 mapsid=
_sion_open_read(fname,_SION_FMODE_READ|_SION_FMODE_ANSI,_SION_READ_MASTER_ONLY_OF_MULTI_FILES,
603 &lntasks,&lnfiles,NULL,&lfsblksize,NULL,&lfileptr);
605 DPRINTFP((1,
"_sion_paropen_mapped_generic", rank,
"after open\n"));
607 DPRINTFP((1,
"_sion_paropen_mapped_generic", rank,
"sion file %d files #tasks=%d rc=%d\n", *numFiles,mapping_size,rc));
610 lfilemanager = (
int *) malloc(*numFiles *
sizeof(
int));
611 if (lfilemanager == NULL) {
612 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot allocate temporary memory of size %lu (lfilemanager), aborting ...\n",
613 (
unsigned long) *numFiles *
sizeof(
int)));
620 for(task=0;task<mapping_size;task++) {
621 if(mapping[task*2+1]==0) {
622 lfilemanager[mapping[task*2+0]]=task;
623 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" manager of file %d is grank=%d\n",mapping[task*2+0],task));
637 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot find file %s , aborting ...\n",fname));
642 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_master->
mapping_size, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
643 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" mapping_size is=%d\n",sion_filedesc_master->
mapping_size));
647 if (mapsid>=0) _sion_close_sid(mapsid);
654 int tasks_per_task = sion_filedesc_master->
mapping_size / ntasks;
655 int startpos = rank*tasks_per_task;
656 int endpos = (rank+1)*tasks_per_task;
659 if(endpos<sion_filedesc_master->mapping_size) endpos=sion_filedesc_master->
mapping_size;
661 *nlocaltasks=endpos-startpos;
662 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"pre-compute distribution: startpos=%d endpos=%d nlocaltasks=%d\n",startpos, endpos, (
int) *nlocaltasks ));
664 if (globalranks == NULL) {
666 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate globalranks, not pointer parameter given, aborting ...\n"));
668 if (mapping_filenrs == NULL) {
670 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate mapping_filenrs, not pointer parameter given, aborting ...\n"));
672 if (mapping_lranks == NULL) {
674 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate mapping_lranks, not pointer parameter given, aborting ...\n"));
676 if ((*globalranks) != NULL) {
678 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"pre-compute distribution: cannot allocate globalranks, memory allready allocated (unknown size), 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, memory allready allocated (unknown size), 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, memory allready allocated (unknown size), aborting ...\n"));
690 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"allocate globalranks field for parameter size=%d\n",(
int) *nlocaltasks ));
691 *globalranks = (sion_int32 *) malloc(*nlocaltasks *
sizeof(sion_int32));
692 if (*globalranks == NULL) {
694 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate memory of size %lu (globalranks), aborting ...\n", (
unsigned long)
sizeof(sion_int32)));
698 for(task=startpos;task<endpos;task++) {
699 (*globalranks)[ltask]=task;
700 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"set *globalranks[%d]=%d\n",(
int) ltask,(*globalranks)[ltask]));
707 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_master->
keyvalmode, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
708 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" keyvalmode is=%d\n",sion_filedesc_master->
keyvalmode));
711 _sion_keyval_check_env(sion_filedesc_master, file_mode_flags);
714 if (rank == 0) helpint64=*numFiles;
715 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64, 1, 0); *numFiles=helpint64;
716 sion_filedesc_master->
nfiles=*numFiles;
720 if (sion_filedesc_master->
multifiles == NULL) {
721 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure vector of size %lu (chunksizes), aborting ...\n",
727 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
729 DPRINTFP((4,
"_sion_paropen_mapped_generic", rank,
" starting init of SION #%d of %d\n", filenr,*numFiles));
731 #ifdef _SION_FIND_ROOT_LRANK_NULL_DO_NOT_USE 738 helpint64=lfilemanager[filenr];
740 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64, 1, 0);
745 for(task=0;task<*nlocaltasks;task++) {
746 if((*globalranks)[task]==grankroot) helpint32=1;
750 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, 0);
752 for(task=0;task<ntasks;task++) {
753 if(sion_count[task]==1) {
764 rootcounter=( (rootcounter+1) % ntasks);
765 helpint64=rootcounter;
768 sion_gendata->apidesc->bcastr_cb(&helpint64, sion_gendata->comm_data_global, _SION_INT64, 1, 0);
770 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" manager of file %d is rank=%d\n",filenr,root));
774 if (sion_filedesc_sub == NULL) {
775 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",
776 (
unsigned long)
sizeof(sion_filedesc_sub)));
778 sion_filedesc_master->
multifiles[filenr]=sion_filedesc_sub;
780 sion_filedesc_sub->
fname = (sion_gendata->apidesc->get_multi_filename_cb?sion_gendata->apidesc->get_multi_filename_cb:
_sion_get_multi_filename)(fname, filenr);
789 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" starting open for read on file %s\n", sion_filedesc_sub->
fname));
790 DPRINTFTS(rank,
"before open");
791 sion_filedesc_sub->
fileptr=NULL;
795 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot open %s for reading, aborting ...\n", fname));
797 sion_filedesc_sub->
fileptr = sion_fileptr;
799 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
800 DPRINTFTS(rank,
"after open root");
805 if (rc!=SION_SUCCESS) {
806 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot read header from file %s, aborting ...\n", fname));
808 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
809 " 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));
811 DPRINTFTS(rank,
"before alloc");
814 DPRINTFTS(rank,
"after alloc");
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));
821 _sion_coll_check_env(sion_filedesc_sub);
825 if (!sion_filedesc_sub->
usecoll) _sion_calculate_startpointers(sion_filedesc_sub);
826 else _sion_calculate_startpointers_collective(sion_filedesc_sub);
827 DPRINTFTS(rank,
"after calculate");
830 _sion_keyval_check_env(sion_filedesc_sub, file_mode_flags);
835 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
globalskip, sion_gendata->comm_data_global, _SION_INT64, 1, root);
838 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
endianness, sion_gendata->comm_data_global, _SION_INT32, 1, root);
839 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
swapbytes, sion_gendata->comm_data_global, _SION_INT32, 1, root);
840 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
fsblksize, sion_gendata->comm_data_global, _SION_INT32, 1, root);
841 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
ntasks, sion_gendata->comm_data_global, _SION_INT32, 1, root);
844 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
fileversion, sion_gendata->comm_data_global, _SION_INT32, 1, root);
845 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
nfiles, sion_gendata->comm_data_global, _SION_INT32, 1, root);
846 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
filenumber, sion_gendata->comm_data_global, _SION_INT32, 1, root);
847 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
flag1, sion_gendata->comm_data_global, _SION_INT64, 1, root);
848 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
flag2, sion_gendata->comm_data_global, _SION_INT64, 1, root);
849 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
maxusedchunks, sion_gendata->comm_data_global, _SION_INT32, 1, root);
850 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
start_of_varheader, sion_gendata->comm_data_global, _SION_INT64, 1, root);
851 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
854 DPRINTFTS(rank,
"after bcast");
861 sion_tmpintfield2 = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
862 if (sion_tmpintfield2 == NULL) {
863 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",
864 (
unsigned long) tmpsize *
sizeof(sion_int64)));
869 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
874 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" scan for gtask=%d\n", (
int) sion_tmpintfield2[task]));
875 for(ltask=0;ltask<*nlocaltasks;ltask++) {
876 if( (
int) sion_tmpintfield2[task]==(*globalranks)[ltask]) {
877 sion_tmpintfield2[task]=-1 * (sion_tmpintfield2[task] + 1);
882 DPRINTFP((32,
"_sion_paropen_mapped_generic", rank,
" found %d globalranks for file %s\n", sion_filedesc_sub->
nlocaltasksinfile, sion_filedesc_sub->
fname));
884 DPRINTFTS(rank,
"before open non-root");
889 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_paropen_mapped_generic: cannot open %s for reading, aborting ...\n", fname));
891 sion_filedesc_sub->
fileptr = sion_fileptr;
894 DPRINTFTS(rank,
"after open non-root");
900 _sion_free_filedesc_all_globalranks(sion_filedesc_sub);
903 _sion_alloc_filedesc_all_globalranks(sion_filedesc_sub);
904 _sion_alloc_filedesc_all_localranks(sion_filedesc_sub);
909 _sion_alloc_filedesc_all_localranks(sion_filedesc_sub);
915 if(sion_tmpintfield2[task]<0) {
917 sion_filedesc_sub->
all_globalranks[ltask]= (-1 * sion_tmpintfield2[task]) - 1;
918 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" all_globalranks[%d]=%d all_localranks[%d]=%d\n",
928 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
930 _sion_free_filedesc_all_chunksizes(sion_filedesc_sub);
931 _sion_alloc_filedesc_all_chunksizes(sion_filedesc_sub);
943 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
945 _sion_free_filedesc_all_startpointers(sion_filedesc_sub);
946 _sion_alloc_filedesc_all_startpointers(sion_filedesc_sub);
963 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" got from file blockcount[%d]=%d\n",task,(
int) sion_tmpintfield2[task]));
965 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
970 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" store blockcount task=%d -> ltask=%d cnt=%d\n",task,ltask,(
int) sion_tmpintfield2[task]));
975 for (blknum = 0; blknum < sion_filedesc_sub->
maxusedchunks; blknum++) {
981 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
990 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
keyvalmode, sion_gendata->comm_data_global, _SION_INT32, 1, root);
993 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
usecoll, sion_gendata->comm_data_global, _SION_INT32, 1, root);
994 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
collsize, sion_gendata->comm_data_global, _SION_INT32, 1, root);
996 if(sion_filedesc_sub->
usecoll) {
1000 sion_tmpintfield2[task]= (sion_int64) (sion_filedesc_sub->
all_coll_collector[task]*_SION_CONST_MAX_INT32) + sion_filedesc_sub->
collsize;
1002 sion_gendata->apidesc->bcastr_cb(sion_tmpintfield2, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
ntotaltasksinfile, root);
1006 _sion_alloc_filedesc_all_chunksizes(sion_filedesc_sub);
1009 DPRINTFP((64,
"_sion_paropen_mapped_generic", rank,
" store collsize+collector for %d elements\n",sion_filedesc_sub->
nlocaltasksinfile));
1024 sion_filedesc_sub->
rank = 0;
1034 _sion_alloc_filedesc_all_keyvalptr(sion_filedesc_sub);
1041 if(sion_tmpintfield2) free(sion_tmpintfield2);
1049 int lfile=-1,lrank=-1, blknum;
1050 sion_filedesc_sub=NULL;
1051 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1052 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1060 DPRINTFP((32,
"sion_paropen_mapped_generic",rank,
"init to first local rank in first file (%d, %d)\n",lfile,lrank));
1062 if((sion_filedesc_sub) && (lrank>=0) && (lfile>=0)) {
1063 DPRINTFP((32,
"sion_paropen_mapped_generic",rank,
"sion_filedesc_master->mapping_size=%d\n",sion_filedesc_master->
mapping_size));
1072 sion_filedesc_master->
rank = lrank;
1090 for(filenr=0;filenr<sion_filedesc_sub->
nfiles;filenr++) {
1095 for (blknum = 0; blknum < sion_filedesc_sub->
all_blockcount[lrank]; blknum++) {
1106 DPRINTFP((32,
"sion_paropen_mapped_generic",rank,
"set startpointer to %d\n",(
int) sion_filedesc_master->
currentpos));
1115 *fileptr=sion_filedesc_master->
fileptr->fileptr;
1124 sion_int64 *helpptr_chunksize = NULL;
1125 sion_int32 *helpptr_mapping_filenrs = NULL;
1126 sion_int32 *helpptr_mapping_lranks = NULL;
1129 if (chunksizes != NULL) {
1130 if ((*chunksizes) == NULL) {
1131 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"allocate chunksizes field for parameter size=%d\n",(
int) *nlocaltasks ));
1132 helpptr_chunksize = (sion_int64 *) malloc(*nlocaltasks *
sizeof(sion_int64));
1133 if (helpptr_chunksize == NULL) {
1134 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)));
1136 *chunksizes = helpptr_chunksize;
1138 helpptr_chunksize = *chunksizes;
1142 if (mapping_filenrs != NULL) {
1143 if ((*mapping_filenrs) == NULL) {
1144 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"allocate mapping_filenrs field for parameter size=%d\n",(
int) *nlocaltasks ));
1145 helpptr_mapping_filenrs = (sion_int32 *) malloc(*nlocaltasks *
sizeof(sion_int32));
1146 if (helpptr_mapping_filenrs == NULL) {
1147 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)));
1149 *mapping_filenrs = helpptr_mapping_filenrs;
1151 helpptr_mapping_filenrs = *mapping_filenrs;
1155 if (mapping_lranks != NULL) {
1156 if ((*mapping_lranks) == NULL) {
1157 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
"allocate mapping_lranks field for parameter size=%d\n",(
int) *nlocaltasks ));
1158 helpptr_mapping_lranks = (sion_int32 *) malloc(*nlocaltasks *
sizeof(sion_int32));
1159 if (helpptr_mapping_lranks == NULL) {
1160 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)));
1162 *mapping_lranks = helpptr_mapping_lranks;
1164 helpptr_mapping_lranks = *mapping_lranks;
1169 if(helpptr_chunksize || helpptr_mapping_filenrs || helpptr_mapping_lranks) {
1170 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1171 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1173 for(task=0;task<*nlocaltasks;task++) {
1175 DPRINTFP((32,
"sion_paropen_mapped_generic:",rank,
" set chunksizes[%d]=%4d (filenr=%d, ltask=%d lrank=%d)\n",
1177 if(helpptr_chunksize) helpptr_chunksize[task] = sion_filedesc_sub->
all_chunksizes[ltask];
1178 if(helpptr_mapping_filenrs) helpptr_mapping_filenrs[task] = filenr;
1179 if(helpptr_mapping_lranks) helpptr_mapping_lranks[task] = sion_filedesc_sub->
all_localranks[ltask];
1188 _sion_print_filedesc(sion_filedesc_master, 512,
"_sion_paropen_mapped_generic", _SION_DEBUG_PRINT_ALL|_SION_DEBUG_PRINT_RECURSIVE);
1191 if(sion_count) free(sion_count);
1193 if(lfilemanager) free(lfilemanager);
1198 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"sion_paropen_multi_mpi: unknown file mode"));
1205 int _sion_parclose_mapped_generic(
int sid,
1209 int rc=SION_SUCCESS;
1210 int lfile, grank, lrank, blknum, filenr, tmpsize, root, ltask, mappingroot, task;
1213 sion_int64 *sion_tmpintfield_send = NULL;
1214 sion_int64 *sion_tmpintfield_lrank_recv = NULL;
1215 sion_int64 *sion_tmpintfield_data_recv = NULL;
1216 sion_int64 *sion_tmpintfield_data = NULL;
1217 sion_int32 *mapping = NULL;
1218 sion_int32 *sion_tmpint32field_send = NULL;
1219 sion_int32 *sion_tmpint32field_data_recv = NULL;
1220 sion_int32 *sion_count = NULL;
1221 sion_int32 helpint32;
1223 DPRINTFP((2,
"_sion_parclose_mapped_generic", rank,
"enter parallel close sid=%d\n", sid));
1226 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: invalid sion_filedesc_master, aborting %d ...\n", sid));
1231 int numbytes, numfds;
1233 DPRINTFP((2,
"_sion_parclose_mapped_generic", rank,
"internal data size of sid %2d (%d bytes, %d fds) \n", sid,numbytes, numfds));
1241 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));
1247 _sion_print_filedesc(sion_filedesc_master, 512,
"_sion_parclose_mapped_generic", _SION_DEBUG_PRINT_ALL|_SION_DEBUG_PRINT_RECURSIVE);
1255 lrank=sion_filedesc_master->
rank;
1256 if((lrank>=0) && (lfile>=0)) {
1257 sion_filedesc_sub=sion_filedesc_master->
multifiles[lfile];
1263 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1264 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1266 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));
1268 if(sion_filedesc_sub->
fileptr!=NULL) {
1270 sion_filedesc_sub->
fileptr = NULL;
1276 _sion_free_filedesc(sion_filedesc_sub);
1279 _SION_SAFE_FREE(mapping, NULL);
1280 _SION_SAFE_FREE(sion_filedesc_master->
multifiles, NULL);
1285 _sion_free_filedesc(sion_filedesc_master);
1286 sion_filedesc_master = NULL;
1298 _sion_print_filedesc(sion_filedesc_master, 512,
"_sion_parclose_mapped_generic", _SION_DEBUG_PRINT_ALL|_SION_DEBUG_PRINT_RECURSIVE);
1302 lrank=sion_filedesc_master->
rank;
1303 sion_filedesc_sub=sion_filedesc_master->
multifiles[lfile];
1315 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));
1321 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
"store current information lrank=%d lastchunknr=%d\n", lrank,sion_filedesc_sub->
lastchunknr));
1325 for (blknum = 0; blknum <= sion_filedesc_sub->
lastchunknr; blknum++) {
1330 sion_count = (sion_int32 *) malloc(ntasks *
sizeof(sion_int32));
1331 if (sion_count == NULL) {
1332 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",
1333 (
unsigned long) ntasks *
sizeof(sion_int32)));
1337 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1339 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1340 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" starting close for file %d: %s \n", filenr,sion_filedesc_sub->
fname));
1347 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));
1349 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));
1350 sion_filedesc_sub->
fileptr = NULL;
1355 sion_gendata->apidesc->barrier_cb(sion_gendata->comm_data_global);
1359 sion_tmpintfield_send = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
1360 if (sion_tmpintfield_send == NULL) {
1361 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield_send), aborting ...\n",
1362 (
unsigned long) tmpsize *
sizeof(sion_int64)));
1364 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));
1371 sion_tmpintfield_lrank_recv = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
1372 if (sion_tmpintfield_lrank_recv == NULL) {
1373 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",
1374 (
unsigned long) tmpsize *
sizeof(sion_int64)));
1376 sion_tmpintfield_data_recv = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
1377 if (sion_tmpintfield_data_recv == NULL) {
1378 free(sion_tmpintfield_lrank_recv);
1379 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",
1380 (
unsigned long) tmpsize *
sizeof(sion_int64)));
1382 sion_tmpintfield_data = (sion_int64 *) malloc(tmpsize *
sizeof(sion_int64));
1383 if (sion_tmpintfield_data == NULL) {
1384 free(sion_tmpintfield_data_recv);
1385 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_parclose_generic: cannot allocate temporary memory of size %lu (sion_tmpintfield_data), aborting ...\n",
1386 (
unsigned long) tmpsize *
sizeof(sion_int64)));
1388 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" file %d: allocate fields for all tasks of file (%d)\n", filenr,tmpsize));
1391 }
else sion_tmpintfield_lrank_recv=sion_tmpintfield_data_recv=sion_tmpintfield_data=NULL;
1395 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, root);
1399 sion_tmpintfield_send[ltask]=sion_filedesc_sub->
all_localranks[ltask];
1401 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" file %d: before call of gathervr_cb %x %x %x %d %d %d\n",
1402 filenr,sion_tmpintfield_lrank_recv, sion_tmpintfield_send, sion_gendata->comm_data_global, _SION_INT64, sion_filedesc_sub->
nlocaltasksinfile, root));
1404 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);
1408 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" send all_blockcount[%d]: %d\n", ltask, sion_filedesc_sub->
all_blockcount[ltask]));
1409 sion_tmpintfield_send[ltask]=sion_filedesc_sub->
all_blockcount[ltask];
1411 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);
1417 if (sion_tmpintfield_data_recv[ltask] > sion_filedesc_sub->
maxusedchunks) {
1418 sion_filedesc_sub->
maxusedchunks = (int) sion_tmpintfield_data_recv[ltask];
1423 sion_gendata->apidesc->bcastr_cb(&sion_filedesc_sub->
maxusedchunks, sion_gendata->comm_data_global, _SION_INT32, 1, root);
1424 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" file %d: maxusedchunks=%d\n", filenr,sion_filedesc_sub->
maxusedchunks));
1430 lrank=(int) sion_tmpintfield_lrank_recv[ltask];
1431 DPRINTFP((64,
"_sion_parclose_mapped_generic", rank,
" sort in ltask=%d --> lrank=%d blkcount=%d\n",
1432 ltask,lrank,sion_tmpintfield_data_recv[ltask]));
1433 sion_tmpintfield_data[lrank]=sion_tmpintfield_data_recv[ltask];
1448 for (blknum = 0; blknum < sion_filedesc_sub->
maxusedchunks; blknum++) {
1450 DPRINTFP((32,
"_sion_parclose_mapped_generic", rank,
" collect blocksize step %d of %d\n", blknum+1,sion_filedesc_sub->
maxusedchunks));
1453 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"sion_filedesc_sub->nlocaltasksinfile=%d\n",sion_filedesc_sub->
nlocaltasksinfile));
1456 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"sort in blksize[%d][%d]=%d\n",blknum, ltask, sion_tmpintfield_send[ltask]));
1458 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);
1465 lrank=(int) sion_tmpintfield_lrank_recv[ltask];
1466 sion_tmpintfield_data[lrank]=sion_tmpintfield_data_recv[ltask];
1467 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"prepare blksize[%d][%d]=%ld\n",blknum,lrank,sion_tmpintfield_data[lrank]));
1476 if(sion_tmpintfield_lrank_recv) free(sion_tmpintfield_lrank_recv);
1477 if(sion_tmpintfield_data_recv) free(sion_tmpintfield_data_recv);
1478 if(sion_tmpintfield_data) free(sion_tmpintfield_data);
1479 if(sion_tmpintfield_send) free(sion_tmpintfield_send);
1481 DPRINTFP((4,
"_sion_parclose_mapped_generic", rank,
" ending close for file %d: %s \n", filenr,sion_filedesc_sub->
fname));
1487 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"mappingroot=%d rank=%d\n", mappingroot, rank ));
1488 if(rank==mappingroot) {
1489 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"allocate mapping of size %d\n",sion_filedesc_master->
mapping_size));
1490 mapping = (sion_int32 *) malloc(sion_filedesc_master->
mapping_size * 2 *
sizeof(sion_int32));
1491 if (mapping == NULL) {
1493 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_ABORT,
"_sion_parclose_generic_mapped: Cannot allocate memory for mapping"));
1498 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1499 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1503 sion_tmpint32field_send = (sion_int32 *) malloc(tmpsize *
sizeof(sion_int32));
1504 if (sion_tmpint32field_send == NULL) {
1506 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",
1507 (
unsigned long) tmpsize *
sizeof(sion_int32)));
1512 sion_gendata->apidesc->gatherr_cb(&helpint32, sion_count, sion_gendata->comm_data_global, _SION_INT32, 1, mappingroot);
1514 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));
1516 if(rank==mappingroot) {
1519 sion_tmpint32field_data_recv = (sion_int32 *) malloc(tmpsize *
sizeof(sion_int32));
1520 if (sion_tmpint32field_data_recv == NULL) {
1521 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",
1522 (
unsigned long) tmpsize *
sizeof(sion_int32)));
1524 }
else sion_tmpint32field_data_recv=NULL;
1528 sion_tmpint32field_send[ltask*2+0]= (int) sion_filedesc_sub->
all_localranks[ltask];
1529 sion_tmpint32field_send[ltask*2+1]= (
int) sion_filedesc_sub->
all_globalranks[ltask];
1530 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]));
1534 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
" sion_tmpint32field_send: %d -> %d \n",ltask, sion_tmpint32field_send[ltask]));
1537 if (rank == mappingroot)
for(task=0;task<ntasks;task++) sion_count[task]*=2;
1538 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);
1539 if (rank == mappingroot)
for(task=0;task<ntasks;task++) sion_count[task]/=2;
1541 if(rank==mappingroot) {
1544 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
" sion_tmpint32field_send: %d -> %d \n",ltask, sion_tmpint32field_data_recv[ltask]));
1547 lrank=(int) sion_tmpint32field_data_recv[ltask*2+0];
1548 grank=(int) sion_tmpint32field_data_recv[ltask*2+1];
1549 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"store mapping[%d]=(%d,%d)\n",grank,filenr,lrank));
1550 mapping[grank*2+0]=filenr;
1551 mapping[grank*2+1]=lrank;
1555 if(sion_tmpint32field_data_recv) free(sion_tmpint32field_data_recv);
1556 if(sion_tmpint32field_send) free(sion_tmpint32field_send);
1560 for(filenr=0;filenr<sion_filedesc_master->
nfiles;filenr++) {
1561 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
1567 DPRINTFP((32,
"_sion_parclose_mapped_generic:",rank,
"mapping size is %d\n",sion_filedesc_master->
mapping_size));
1571 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));
1573 sion_filedesc_sub->
fileptr = NULL;
1582 _sion_free_filedesc(sion_filedesc_sub);
1584 if (sion_gendata->apidesc->free_lcg_cb && sion_gendata->comm_data_local) {
1585 sion_gendata->apidesc->free_lcg_cb(sion_gendata->comm_data_local);
1587 _SION_SAFE_FREE(mapping, NULL);
1588 _SION_SAFE_FREE(sion_count, NULL);
1589 _SION_SAFE_FREE(sion_filedesc_master->
multifiles, NULL);
1592 _sion_free_filedesc(sion_filedesc_master);
1593 sion_filedesc_master = NULL;
1597 DPRINTFP((2,
"_sion_parclose_mapped_generic", rank,
"leave parallel close sid=%d\n", sid));
long _sion_file_get_opt_blksize(_sion_fileptr *sion_fileptr)
Get optional file system block size for a file.
sion_int32 filemanagedbytask
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.
sion_int64 * all_blockcount
#define SION_FILE_FLAG_WRITE
int _sion_file_purge(_sion_fileptr *sion_fileptr)
Purge data to file.
sion_int64 * all_currentpos
sion_int32 filesionpatchlevel
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.
sion_int64 * all_globalranks
int _sion_alloc_filedesc_arrays(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion arrays.
sion_int64 * all_currentblocknr
#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_get_mapping(int sid, int *mapping_size, sion_int32 **mapping, int *numfiles)
Returns pointers to the internal field mapping.
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_PAROPENMAPPEDMANAGED
int sion_get_sizeof(int sid, int *numbytes, int *numfds)
Function returns size of internal data structure for sid.
int _sion_free_filedesc_coll_arrays(_sion_filedesc *sion_filedesc)
free memory for the internal sion arrays
#define SION_FILESTATE_PAROPENMAPPEDMASTER
sion_int32 currentblocknr
int _sion_alloc_filedesc_block_arrays(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion structure, fields for all chunksizes of all tasks.
int sion_get_keyval_mode(int sid)
Return selected mode for key value.
char * _sion_get_multi_filename(const char *fname, int filenumber)
generates the multi filename
#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
sion_int64 * all_localranks
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
sion_int32 filesionversion
sion_int32 * all_coll_collsize
sion_int64 start_of_varheader
sion_int64 * all_blocksizes
sion_int32 ntotaltasksinfile
sion_int32 nlocaltasksinfile
int _sion_file_flush(_sion_fileptr *sion_fileptr)
Flush data to file.
_sion_filedesc ** multifiles
#define SION_FILESTATE_PAROPENMAPPED
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