SIONlib  1.7.7
Scalable I/O library for parallel access to task-local files
sion_fortran_ompi.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 #include "sion.h"
27 #include "sion_debug.h"
28 #include "sion_fd.h"
29 #include "sion_filedesc.h"
30 #include "sion_ompi.h"
31 #include "sion_fortran_ompi.h"
32 
55 void fsion_paropen_ompi_c(char *fname,
56  char *file_mode,
57  int *numFiles,
58  MPI_Fint * fgComm,
59  MPI_Fint * flComm,
60  sion_int64 *chunksize,
61  sion_int32 *fsblksize,
62  int *globalrank,
63  char *newfname,
64  int *sid,
65  int fname_len,
66  int file_mode_len,
67  int newfname_len)
68 {
69  char *fname_tmp,*fmode_tmp;
70  MPI_Comm cgComm,clComm;
71 
72  fname_tmp = (char *) malloc((size_t) ((fname_len + 1) * sizeof(char)));
73  fmode_tmp = (char *) malloc((size_t) ((file_mode_len + 1) * sizeof(char)));
74 
75  /* Copy the strings to the new buffers and pad with nulls */
76  strncpy(fname_tmp, fname, fname_len);
77  strncpy(fmode_tmp, file_mode, file_mode_len);
78 
79  fname_tmp[fname_len] = '\0';
80  fmode_tmp[file_mode_len] = '\0';
81 
82  cgComm = MPI_Comm_f2c(*fgComm);
83  clComm = MPI_Comm_f2c(*flComm);
84 
85 #ifdef SION_DEBUG_UNUSED
86 #pragma omp master
87  {
88  if (*globalrank == 0){
89  if (cgComm == MPI_COMM_WORLD) fprintf(stderr,"COMM_WORLD selected\n");
90  fprintf(stderr,"fsion_paropen_ompi_c: filename_len: %d\n", (int) fname_len);
91  fprintf(stderr,"fsion_paropen_ompi_c: filename: %s\n",fname_tmp);
92 
93  fprintf(stderr,"fsion_paropen_ompi_c: filemode_len: %d\n", (int) file_mode_len);
94  fprintf(stderr,"fsion_paropen_ompi_c: filemode: %s\n",fmode_tmp);
95 
96  fprintf(stderr,"fsion_paropen_ompi_c: chunksize: %lld\n",*chunksize);
97  fprintf(stderr,"fsion_paropen_ompi_c: fsblksize: %d\n",*fsblksize);
98  fprintf(stderr,"fsion_paropen_ompi_c: numFiles: %d\n",*numFiles);
99  }
100  }
101 #pragma omp barrier
102 #endif
103 
104  (*sid) = sion_paropen_ompi(fname_tmp, fmode_tmp, numFiles, cgComm, &clComm, chunksize, fsblksize, globalrank, NULL, NULL);
105 
106  *flComm = MPI_Comm_c2f(clComm);
107 
108  /* Free the used memory */
109  free(fname_tmp);
110  free(fmode_tmp);
111 
112 }
113 
139 void fsion_paropen_multi_ompi_c(char *fname,
140  char *file_mode,
141  int *numFiles,
142  MPI_Fint *fgComm,
143  MPI_Fint *flComm,
144  sion_int64 *chunksize,
145  sion_int32 *fsblksize,
146  int *globalrank,
147  int *sid,
148  char *newfname,
149  int fname_len,
150  int file_mode_len,
151  int newfname_len)
152 {
153  MPI_Comm cgComm, clComm;
154 
155  /* Fortran strings are not NULL-terminated => insert \0 at the end */
156  char *fname_tmp, *fmode_tmp, *newfname_tmp;
157 
158 
159  fname_tmp = (char *) malloc((size_t) ((fname_len + 1) * sizeof(char)));
160  fmode_tmp = (char *) malloc((size_t) ((file_mode_len + 1) * sizeof(char)));
161  newfname_tmp = (char *) malloc((size_t) ((newfname_len + 1) * sizeof(char)));
162 
163  /* Copy the strings to the new buffers and pad with nulls */
164  strncpy(fname_tmp, fname, fname_len);
165  strncpy(fmode_tmp, file_mode, file_mode_len);
166 
167  fname_tmp[fname_len] = '\0';
168  fmode_tmp[file_mode_len] = '\0';
169  newfname_tmp[newfname_len] = '\0';
170  strncpy(newfname_tmp, newfname, newfname_len);
171 
172  cgComm = MPI_Comm_f2c(*fgComm);
173 
174  (*sid) = sion_paropen_ompi(fname_tmp, fmode_tmp, numFiles, cgComm, &clComm, chunksize, fsblksize, globalrank, NULL, &newfname_tmp);
175 
176  *flComm = MPI_Comm_c2f(clComm);
177  strncpy(newfname, newfname_tmp, newfname_len);
178 
179  /* Free the used memory */
180  free(fname_tmp);
181  free(fmode_tmp);
182  free(newfname_tmp);
183 }
184 
195 void fsion_parclose_ompi_c(int *sid,
196  int *ierr)
197 {
198  (*ierr) = sion_parclose_ompi(*sid);
199 }
200 
void fsion_paropen_multi_ompi_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.
void fsion_paropen_ompi_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)
Fortran wrapper function that calls sion_paropen_mpi for 1 file.
void fsion_parclose_ompi_c(int *sid, int *ierr)
Fortran procedure to close a sion file opened in OpenMP/MPI in parallel.