Changeset 20943


Ignore:
Timestamp:
07/19/16 13:36:05 (9 years ago)
Author:
Mathieu Morlighem
Message:

CHG: do not keep file pointer, reopen and append to outbin file

Location:
issm/trunk-jpl
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/jenkins/jenkins.sh

    r20942 r20943  
    9292                ISSM_COMPILATION="no"
    9393        fi
    94         ISSM_COMPILATION="yes"
    9594
    9695else
  • issm/trunk-jpl/src/c/classes/FemModel.cpp

    r20936 r20943  
    187187
    188188        /*Intermediary*/
    189         FILE *output_fid;
    190         char *outbinfilename = NULL;
    191189        char *lockfilename   = NULL;
    192190        bool  waitonlock     = false;
    193191
    194         /*Close output file: */
    195         this->parameters->FindParam(&output_fid,OutputFilePointerEnum);
    196         this->parameters->FindParam(&outbinfilename,OutputFileNameEnum);
    197         pfclose(output_fid,outbinfilename);
    198192
    199193        /*Write lock file if requested: */
     
    225219
    226220        /*Clean up*/
    227         xDelete<char>(outbinfilename);
    228221        xDelete<char>(lockfilename);
    229 
    230 }
    231 /*}}}*/
     222} /*}}}*/
    232223FemModel* FemModel::copy(void){/*{{{*/
    233224
     
    296287        FILE *IOMODEL            = NULL;
    297288        FILE *toolkitsoptionsfid = NULL;
    298         FILE *output_fid         = NULL;
    299289
    300290        /*recover my_rank:*/
     
    314304        pfclose(toolkitsoptionsfid,toolkitsfilename);
    315305
    316         /*Open output file once for all and add output file descriptor to parameters*/
    317         output_fid=pfopen(outputfilename,"wb");
    318         this->parameters->SetParam(output_fid,OutputFilePointerEnum);
    319        
    320306        /*Now save all of these file names into parameters, you never know when you might need them: */
    321307        this->parameters->AddObject(new StringParam(ToolkitsFileNameEnum,toolkitsfilename));
     
    441427
    442428        FILE* restartfid=NULL;
    443         FILE* output_fid=NULL;
    444429        char* restartfilename = NULL;
    445430        int   femmodel_size=0;
     
    471456        femmodel_buffer_ini=femmodel_buffer; //keep track of the initial position, so as to free later.
    472457
    473         this->parameters->FindParam(&output_fid,OutputFilePointerEnum);
    474 
    475458        /*Create new FemModel by demarshalling the buffer: */
    476459        this->Marshall(&femmodel_buffer,NULL,MARSHALLING_BACKWARD);
    477 
    478         this->parameters->SetParam(output_fid,OutputFilePointerEnum);
    479460
    480461        /*Reset position of buffer: */
     
    487468        xDelete<char>(restartfilename);
    488469        xDelete<char>(femmodel_buffer);
    489        
    490 }
    491 /*}}}*/
     470}/*}}}*/
    492471void FemModel::SetCurrentConfiguration(int configuration_type,int analysis_type){/*{{{*/
    493472
     
    24482427/*}}}*/
    24492428#endif
    2450 
    24512429void FemModel::HydrologyEPLupdateDomainx(IssmDouble* pEplcount){ /*{{{*/
    24522430
     
    25852563}
    25862564/*}}}*/
    2587 
    25882565#ifdef _HAVE_JAVASCRIPT_
    25892566FemModel::FemModel(IssmDouble* buffer, int buffersize, char* toolkits, char* solution, char* modelname,ISSM_MPI_Comm incomm, bool trace){ /*{{{*/
     
    26412618        poutputbuffersize=outputbuffersizeparam->GetParameterValue();
    26422619
    2643         /*Close output file. Watch out, only close the output file after recovering the buffer pointers. Not sure
    2644          * why, but otherwise, the buffers are garbage: */
    2645         this->parameters->FindParam(&output_fid,OutputFilePointerEnum);
    2646         fclose(output_fid);
    2647 
    26482620        /*Assign output values: */
    26492621        *poutput=*poutputbuffer;
     
    26602632        size_t      outputsize;
    26612633        char       *outputbuffer;
    2662         const char*       rootpath=""; //needed for Dakota runs only, which we won't do here.
     2634        const char *rootpath = "";  //needed for Dakota runs only, which we won't do here.
    26632635
    26642636        /*recover my_rank:*/
  • issm/trunk-jpl/src/c/classes/IoModel.cpp

    r20940 r20943  
    733733                                ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
    734734                                switch(record_code){
    735                                 case 1:
    736                                         /*boolean. get it from cpu 0 */
    737                                         ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    738 
    739                                         /*create BoolParam: */
    740                                         this->AddConstant(new IoConstant((bool)booleanint,record_name)); //cast to a boolean
    741                                         break;
    742 
    743                                 case 2:
    744                                         /*integer. get it from cpu 0 */
    745                                         ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    746 
    747                                         /*create IntParam: */
    748                                         this->AddConstant(new IoConstant(integer,record_name));
    749                                         break;
    750                                 case 3:
    751                                         /*scalar. get it from cpu 0 */
    752                                           {
    753                                                 /*IssmDouble, check whether it is already there (from "declare independents")*/
    754                                                 bool exists = false;
    755                                                 vector<IoConstant*>::iterator iter;
    756                                                 for(iter=constants.begin();iter<constants.end();iter++){
    757                                                         IoConstant* ioconstant=*iter;
    758                                                         if(strcmp(ioconstant->name,record_name)==0){
    759                                                                 exists = true;
    760                                                                 break;
     735                                        case 1:
     736                                                /*boolean. get it from cpu 0 */
     737                                                ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     738
     739                                                /*create BoolParam: */
     740                                                this->AddConstant(new IoConstant((bool)booleanint,record_name)); //cast to a boolean
     741                                                break;
     742
     743                                        case 2:
     744                                                /*integer. get it from cpu 0 */
     745                                                ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     746
     747                                                /*create IntParam: */
     748                                                this->AddConstant(new IoConstant(integer,record_name));
     749                                                break;
     750                                        case 3:
     751                                                /*scalar. get it from cpu 0 */
     752                                                  {
     753                                                        /*IssmDouble, check whether it is already there (from "declare independents")*/
     754                                                        bool exists = false;
     755                                                        vector<IoConstant*>::iterator iter;
     756                                                        for(iter=constants.begin();iter<constants.end();iter++){
     757                                                                IoConstant* ioconstant=*iter;
     758                                                                if(strcmp(ioconstant->name,record_name)==0){
     759                                                                        exists = true;
     760                                                                        break;
     761                                                                }
    761762                                                        }
     763                                                        if(!exists){
     764                                                                ISSM_MPI_Bcast(&pscalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
     765                                                                scalar=pscalar;
     766                                                                /*create DoubleParam: */
     767                                                                this->AddConstant(new IoConstant(scalar,record_name));
     768                                                        }
     769                                                  }
     770                                                break;
     771                                        case 4:
     772                                                ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     773                                                if(string_size){
     774                                                        string=xNew<char>((string_size+1));
     775                                                        string[string_size]='\0';
     776
     777                                                        /*Read string from cpu 0: */
     778                                                        ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
    762779                                                }
    763                                                 if(!exists){
    764                                                         ISSM_MPI_Bcast(&pscalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
    765                                                         scalar=pscalar;
    766                                                         /*create DoubleParam: */
    767                                                         this->AddConstant(new IoConstant(scalar,record_name));
     780                                                else{
     781                                                        string=xNew<char>(1);
     782                                                        string[0]='\0';
    768783                                                }
    769                                           }
    770                                         break;
    771                                 case 4:
    772                                         ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    773                                         if(string_size){
    774                                                 string=xNew<char>((string_size+1));
    775                                                 string[string_size]='\0';
    776 
    777                                                 /*Read string from cpu 0: */
    778                                                 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
    779                                         }
    780                                         else{
    781                                                 string=xNew<char>(1);
    782                                                 string[0]='\0';
    783                                         }
    784                                         if(strcmp(record_name,"md.flowequation.fe_SSA")==0){
    785                                                 this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
    786                                         } else if(strcmp(record_name,"md.flowequation.fe_HO")==0){
    787                                                 this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
    788                                         } else if(strcmp(record_name,"md.flowequation.fe_FS")==0){
    789                                                 this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
    790                                         } else if(strcmp(record_name,"md.groundingline.migration")==0){
    791                                                 this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
    792                                         } else if(strcmp(record_name,"md.masstransport.hydrostatic_adjustment")==0){
    793                                                 this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
    794                                         } else {
    795                                                 /*Add string to parameters: */
    796                                                 this->AddConstant(new IoConstant(string,record_name));
    797                                         }
    798 
    799                                         /*Free string*/
    800                                         xDelete<char>(string);
    801 
    802                                         break;
    803                                 case 5: break; //do nothing. not interested in this type of data, which is memory intensive.
    804                                 case 6: break; //do nothing. not interested in this type of data, which is memory intensive.
    805                                 case 7: break; //do nothing. not interested in this type of data, which is memory intensive.
    806                                 case 8: break; //do nothing. not interested in this type of data, which is memory intensive.
    807                                 case 9:
    808                                         ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    809                                         /*Now allocate string array: */
    810                                         if(numstrings){
    811                                                 strings=xNew<char*>(numstrings);
    812                                                 for(int i=0;i<numstrings;i++)strings[i]=NULL;
    813 
    814                                                 /*Go through strings, and read: */
    815                                                 for(int i=0;i<numstrings;i++){
    816 
    817                                                         ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
    818                                                         if(string_size){
    819                                                                 string=xNew<char>((string_size+1));
    820                                                                 string[string_size]='\0';
    821                                                                 ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
    822                                                         }
    823                                                         else{
    824                                                                 string=xNew<char>(1);
    825                                                                 string[0]='\0';
    826                                                         }
    827                                                         strings[i]=string;
     784                                                if(strcmp(record_name,"md.flowequation.fe_SSA")==0){
     785                                                        this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
     786                                                } else if(strcmp(record_name,"md.flowequation.fe_HO")==0){
     787                                                        this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
     788                                                } else if(strcmp(record_name,"md.flowequation.fe_FS")==0){
     789                                                        this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
     790                                                } else if(strcmp(record_name,"md.groundingline.migration")==0){
     791                                                        this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
     792                                                } else if(strcmp(record_name,"md.masstransport.hydrostatic_adjustment")==0){
     793                                                        this->AddConstant(new IoConstant(StringToEnumx(string),record_name));
     794                                                } else {
     795                                                        /*Add string to parameters: */
     796                                                        this->AddConstant(new IoConstant(string,record_name));
    828797                                                }
    829                                         }
    830 
    831                                         /*Add strings to parameters: */
    832                                         this->AddConstant(new IoConstant(strings,numstrings,record_name));
    833 
    834                                         /*Free string*/
    835                                         for(int i=0;i<numstrings;i++) xDelete<char>(strings[i]);
    836                                         xDelete<char*>(strings);
    837                                         break;
    838                                 default:
    839                                         _error_("unknown record type:" << record_code);
    840                                         break;
     798
     799                                                /*Free string*/
     800                                                xDelete<char>(string);
     801
     802                                                break;
     803                                        case 5: break; //do nothing. not interested in this type of data, which is memory intensive.
     804                                        case 6: break; //do nothing. not interested in this type of data, which is memory intensive.
     805                                        case 7: break; //do nothing. not interested in this type of data, which is memory intensive.
     806                                        case 8: break; //do nothing. not interested in this type of data, which is memory intensive.
     807                                        case 9:
     808                                                          ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     809                                                          /*Now allocate string array: */
     810                                                          if(numstrings){
     811                                                                  strings=xNew<char*>(numstrings);
     812                                                                  for(int i=0;i<numstrings;i++)strings[i]=NULL;
     813
     814                                                                  /*Go through strings, and read: */
     815                                                                  for(int i=0;i<numstrings;i++){
     816
     817                                                                          ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
     818                                                                          if(string_size){
     819                                                                                  string=xNew<char>((string_size+1));
     820                                                                                  string[string_size]='\0';
     821                                                                                  ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
     822                                                                          }
     823                                                                          else{
     824                                                                                  string=xNew<char>(1);
     825                                                                                  string[0]='\0';
     826                                                                          }
     827                                                                          strings[i]=string;
     828                                                                  }
     829                                                          }
     830
     831                                                          /*Add strings to parameters: */
     832                                                          this->AddConstant(new IoConstant(strings,numstrings,record_name));
     833
     834                                                          /*Free string*/
     835                                                          for(int i=0;i<numstrings;i++) xDelete<char>(strings[i]);
     836                                                          xDelete<char*>(strings);
     837                                                          break;
     838                                        default:
     839                                                          _error_("unknown record type:" << record_code);
     840                                                          break;
    841841                                }
    842 
     842                                xDelete<char>(record_name);
    843843                        }
    844844                }
  • issm/trunk-jpl/src/c/classes/Params/Parameters.cpp

    r20827 r20943  
    221221
    222222/*Object management*/
     223void Parameters::Delete(int param_enum){/*{{{*/
     224
     225        _assert_(param_enum>ParametersSTARTEnum);
     226        _assert_(param_enum<ParametersENDEnum);
     227
     228        int index = param_enum - ParametersSTARTEnum -1;
     229        if(this->params[index]){
     230                delete this->params[index];
     231                this->params[index] = NULL;
     232        }
     233
     234        return;
     235}
     236/*}}}*/
    223237bool Parameters::Exist(int param_enum){/*{{{*/
    224238
  • issm/trunk-jpl/src/c/classes/Params/Parameters.h

    r20827 r20943  
    3232                void  DeepEcho();
    3333                void  Echo();
     34                void  Delete(int enum_type);
    3435                bool  Exist(int enum_type);
    3536                void  Marshall(char** pmarshalled_data, int* pmarshalled_data_size, int marshall_direction);
  • issm/trunk-jpl/src/c/modules/OutputResultsx/OutputResultsx.cpp

    r19709 r20943  
    4646        }
    4747
    48         /*Now, open file for writing, if not already done: */
    49         if(!femmodel->parameters->Exist(OutputFilePointerEnum)){
     48        /*Now, open file for writing*/
     49        _assert_(!femmodel->parameters->Exist(OutputFilePointerEnum));
     50        femmodel->parameters->FindParam(&outputfilename,OutputFileNameEnum);
     51        femmodel->parameters->FindParam(&io_gather,SettingsIoGatherEnum);
    5052
    51                 /*We don't have a file pointer. Retrieve the output file name and open it for writing:*/
    52                 femmodel->parameters->FindParam(&outputfilename,OutputFileNameEnum);
     53#ifdef _HAVE_JAVASCRIPT_
     54        femmodel->parameters->FindParam(&fid,OutputFilePointerEnum);
     55#else
    5356
    54                 /*What strategy? : */
    55                 femmodel->parameters->FindParam(&io_gather,SettingsIoGatherEnum);
     57        if(io_gather){
     58                /*Just open the file for output on cpu 0. We are gathering the data on cpu 0 from all other cpus: */
     59                if(my_rank==0) fid=pfopen0(outputfilename ,"ab+");
     60        }
     61        else{
     62                /*We are opening different  files for output on all cpus. Append the  rank to the filename, and open: */
     63                sprintf(cpu_outputfilename,"%s.%i",outputfilename,my_rank);
     64                fid=pfopen(cpu_outputfilename ,"ab+");
     65        }
    5666
    57                 if(io_gather){
    58                         /*Just open the file for output on cpu 0. We are gathering the data on cpu 0 from all other cpus: */
    59                         if(my_rank==0) fid=pfopen0(outputfilename ,"wb");
    60                 }
    61                 else{
    62                         /*We are opening different  files for output on all cpus. Append the  rank to the filename, and open: */
    63                         femmodel->parameters->FindParam(&fid,OutputFilePointerEnum);
    64                         sprintf(cpu_outputfilename,"%s.%i",outputfilename,my_rank);
    65                         fid=pfopen(cpu_outputfilename ,"wb");
    66                 }
    67                 xDelete<char>(outputfilename);
    68 
    69                 /*Add file pointer in parameters for further calls to OutputResultsx: */
    70                 femmodel->parameters->SetParam(fid,OutputFilePointerEnum);
    71         }
     67        /*Add file pointer in parameters for further calls to OutputResultsx: */
     68        femmodel->parameters->SetParam(fid,OutputFilePointerEnum);
     69#endif
    7270
    7371        /*Write results to disk: */
    7472        femmodel->results->Write(femmodel->parameters);
    7573
     74        femmodel->parameters->Delete(OutputFilePointerEnum);
     75
    7676        /*Delete and reinitialize results, in parallel: */
    7777        femmodel->results->clear();
    7878
     79#ifndef _HAVE_JAVASCRIPT_
    7980        /*Close output file? :*/
    80         /*FIXME WARNING: issm.cpp is taking care of it for now (quick fix)
    81           if((step==1) && (time==0)){
    82           if(io_gather){
    83           if(my_rank==0) pfclose(fid,outputfilename);
    84           }
    85           else pfclose(fid,cpu_outputfilename);
    86           }
    87         */
     81        if(io_gather){
     82                if(my_rank==0) pfclose(fid,outputfilename);
     83        }
     84        else pfclose(fid,cpu_outputfilename);
     85#endif
     86
     87        /*Clean up and return*/
     88        xDelete<char>(outputfilename);
    8889}
Note: See TracChangeset for help on using the changeset viewer.