Ice Sheet System Model  4.18
Code documentation
Functions
pfopen.cpp File Reference

fopen wrapper for parallel solution More...

#include <stdio.h>
#include "../Print/Print.h"
#include "../Comm/IssmComm.h"
#include "../../Exceptions/exceptions.h"

Go to the source code of this file.

Functions

FILE * pfopen0 (char *filename, const char *format)
 
FILE * pfopen (char *filename, const char *format, bool errorout)
 

Detailed Description

fopen wrapper for parallel solution

Definition in file pfopen.cpp.

Function Documentation

◆ pfopen0()

FILE* pfopen0 ( char *  filename,
const char *  format 
)

Definition at line 16 of file pfopen.cpp.

16  {
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 }

◆ pfopen()

FILE* pfopen ( char *  filename,
const char *  format,
bool  errorout 
)

Definition at line 30 of file pfopen.cpp.

30  {
31 
32  FILE* fid=NULL;
33 
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);
42  }
43  if(errorout && fid==NULL)_error_("could not open file " << filename << " for binary reading or writing");
44 
45  return fid;
46 }
IssmComm::GetComm
static ISSM_MPI_Comm GetComm(void)
Definition: IssmComm.cpp:30
IssmComm::GetSize
static int GetSize(void)
Definition: IssmComm.cpp:46
IssmComm::GetRank
static int GetRank(void)
Definition: IssmComm.cpp:34
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
ISSM_MPI_Barrier
int ISSM_MPI_Barrier(ISSM_MPI_Comm comm)
Definition: issmmpi.cpp:148