SIONlib  1.7.7
Scalable I/O library for parallel access to task-local files
sion_fortran_mpi.c
Go to the documentation of this file.
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 ****************************************************************************/
18 #define _XOPEN_SOURCE 700
19 
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 
24 #include "mpi.h"
25 
26 /* #define _FORTRANUNDERSCORE
27  #define _FORTRANNOCAPS
28  #define _FORTRANCAPS
29  #define _FORTRANDOUBLEUNDERSCORE */
30 #include "sion.h"
31 #include "sion_debug.h"
32 #include "sion_fd.h"
33 #include "sion_filedesc.h"
34 #include "sion_mpi.h"
35 #include "sion_fortran_mpi.h"
36 
62 void fsion_paropen_mpi_c(char *fname,
63  char *file_mode,
64  int *numFiles,
65  MPI_Fint * fgComm,
66  MPI_Fint * flComm,
67  sion_int64 *chunksize,
68  sion_int32 *fsblksize,
69  int *globalrank,
70  char *newfname,
71  int *sid,
72  int fname_len,
73  int file_mode_len,
74  int newfname_len) {
75 
76  char *fname_tmp,*fmode_tmp;
77  MPI_Comm cgComm,clComm;
78 
79 
80 #ifdef SION_DEBUG_BUG_OPENMPI
81  {
82  int grank;
83  MPI_Comm newcomm;
84  MPI_Comm_rank(MPI_COMM_WORLD,&grank);
85  fprintf(stderr,"fsion_paropen_mpi: grank: %d\n", (int) grank);
86  MPI_Comm_dup(MPI_COMM_WORLD,&newcomm);
87  MPI_Comm_split(MPI_COMM_WORLD,0,grank,&newcomm);
88  }
89 #endif
90 
91  fname_tmp = (char *) malloc((size_t) ((fname_len + 1) * sizeof(char)));
92  fmode_tmp = (char *) malloc((size_t) ((file_mode_len + 1) * sizeof(char)));
93 
94  /* Copy the strings to the new buffers and pad with nulls */
95  strncpy(fname_tmp, fname, fname_len);
96  strncpy(fmode_tmp, file_mode, file_mode_len);
97 
98  fname_tmp[fname_len] = '\0';
99  fmode_tmp[file_mode_len] = '\0';
100 /* newfname_tmp[newfname_len] = '\0'; */
101 /* strncpy(newfname_tmp, newfname, newfname_len); */
102 
103  cgComm = MPI_Comm_f2c(*fgComm);
104  clComm = MPI_Comm_f2c(*flComm);
105 
106 #ifdef SION_DEBUG_UNUSED
107  if (*globalrank == 0){
108  if (cgComm == MPI_COMM_WORLD) fprintf(stderr,"COMM_WORLD selected\n");
109  fprintf(stderr,"fsion_paropen_mpi: filename_len: %d\n", (int) fname_len);
110  fprintf(stderr,"fsion_paropen_mpi: filename: %s\n",fname_tmp);
111  /*
112  fprintf(stderr,"fsion_paropen_mpi: newfname_len: %d\n",(int) newfname_len);
113  fprintf(stderr,"fsion_paropen_mpi: newfname: %s\n",newfname_tmp);
114  */
115  fprintf(stderr,"fsion_paropen_mpi: filemode_len: %d\n", (int) file_mode_len);
116  fprintf(stderr,"fsion_paropen_mpi: filemode: %s\n",fmode_tmp);
117 
118  fprintf(stderr,"fsion_paropen_mpi: chunksize: %lld\n",*chunksize);
119  fprintf(stderr,"fsion_paropen_mpi: fsblksize: %d\n",*fsblksize);
120  fprintf(stderr,"fsion_paropen_mpi: numFiles: %d\n",*numFiles);
121  }
122 #endif
123 
124  (*sid) = sion_paropen_mpi(fname_tmp, fmode_tmp, numFiles, cgComm, &clComm, chunksize, fsblksize, globalrank, NULL, NULL);
125 
126  /* int help=MPI_Comm_c2f(clComm); */
127  /* printf("WF: flComm=%d (%x), help=%d\n",*flComm,flComm,help); */
128 /* *flComm = MPI_Comm_c2f(clComm); WF */
129 /* strncpy(newfname, newfname_tmp, newfname_len); */
130 
131  /* Free the used memory */
132  free(fname_tmp);
133  free(fmode_tmp);
134 
135 }
136 
163 void fsion_paropen_multi_mpi_c(char *fname,
164  char *file_mode,
165  int *numFiles,
166  MPI_Fint * fgComm,
167  MPI_Fint * flComm,
168  sion_int64 *chunksize,
169  sion_int32 *fsblksize,
170  int *globalrank, int *sid, char *newfname, int fname_len, int file_mode_len, int newfname_len)
171 {
172  MPI_Comm cgComm, clComm;
173 
174  /* Fortran strings are not NULL-terminated => insert \0 at the end */
175  char *fname_tmp, *fmode_tmp, *newfname_tmp;
176 
177 
178  fname_tmp = (char *) malloc((size_t) ((fname_len + 1) * sizeof(char)));
179  fmode_tmp = (char *) malloc((size_t) ((file_mode_len + 1) * sizeof(char)));
180  newfname_tmp = (char *) malloc((size_t) ((newfname_len + 1) * sizeof(char)));
181  /* Copy the strings to the new buffers and pad with nulls */
182  strncpy(fname_tmp, fname, fname_len);
183  strncpy(fmode_tmp, file_mode, file_mode_len);
184 
185  fname_tmp[fname_len] = '\0';
186  fmode_tmp[file_mode_len] = '\0';
187  newfname_tmp[newfname_len] = '\0';
188  strncpy(newfname_tmp, newfname, newfname_len);
189 
190  cgComm = MPI_Comm_f2c(*fgComm);
191  /* clComm = MPI_Comm_f2c(*flComm); */
192 
193  /*
194  #ifdef SION_DEBUG
195  if (*globalrank == 0){
196  if (cgComm == MPI_COMM_WORLD) fprintf(stderr,"COMM_WORLD selected\n");
197  fprintf(stderr,"fsion_paropen_mpi: filename_len: %d\n", fname_len);
198  fprintf(stderr,"fsion_paropen_mpi: filename: %s\n",fname_tmp);
199 
200  fprintf(stderr,"fsion_paropen_mpi: newfname_len: %d\n", newfname_len);
201  fprintf(stderr,"fsion_paropen_mpi: newfname: %s\n",newfname_tmp);
202 
203  fprintf(stderr,"fsion_paropen_mpi: filemode_len: %d\n", file_mode_len);
204  fprintf(stderr,"fsion_paropen_mpi: filemode: %s\n",fmode_tmp);
205 
206  fprintf(stderr,"fsion_paropen_mpi: chunksize: %lld\n",*chunksize);
207  fprintf(stderr,"fsion_paropen_mpi: fsblksize: %d\n",*fsblksize);
208  fprintf(stderr,"fsion_paropen_mpi: numFiles: %d\n",*numFiles);
209  }
210  #endif
211  */
212  (*sid) = sion_paropen_multi_mpi(fname_tmp, fmode_tmp, numFiles, cgComm, &clComm, chunksize, fsblksize, globalrank, NULL, newfname_tmp);
213 
214  *flComm = MPI_Comm_c2f(clComm);
215  strncpy(newfname, newfname_tmp, newfname_len);
216 
217  /* Free the used memory */
218  free(fname_tmp);
219  free(fmode_tmp);
220  free(newfname_tmp);
221 }
222 
233 void fsion_parclose_mpi_c(int *sid, int *ierr)
234 {
235  (*ierr) = sion_parclose_mpi(*sid);
236 }
237 
void fsion_parclose_mpi_c(int *sid, int *ierr)
Fortran procedure to close a sion file in parallel.
void fsion_paropen_mpi_c(char *fname, char *file_mode, int *numFiles, MPI_Fint *fgComm, MPI_Fint *flComm, sion_int64 *chunksize, sion_int32 *fsblksize, int *globalrank, char *newfname, int *sid, int fname_len, int file_mode_len, int newfname_len)
Wrapper function that calls fsion_paropen_multi_mpi for 1 file.
void fsion_paropen_multi_mpi_c(char *fname, char *file_mode, int *numFiles, MPI_Fint *fgComm, MPI_Fint *flComm, sion_int64 *chunksize, sion_int32 *fsblksize, int *globalrank, int *sid, char *newfname, int fname_len, int file_mode_len, int newfname_len)
Fortran procedure to open multiple sion files in parallel.
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