SIONlib  1.7.1
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-2016 **
5 ** Forschungszentrum Juelich, Juelich Supercomputing Centre **
6 ** **
7 ** See the file COPYRIGHT in the package base directory for details **
8 ****************************************************************************/
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 
22 #include "mpi.h"
23 
24 #include "sion.h"
25 #include "sion_debug.h"
26 #include "sion_fd.h"
27 #include "sion_filedesc.h"
28 #include "sion_ompi.h"
29 #include "sion_fortran_ompi.h"
30 
53 void fsion_paropen_ompi_c(char *fname,
54  char *file_mode,
55  int *numFiles,
56  MPI_Fint * fgComm,
57  MPI_Fint * flComm,
58  sion_int64 *chunksize,
59  sion_int32 *fsblksize,
60  int *globalrank,
61  char *newfname,
62  int *sid,
63  int fname_len,
64  int file_mode_len,
65  int newfname_len)
66 {
67  FILE *fileptr;
68  char *fname_tmp,*fmode_tmp;
69  MPI_Comm cgComm,clComm;
70 
71  fname_tmp = (char *) malloc((size_t) ((fname_len + 1) * sizeof(char)));
72  fmode_tmp = (char *) malloc((size_t) ((file_mode_len + 1) * sizeof(char)));
73 
74  /* Copy the strings to the new buffers and pad with nulls */
75  strncpy(fname_tmp, fname, fname_len);
76  strncpy(fmode_tmp, file_mode, file_mode_len);
77 
78  fname_tmp[fname_len] = '\0';
79  fmode_tmp[file_mode_len] = '\0';
80 
81  cgComm = MPI_Comm_f2c(*fgComm);
82  clComm = MPI_Comm_f2c(*flComm);
83 
84 #ifdef SION_DEBUG_UNUSED
85 #pragma omp master
86  {
87  if (*globalrank == 0){
88  if (cgComm == MPI_COMM_WORLD) fprintf(stderr,"COMM_WORLD selected\n");
89  fprintf(stderr,"fsion_paropen_ompi_c: filename_len: %d\n", (int) fname_len);
90  fprintf(stderr,"fsion_paropen_ompi_c: filename: %s\n",fname_tmp);
91 
92  fprintf(stderr,"fsion_paropen_ompi_c: filemode_len: %d\n", (int) file_mode_len);
93  fprintf(stderr,"fsion_paropen_ompi_c: filemode: %s\n",fmode_tmp);
94 
95  fprintf(stderr,"fsion_paropen_ompi_c: chunksize: %lld\n",*chunksize);
96  fprintf(stderr,"fsion_paropen_ompi_c: fsblksize: %d\n",*fsblksize);
97  fprintf(stderr,"fsion_paropen_ompi_c: numFiles: %d\n",*numFiles);
98  }
99  }
100 #pragma omp barrier
101 #endif
102 
103  (*sid) = sion_paropen_ompi(fname_tmp, fmode_tmp, numFiles, cgComm, &clComm, chunksize, fsblksize, globalrank, &fileptr, NULL);
104 
105  *flComm = MPI_Comm_c2f(clComm);
106 
107  /* Free the used memory */
108  free(fname_tmp);
109  free(fmode_tmp);
110 
111 }
112 
138 void fsion_paropen_multi_ompi_c(char *fname,
139  char *file_mode,
140  int *numFiles,
141  MPI_Fint *fgComm,
142  MPI_Fint *flComm,
143  sion_int64 *chunksize,
144  sion_int32 *fsblksize,
145  int *globalrank,
146  int *sid,
147  char *newfname,
148  int fname_len,
149  int file_mode_len,
150  int newfname_len)
151 {
152  FILE *fileptr;
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, &fileptr, &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_parclose_ompi_c(int *sid, int *ierr)
Fortran procedure to close a sion file opened in OpenMP/MPI 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_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.