SIONlib  1.7.7
Scalable I/O library for parallel access to task-local files
sion_mpi_deprecated.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 ****************************************************************************/
9 
14 #define _XOPEN_SOURCE 700
15 
16 #include <stdlib.h>
17 #include <stdio.h>
18 #include <stdarg.h>
19 #include <string.h>
20 #include <time.h>
21 
22 #include <sys/time.h>
23 
24 #include <sys/types.h>
25 #include <fcntl.h>
26 
27 #include <unistd.h>
28 
29 #include "mpi.h"
30 
31 #include "sion.h"
32 #include "sion_debug.h"
33 #include "sion_error_handler.h"
34 #include "sion_internal.h"
35 #include "sion_fd.h"
36 #include "sion_filedesc.h"
37 #include "sion_printts.h"
38 
39 #ifdef SION_MPI
40 
41 #include "sion_generic.h"
42 #include "sion_generic_internal.h"
43 
44 #include "sion_mpi.h"
45 #include "sion_mpi_internal_gen.h"
46 
47 #include "sion_mpi_cb_gen.h"
48 
49 
50 /* wrapper for old SIONlib MPI function */
51 size_t sion_coll_fwrite_mpi(const void *data, size_t size, size_t nitems, int sid) {
52  return(sion_coll_fwrite(data,size,nitems,sid));
53 }
54 
55 
56 /* wrapper for old SIONlib MPI function */
57 size_t sion_coll_fread_mpi(void *data, size_t size, size_t nitems, int sid) {
58  return(sion_coll_fread(data,size,nitems,sid));
59 }
60 
61 
62 /* wrapper for old SIONlib MPI function */
63 int sion_paropen_comms_mpi(char *fname,
64  const char *file_mode,
65  int *numFiles,
66  MPI_Comm gComm,
67  MPI_Comm lComm, sion_int64 *chunksize, sion_int32 *fsblksize, int *globalrank, FILE **fileptr, char *newfname)
68 {
69  *numFiles=0;
70  return(sion_paropen_mpi(fname,file_mode,numFiles,gComm,&lComm,chunksize,fsblksize,globalrank,fileptr,&newfname));
71 }
72 
73 int sion_paropen_multi_mpi(char *fname,
74  const char *file_mode,
75  int *numFiles,
76  MPI_Comm gComm,
77  MPI_Comm *lComm, sion_int64 *chunksize, sion_int32 *fsblksize, int *globalrank, FILE **fileptr, char *newfname)
78 {
79  return(sion_paropen_mpi(fname,file_mode,numFiles,gComm,lComm,chunksize,fsblksize,globalrank,fileptr,&newfname));
80 }
81 
82 
83 /* obsolate functions for transaction, not in public interface */
84 int sion_startof_transaction_mpi( int sid ) {
85  int rc = SION_SUCCESS;
86  int grank, lrank, lsize, blocksize, step=0;
87  MPI_Comm gComm, lComm;
88  MPI_Status status;
89  _sion_filedesc *sion_filedesc;
90  const char *t;
91  _sion_generic_gendata *sion_gendata;
92  _mpi_api_commdata *gcommgroup,*lcommgroup;
93 
94  if ( (sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR) || !(sion_filedesc = _sion_vcdtovcon(sid))) {
95  return(_sion_errorprint_mpi(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"sion_parclose_mpi: invalid sion_filedesc %d", sid));
96  }
97  sion_gendata = (_sion_generic_gendata *)sion_filedesc->dataptr;
98  gcommgroup = (_mpi_api_commdata *) sion_gendata->comm_data_global;
99  lcommgroup = (_mpi_api_commdata *) sion_gendata->comm_data_local;
100  gComm=gcommgroup->comm;
101  lComm=lcommgroup->comm;
102  MPI_Comm_rank(gComm, &grank);
103  MPI_Comm_rank(lComm, &lrank);
104  MPI_Comm_size(lComm, &lsize);
105 
106  t = _sion_getenv("SION_SERBLOCKSIZE");
107  if (t) blocksize= atoi(t);
108  else if(lsize>128) blocksize= 32;
109  else if(lsize>64) blocksize= 16;
110  else if(lsize>16) blocksize= 8;
111  else blocksize=lsize;
112  lcommgroup->blocksize=blocksize;
113 
114  /* */ DPRINTFTS(grank, "enter start of transaction of sid");
115  DPRINTFP((1, "sion_startof_transaction_mpi", grank, "enter start of transaction of sid %d blocksize=%d lrank=%d\n", sid,blocksize,lrank));
116 
117  lcommgroup->ts=_sion_get_time();
118 
119  if(lrank>blocksize) {
120  if(sion_filedesc->filenumber==0) fprintf(stderr,"sion_startof_transaction_mpi ts=%8.4fs on grank=%5d lrank=%3d waiting for message from %5d\n",_sion_get_time()-lcommgroup->ts,
121  grank,lrank,lrank-blocksize);
122  MPI_Recv(&step, 1, MPI_INT, lrank-blocksize, 1430, lComm, &status);
123  }
124 
125  lcommgroup->step=step;
126  if(sion_filedesc->filenumber==0) fprintf(stderr,"sion_startof_transaction_mpi ts=%8.4fs on grank=%5d lrank=%3d starting transaction (blocksize=%d, step=%d)\n",_sion_get_time()-lcommgroup->ts,
127  grank,lrank,blocksize,step);
128  DPRINTFP((1, "sion_startof_transaction_mpi", grank, "leave start of transaction of sid %d\n", sid));
129  /* */ DPRINTFTS(grank, "leave start of transaction of sid");
130  return(rc);
131 }
132 
133 int sion_endof_transaction_mpi ( int sid ) {
134  int rc = SION_SUCCESS;
135  int grank, lrank, lsize, blocksize, step=1;
136  MPI_Comm gComm, lComm;
137  _sion_filedesc *sion_filedesc;
138  _sion_generic_gendata *sion_gendata;
139  _mpi_api_commdata *gcommgroup,*lcommgroup;
140 
141  if ( (sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR) || !(sion_filedesc = _sion_vcdtovcon(sid))) {
142  return(_sion_errorprint_mpi(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"sion_parclose_mpi: invalid sion_filedesc %d", sid));
143  }
144  sion_gendata = (_sion_generic_gendata *)sion_filedesc->dataptr;
145  gcommgroup = (_mpi_api_commdata *) sion_gendata->comm_data_global;
146  lcommgroup = (_mpi_api_commdata *) sion_gendata->comm_data_local;
147  gComm=gcommgroup->comm;
148  lComm=lcommgroup->comm;
149  MPI_Comm_rank(gComm, &grank);
150  MPI_Comm_rank(lComm, &lrank);
151  MPI_Comm_size(lComm, &lsize);
152 
153  blocksize=lcommgroup->blocksize;
154  step= lcommgroup->step+1;
155 
156  /* */ DPRINTFTS(grank, "enter end of transaction of sid");
157  DPRINTFP((1, "sion_endof_transaction_mpi", grank, "enter end of transaction of sid %d blocksize=%d lrank=%d\n", sid,blocksize,lrank));
158 
159 
160  if(lrank+blocksize<lsize) {
161  if(sion_filedesc->filenumber==0) fprintf(stderr,"sion_endof_transaction_mpi ts=%8.4fs on grank=%5d lrank=%3d sending step %2d to %5d\n",_sion_get_time()-lcommgroup->ts,
162  grank,lrank,step,lrank+blocksize);
163  MPI_Send(&step, 1, MPI_INT, lrank+blocksize, 1430, lComm);
164  }
165 
166  if(sion_filedesc->filenumber==0) fprintf(stderr,"sion_endof_transaction_mpi ts=%8.4fs on grank=%5d lrank=%3d end of transaction step=%2d\n",_sion_get_time()-lcommgroup->ts,
167  grank,lrank,step);
168 
169  DPRINTFP((1, "sion_endof_transaction_mpi", grank, "leave end of transaction of sid %d\n", sid));
170  /* */ DPRINTFTS(grank, "leave end of transaction of sid");
171  return(rc);
172 }
173 
174 
175 /* end of ifdef MPI */
176 #endif
void * _sion_vcdtovcon(int sid)
Definition: sion_fd.c:53
int _sion_vcdtype(int sid)
Definition: sion_fd.c:58
#define SION_FILEDESCRIPTOR
Definition: sion_fd.h:17
char * _sion_getenv(const char *name)
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
double _sion_get_time(void)
Returns the current time as a double.
Definition: sion_printts.c:70
Sion Time Stamp Header.
Sion File Descriptor Structure.
Definition: sion_filedesc.h:79