Changeset 15559


Ignore:
Timestamp:
07/23/13 12:06:26 (12 years ago)
Author:
Mathieu Morlighem
Message:

BUG: on fe233, pfopen crashed because the same file cannot be created simultaneously by all processor

Location:
issm/trunk-jpl/src/c
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/classes/FemModel.cpp

    r15444 r15559  
    188188
    189189        /*Open input file on cpu 0: */
    190         if(my_rank==0) IOMODEL = pfopen(inputfilename ,"rb");
     190        if(my_rank==0) IOMODEL = pfopen0(inputfilename ,"rb");
    191191
    192192        /*Initialize internal data: */
     
    14651465        /*Get response*/
    14661466        J=0;
     1467        //_printf_(true,"list of misfits: ");
    14671468        for(int i=0;i<num_responses;i++){
    14681469                this->Responsex(&Jplus,EnumToStringx(responses[i]),i);
     1470                //_printf_(true," %12.7g ",Jplus);
    14691471                J+=Jplus;
    14701472        }
     1473        //_printf_(true," \n");
    14711474
    14721475        /*Assign output pointers: */
  • issm/trunk-jpl/src/c/modules/OutputResultsx/OutputResultsx.cpp

    r15128 r15559  
    6161                if(io_gather){
    6262                        /*Just open the file for output on cpu 0. We are gathering the data on cpu 0 from all other cpus: */
    63                         if(my_rank==0) fid=pfopen(outputfilename ,"wb");
     63                        if(my_rank==0) fid=pfopen0(outputfilename ,"wb");
    6464                }
    6565                else{
  • issm/trunk-jpl/src/c/shared/io/Disk/diskio.h

    r13549 r15559  
    99
    1010FILE* pfopen(char* filename,const char* format);
     11FILE* pfopen0(char* filename,const char* format);
    1112void  pfclose(FILE* fid,char* filename);
    1213void WriteLockFile(char* filename);
  • issm/trunk-jpl/src/c/shared/io/Disk/pfopen.cpp

    r14950 r15559  
    44
    55#ifdef HAVE_CONFIG_H
    6         #include <config.h>
     6#include <config.h>
    77#else
    88#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
     
    1010
    1111#include <stdio.h>
    12 #include "../../shared.h"
     12#include "../Print/Print.h"
     13#include "../Comm/Comm.h"
     14#include "../../Exceptions/exceptions.h"
    1315
     16FILE* pfopen0(char* filename,const char* format){
     17
     18        FILE* fid=NULL;
     19
     20        /*recover my_rank:*/
     21        int my_rank  = IssmComm::GetRank();
     22        if(my_rank) _error_("This function should only be called by cpu 0");
     23
     24        /*Open handle to data on disk*/
     25        fid = fopen(filename,format);
     26        if(fid==NULL) _error_("could not open file " << filename << " for binary reading or writing");
     27
     28        return fid;
     29}
    1430FILE* pfopen(char* filename,const char* format){
    1531
    1632        FILE* fid=NULL;
    1733
    18         /*Open handle to data on disk: */
    19         fid=fopen(filename,format);
    20         if(fid==NULL) _error_("could not open file " << filename << " for binary reading or writing");
     34        /*recover my_rank:*/
     35        int my_rank  = IssmComm::GetRank();
     36        int num_proc = IssmComm::GetSize();
     37
     38        /*Open handle to data on disk (one by one to avoid errors)*/
     39        for(int i=0;i<num_proc;i++){
     40                if(my_rank==i) fid = fopen(filename,format);
     41#ifdef _HAVE_MPI_
     42                MPI_Barrier(IssmComm::GetComm());
     43#endif
     44        }
     45        if(fid==NULL) _error_("could not open file " << filename << " for binary reading or writing");
    2146
    2247        return fid;
Note: See TracChangeset for help on using the changeset viewer.