SIONlib  2.0.0-rc.1
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-2018 **
5 ** Forschungszentrum Juelich, Juelich Supercomputing Centre **
6 ** **
7 ** See the file COPYRIGHT in the package base directory for details **
8 ****************************************************************************/
9 
10 #define _XOPEN_SOURCE 700
11 
12 #include <mpi.h>
13 #include <stdint.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 
18 #include "sion_const.h"
19 #include "sion_debug.h"
20 #include "sion_error_handler.h"
21 
22 #ifdef SION_MPI
23 
24 #include "sion_mpi.h"
25 
27  char *file_mode;
28  int numfiles;
29  MPI_Comm gComm;
30  MPI_Comm lComm;
31 };
32 
33 #define DFUNCTION "_sion_paropen_generic_buddy"
34 sion_file_check_par_args_mpi *sion_file_check_par_args_init_mpi(
35  const char *file_mode, MPI_Comm gComm, int numfiles, MPI_Comm lComm)
36 {
38 
39  cb_args = malloc(sizeof(sion_file_check_par_args_mpi));
40  if (cb_args == NULL) {
41  _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_RETURN,
42  "cannot allocate cb_args structure of size %lu (sion_file_check_par_args), aborting ...\n",
43  (unsigned long)sizeof(sion_file_check_par_args_mpi));
44  return NULL;
45  }
46 
47  cb_args->file_mode = strdup(file_mode);
48  cb_args->gComm = gComm;
49  cb_args->lComm = lComm;
50  cb_args->numfiles = numfiles;
51 
52  return cb_args;
53 }
54 #undef DFUNCTION
55 
56 #define DFUNCTION "sion_file_check_par_args_free_mpi"
57 int sion_file_check_par_args_free_mpi(sion_file_check_par_args_mpi *cb_args)
58 {
59  int rc = SION_SUCCESS;
60  if (cb_args != NULL) {
61  free(cb_args->file_mode);
62  free(cb_args);
63  }
64  return rc;
65 }
66 #undef DFUNCTION
67 
68 #define DFUNCTION "sion_file_check_par_cb_mpi"
69 int sion_file_check_par_cb_mpi(char *fname, void *v_args)
70 {
71  sion_file_check_par_args_mpi *cb_args = v_args;
72  int rc = SION_NOT_SUCCESS;
73  int gtasks, gRank, sid;
74  int64_t chunksize = 0;
75  int32_t fsblksize = -1;
76  int globalrank = -1;
77 
78  MPI_Comm_size(cb_args->gComm, &gtasks);
79  MPI_Comm_rank(cb_args->gComm, &gRank);
80 
81  DPRINTFP((1, DFUNCTION, gRank, "enter parallel check of file %s with mode %s\n", fname, cb_args->file_mode));
82 
83  _sion_errorprint_set_flag(_SION_ERROR_FLAG_SUPPRESS_MSG);
84  sid = sion_paropen_mpi(fname, cb_args->file_mode, &cb_args->numfiles, cb_args->gComm, &cb_args->lComm, &chunksize, &fsblksize,
85  &globalrank, NULL, NULL);
86  _sion_errorprint_set_flag(_SION_ERROR_FLAG_NONE);
87  if (sid < 0) {
88  rc = SION_NOT_SUCCESS;
89  } else {
90  rc = SION_SUCCESS;
91  sion_parclose_mpi(sid);
92  }
93 
94  DPRINTFP((1, DFUNCTION, gRank, "leave parallel check of file %s with mode %s rc=%d\n", fname, cb_args->file_mode, rc));
95  return rc;
96 }
97 #undef DFUNCTION
98 
99 #endif
int sion_parclose_mpi(int sid)
Close a sion file using MPI.
Definition: sion_mpi_gen.c:162
int sion_paropen_mpi(const char *fname, const char *file_mode, int *numFiles, MPI_Comm gComm, const MPI_Comm *lComm, int64_t *chunksize, int32_t *fsblksize, int *globalrank, FILE **fileptr, char **newfname)
Open a sion file using MPI.
Definition: sion_mpi_gen.c:35