SIONlib  1.7.7
Scalable I/O library for parallel access to task-local files
sion_mpi_file_check.c
1 /****************************************************************************
2 ** SIONLIB http://www.fz-juelich.de/jsc/sionlib **
3 *****************************************************************************
4 ** Copyright (c) 2008-2019 **
5 ** Forschungszentrum Juelich, Juelich Supercomputing Centre **
6 ** **
7 ** See the file COPYRIGHT in the package base directory for details **
8 ****************************************************************************/
9 /*
10  *
11  * \brief Internal Functions(parallel)
12  */
13 
14 #define _XOPEN_SOURCE 700
15 
16 #include <stdlib.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include <unistd.h>
20 
21 #include "mpi.h"
22 
23 #include "sion.h"
24 #include "sion_debug.h"
25 #include "sion_error_handler.h"
26 #include "sion_internal.h"
27 #include "sion_fd.h"
28 #include "sion_filedesc.h"
29 #include "sion_printts.h"
30 #include "sion_flags.h"
31 
32 
33 #ifdef SION_MPI
34 
35 #include "sion_generic.h"
36 
37 #include "sion_mpi.h"
38 #include "sion_mpi_internal_gen.h"
39 
40 #include "sion_mpi_cb_gen.h"
41 
42 
44  char *file_mode;
45  int numfiles;
46  MPI_Comm gComm;
47  MPI_Comm lComm;
48 };
49 
57 #define DFUNCTION "_sion_paropen_generic_buddy"
58 sion_file_check_par_args_mpi *sion_file_check_par_args_init_mpi( const char *file_mode,
59  MPI_Comm gComm,
60  int numfiles,
61  MPI_Comm lComm
62  ) {
64 
65  cb_args = (sion_file_check_par_args_mpi *) malloc(sizeof(sion_file_check_par_args_mpi));
66  if (cb_args == NULL) {
67  _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"cannot allocate cb_args structure of size %lu (sion_file_check_par_args), aborting ...\n",
68  (unsigned long) sizeof(sion_file_check_par_args_mpi));
69  return(NULL);
70  }
71 
72  cb_args->file_mode=strdup(file_mode);
73  cb_args->gComm=gComm;
74  cb_args->lComm=lComm;
75  cb_args->numfiles=numfiles;
76 
77  return(cb_args);
78 }
79 #undef DFUNCTION
80 
81 #define DFUNCTION "sion_file_check_par_args_free_mpi"
82 int sion_file_check_par_args_free_mpi( sion_file_check_par_args_mpi *cb_args ) {
83  int rc=SION_SUCCESS;
84  if(cb_args!=NULL) {
85  if(cb_args->file_mode!=NULL) {
86  free(cb_args->file_mode);
87  }
88  free(cb_args);
89  }
90  return(rc);
91 }
92 #undef DFUNCTION
93 
94 #define DFUNCTION "sion_file_check_par_cb_mpi"
95 int sion_file_check_par_cb_mpi( char *fname, void *v_args ) {
97  int rc=SION_NOT_SUCCESS;
98  int gtasks, gRank, sid;
99  sion_int64 chunksize=0;
100  sion_int32 fsblksize=-1;
101  int globalrank=-1;
102 
103 
104  MPI_Comm_size(cb_args->gComm, &gtasks);
105  MPI_Comm_rank(cb_args->gComm, &gRank);
106 
107  DPRINTFP((1, DFUNCTION, gRank, "enter parallel check of file %s with mode %s\n", fname,cb_args->file_mode));
108 
109  _sion_errorprint_set_flag(_SION_ERROR_FLAG_SUPPRESS_MSG);
110  sid = sion_paropen_mpi(fname, cb_args->file_mode, &cb_args->numfiles, cb_args->gComm, &cb_args->lComm, &chunksize, &fsblksize, &globalrank, NULL, NULL);
111  _sion_errorprint_set_flag(_SION_ERROR_FLAG_NONE);
112  if(sid<0) {
113  rc=SION_NOT_SUCCESS;
114  } else {
115  rc=SION_SUCCESS;
116  sion_parclose_mpi(sid);
117  }
118 
119  DPRINTFP((1, DFUNCTION, gRank, "leave parallel check of file %s with mode %s rc=%d\n", fname,cb_args->file_mode,rc));
120  return(rc);
121 }
122 #undef DFUNCTION
123 
124 #endif
int sion_paropen_mpi(const char *fname, const char *file_mode, int *numFiles, MPI_Comm gComm, const MPI_Comm *lComm, sion_int64 *chunksize, sion_int32 *fsblksize, int *globalrank, FILE **fileptr, char **newfname)
Open a sion file using MPI.
Definition: sion_mpi_gen.c:85
int sion_parclose_mpi(int sid)
Close a sion file using MPI.
Definition: sion_mpi_gen.c:230
Sion Time Stamp Header.