12 int dump_gen(
int readwrite,
long dump_cnt,
int bintxt,
int whichdump, MPI_Datatype datatype,
char *fileprefix,
char *fileformat,
char *filesuffix,
int (*headerfun) (
int whichdump,
int whichdumpversion,
int numcolumns,
int bintxt, FILE*headerptr),
int (*setgetcontent) (
int i,
int j,
int k, MPI_Datatype datatype,
void*setbuf))
14 int i = 0, j = 0, k = 0, l = 0, col = 0;
20 static void *writebuf;
31 long int uptodatabytesize;
34 int gopastlinebreak(FILE *stream);
43 mpiio_final(0, 0, NULL, 0, MPICOMBINEROMIO, NULL, -1, 0, NULL, &writebuf);
88 if(myid==0) isenoughfreespace((
unsigned long long)(
sizeof(
FTYPE))*(
unsigned long long)numcolumns*(
unsigned long long)(
totalsize[1])*(
unsigned long long)(
totalsize[2])*(
unsigned long long)(
totalsize[3]) );
89 else isenoughfreespace(0);
92 if(myid==0) isenoughfreespace((
unsigned long long)(22)*(
unsigned long long)numcolumns*(
unsigned long long)(
totalsize[1])*(
unsigned long long)(
totalsize[2])*(
unsigned long long)(
totalsize[3]) );
93 else isenoughfreespace(0);
98 isenoughfreespace((
unsigned long long)(
sizeof(
FTYPE))*(
unsigned long long)numcolumns*(
unsigned long long)(
N1)*(
unsigned long long)(
N2)*(
unsigned long long)(
N3) );
101 isenoughfreespace((
unsigned long long)(21)*(
unsigned long long)numcolumns*(
unsigned long long)(
N1)*(
unsigned long long)(
N2)*(
unsigned long long)(
N3) );
112 sizeofdatatype=getsizeofdatatype(datatype);
113 setbuf=malloc(numcolumns*sizeofdatatype);
115 dualfprintf(
fail_file,
"cannot allocate memory to setbuf in %s %s with numcolumns=%d and sizeofdatatype=%d\n",fileprefix,filesuffix,numcolumns,sizeofdatatype);
133 else romiocloopend=1;
148 if(fileprefix[0]==
'i') binextension=0;
156 else strcpy(truemyidtxt,
".bin");
160 else strcpy(truemyidtxt,
"");
165 strcpy(localfileformat,
"%s");
166 strcat(localfileformat,fileformat);
167 strcat(localfileformat,
"%s");
168 strcat(localfileformat,
"%s");
169 sprintf(dfnam, localfileformat, fileprefix, dump_cnt, filesuffix, truemyidtxt);
172 sprintf(dfnam,
"%s%s%s", fileprefix, filesuffix, truemyidtxt);
184 int problemloadingfile=0;
189 if((fpp=(FILE**)malloc(
sizeof(FILE*)*numfiles))==NULL){
190 dualfprintf(
fail_file,
"couldn't open fpp in dump()\n");
198 sprintf(dfnamreal,
"%s-col%04d",dfnam,coliter);
200 else strcpy(dfnamreal,dfnam);
202 if ((fpp[coliter] = fopen(dfnamreal, filerw)) == NULL) {
203 dualfprintf(
fail_file,
"error opening %s %s (fullname=%s) file\n",fileprefix,filesuffix,dfnamreal);
204 dualfprintf(
fail_file,
"Check if disk full or have correct permissions\n");
205 problemloadingfile=1;
213 MPI_Bcast(&problemloadingfile,1,MPI_INT,MPIid[0], MPI_COMM_GRMHD);
215 if(problemloadingfile){
233 headerfun(whichdump,whichdumpversion,numcolumns,headerbintxt,fpp[coliter]);
243 checkstatus=check_fileformat(readwrite, bintxt, whichdump, numcolumns,
docolsplit,
mpicombine, sizeofdatatype, fpp[coliter]);
251 if(gopastlinebreak(fpp[coliter])) checkstatus=1;
256 uptodatabytesize=ftell(fpp[coliter]);
270 #if(USEMPI&&USEROMIO)
271 MPI_Bcast(&uptodatabytesize,1,MPI_LONG,MPIid[0], MPI_COMM_GRMHD);
296 if(romiocloopend>1) trifprintf(
"romiocoliter=%d of romiocloopend=%d\n",
romiocoliter,romiocloopend);
304 else mpiio_init(dumpbintxt,
sortedoutput, fpp, uptodatabytesize, readwrite, dfnam, numcolumns, datatype, &jonio, &writebuf);
345 if((
mpicombine)&&(
truempicombinetype==MPICOMBINEMINMEM)) mpiio_minmem(
READFILE,whichdump,i,j,k,dumpbintxt,
sortedoutput,numcolumns,datatype, fpp,jonio,writebuf);
349 myfread(dumpbintxt,datatype,setbuf,0,numcolumns,i,j,k,fpp,writebuf);
353 dualfprintf(
fail_file,
"Number of columns (numcolumns=%d) isn't equal to number of columns/buffers attempted (nextbuf=%lld)\n",numcolumns,
nextbuf);
358 setgetcontent(i,j,k,datatype,setbuf);
362 dualfprintf(
fail_file,
"Number of columns (numcolumns=%d) isn't equal to number of columns attempted (nextcol=%d)\n",numcolumns,
nextcol);
384 setgetcontent(i,j,k,datatype,setbuf);
388 dualfprintf(
fail_file,
"Number of columns (numcolumns=%d) isn't equal to number of columns attempted (nextcol=%d)\n",numcolumns,
nextcol);
393 myfwrite(dumpbintxt,datatype,setbuf,0,numcolumns,i,j,k,fpp,writebuf);
398 dualfprintf(
fail_file,
"Number of columns (numcolumns=%d) isn't equal to number of columns/buffers attempted (nextbuf=%d)\n",numcolumns,
nextbuf);
405 if((
mpicombine)&&(
truempicombinetype==MPICOMBINEMINMEM)) mpiio_minmem(
WRITEFILE,whichdump,i,j,k,dumpbintxt,
sortedoutput,numcolumns,datatype, fpp, jonio,writebuf);
423 COLLOOP(coliter) if (fpp[coliter] != NULL) fclose(fpp[coliter]);
427 if(readwrite==WRITEFILE) mpiio_combine(dumpbintxt, sortedoutput, numcolumns, datatype, fpp, jonio, writebuf);
437 if(setbuf!=NULL) free(setbuf);
480 int header1_gen(
int accessmemory,
int readwrite,
int bintxt,
int bcasthead,
void *ptr,
size_t size,
char *format,
size_t nmemb, MPI_Datatype datatype, FILE *stream)
490 long long int *ptr8i;
502 char largedumbspace[200];
520 if (datatype == MPI_UNSIGNED_CHAR) ptrlocal = (
unsigned char *) &var1;
521 else if (datatype == MPI_FLOAT) ptrlocal = (
float *) &var4;
522 else if (datatype == MPI_DOUBLE) ptrlocal = (
double *) &var8;
523 else if (datatype == MPI_LONG_DOUBLE) ptrlocal = (
long double *) &var16;
524 else if (datatype == MPI_INT) ptrlocal = (
int *) &var4i;
525 else if (datatype == MPI_LONG) ptrlocal = (
long *) &var4l;
526 else if (datatype == MPI_LONG_LONG_INT) ptrlocal = (
long long int *) &var8i;
528 dualfprintf(
fail_file,
"No such datatype=%d\n",datatype);
541 if (datatype == MPI_UNSIGNED_CHAR) ptr1 = (
unsigned char *) ptrlocal;
542 else if (datatype == MPI_FLOAT) ptr4 = (
float *) ptrlocal;
543 else if (datatype == MPI_DOUBLE) ptr8 = (
double *) ptrlocal;
544 else if (datatype == MPI_LONG_DOUBLE) ptr16 = (
long double *) ptrlocal;
545 else if (datatype == MPI_INT) ptr4i = (
int *) ptrlocal;
546 else if (datatype == MPI_LONG) ptr4l = (
long *) ptrlocal;
547 else if (datatype == MPI_LONG_LONG_INT) ptr8i = (
long long int *) ptrlocal;
549 dualfprintf(
fail_file,
"No such datatype=%d\n",datatype);
559 if(accessmemory) fread(ptrlocal,size,nmemb,stream);
561 for(ii=0;ii<nmemb;ii++){
562 fread(ptrlocal,size,1,stream);
568 for(ii=0;ii<nmemb;ii++){
570 if(accessmemory) jj=ii;
573 if (datatype == MPI_UNSIGNED_CHAR) fscanf(stream,format,&ptr1[jj]);
574 else if (datatype == MPI_FLOAT) fscanf(stream,format,&ptr4[jj]);
575 else if (datatype == MPI_DOUBLE) fscanf(stream,format,&ptr8[jj]);
576 else if (datatype == MPI_LONG_DOUBLE) fscanf(stream,format,&ptr16[jj]);
577 else if (datatype == MPI_INT) fscanf(stream,format,&ptr4i[jj]);
578 else if (datatype == MPI_LONG) fscanf(stream,format,&ptr4l[jj]);
579 else if (datatype == MPI_LONG_LONG_INT) fscanf(stream,format,&ptr8i[jj]);
581 dualfprintf(
fail_file,
"No such datatype=%d\n",datatype);
587 dualfprintf(
fail_file,
"No such bintxt=%d in readwrite=%d\n",bintxt,readwrite);
595 if(accessmemory) fwrite(ptrlocal,size,nmemb,stream);
597 for(ii=0;ii<nmemb;ii++){
598 fwrite(ptrlocal,size,1,stream);
603 sprintf(formatwithspace,
"%s ",format);
605 for(ii=0;ii<nmemb;ii++){
607 if(accessmemory) jj=ii;
610 if (datatype == MPI_UNSIGNED_CHAR) fprintf(stream,formatwithspace,ptr1[jj]);
611 else if (datatype == MPI_FLOAT) fprintf(stream,formatwithspace,ptr4[jj]);
612 else if (datatype == MPI_DOUBLE) fprintf(stream,formatwithspace,ptr8[jj]);
613 else if (datatype == MPI_LONG_DOUBLE) fprintf(stream,formatwithspace,ptr16[jj]);
614 else if (datatype == MPI_INT) fprintf(stream,formatwithspace,ptr4i[jj]);
615 else if (datatype == MPI_LONG) fprintf(stream,formatwithspace,ptr4l[jj]);
616 else if (datatype == MPI_LONG_LONG_INT) fprintf(stream,formatwithspace,ptr8i[jj]);
618 dualfprintf(
fail_file,
"No such datatype=%d\n",datatype);
624 dualfprintf(
fail_file,
"No such bintxt=%d in readwrite=%d\n",bintxt,readwrite);
631 dualfprintf(
fail_file,
"Entered header1_gen() with nothing do to\n");
636 dualfprintf(
fail_file,
"Entered header1_gen() with nothing do to version2\n");
645 if(bcasthead && accessmemory){
649 MPI_Bcast(ptr, (
int)nmemb, datatype, MPIid[0], MPI_COMM_GRMHD);
667 int check_fileformat(
int readwrite,
int bintxt,
int whichdump,
int numcolumnsvar,
int docolsplitvar,
int mpicombinevar,
int sizeofdatatype, FILE *stream)
669 long onlyheaderbytesize;
670 long uptodatabytesize;
671 long withintransitionbytesize;
675 long long int datawordnumber;
676 long long int totaldatasize;
677 long long int wordtotal;
678 long long int badwordtotal;
679 long long int databytesize;
680 long long int fullheaderbytesize;
681 int get_word_count(
long long int databytesize,
long long int *wordtotal, FILE *stream);
682 unsigned char mychar;
683 int gopastlinebreak(FILE *stream);
687 onlyheaderbytesize=ftell(stream);
693 gopastlinebreak(stream);
698 uptodatabytesize=ftell(stream);
703 fseek(stream,0,SEEK_SET);
704 gopastlinebreak(stream);
707 fullheaderbytesize=ftell(stream);
711 if(fullheaderbytesize!=uptodatabytesize){
712 dualfprintf(
fail_file,
"restart read found \\n mismatch: fullheaderbytesize=%lld uptodatabytesize=%lld\n",fullheaderbytesize,uptodatabytesize);
719 fseek(stream,uptodatabytesize,SEEK_SET);
722 withintransitionbytesize = uptodatabytesize - onlyheaderbytesize;
729 fseek(stream,0,SEEK_END);
731 totalbytesize=ftell(stream);
735 databytesize = totalbytesize-uptodatabytesize;
739 if(docolsplitvar) truenumcolumns=1;
740 else truenumcolumns=numcolumnsvar;
744 else datawordnumber=
N1*
N2*
N3*truenumcolumns;
747 totaldatasize=datawordnumber*sizeofdatatype;
766 fseek(stream,onlyheaderbytesize,SEEK_SET);
769 get_word_count(withintransitionbytesize, &badwordtotal, stream);
772 dualfprintf(
fail_file,
"restart read found extra words (badwordtotal=%lld) in header or could be that reading of header passed into data section\n",badwordtotal);
792 if(databytesize != totaldatasize){
793 dualfprintf(
fail_file,
"restart read binary header/data found databytesize=%d and totaldatasize=%d\n",databytesize,totaldatasize);
811 fseek(stream,uptodatabytesize,SEEK_SET);
814 get_word_count(databytesize, &wordtotal, stream);
817 if(wordtotal!=datawordnumber){
818 dualfprintf(
fail_file,
"restart read text data found wordtotal=%lld while datawordnumber=%lld\n",wordtotal,datawordnumber);
819 dualfprintf(
fail_file,
"onlyheaderbytesize=%lld ,totalbytesize=%lld,databytesize=%lld,truenumcolumns=%lld,datawordnumber=%lld,totaldatasize=%lld\n",onlyheaderbytesize,totalbytesize,databytesize,truenumcolumns,datawordnumber,totaldatasize);
832 fseek(stream,onlyheaderbytesize,SEEK_SET);
842 int gopastlinebreak(FILE *stream)
848 mychar=fgetc(stream);
849 if(mychar==
'\n' || mychar==
'\r')
break;
851 dualfprintf(
fail_file,
"Reached end of file while seeking \\n or \\r in header\n");
860 int get_word_count(
long long int databytesize,
long long int *wordtotal, FILE *stream)
862 unsigned char mychar;
863 int wordchar,spacechar;
875 for(i=0;i<databytesize;i++){
877 mychar=(
unsigned char)fgetc(stream);
881 dualfprintf(
fail_file,
"Something is wrong with databytesize or loop since databytesize=%lld but found EOF\n",databytesize);
886 if(mychar==
'\n' || mychar==
'\r' || mychar==
' ' || mychar==
'\t' || mychar==
'\v'){
898 if(i==0 && wordchar==1 && thischarisword){
904 if(wordchar==1 && spacechar>0 && thischarisword){