pio.c 5.8 KB
Newer Older
1
#ifdef HAVE_CONFIG_H
Deike Kleberg's avatar
Deike Kleberg committed
2
#include "config.h"
3
4
#endif

Deike Kleberg's avatar
Deike Kleberg committed
5
6
7
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
Deike Kleberg's avatar
Deike Kleberg committed
8
#include <string.h>
9
#include <unistd.h>
Deike Kleberg's avatar
Deike Kleberg committed
10

Deike Kleberg's avatar
Deike Kleberg committed
11
12
#include <assert.h>

13
#include "pio.h"
Deike Kleberg's avatar
Deike Kleberg committed
14
#include "cdi.h"
15
16
#include "pio_util.h"

17
#ifdef USE_MPI
Deike Kleberg's avatar
Deike Kleberg committed
18
#include "pio_comm.h"
Deike Kleberg's avatar
Deike Kleberg committed
19
#include "pio_impl.h"
Deike Kleberg's avatar
Deike Kleberg committed
20
21
#endif

22
#ifdef USE_MPI
Deike Kleberg's avatar
Deike Kleberg committed
23

24
char * command2charP[6] = {"IO_Open_file", "IO_Close_file",
25
26
                           "IO_Get_fp","IO_Set_fp",
                           "IO_Send_buffer", "IO_Finalize"};
Deike Kleberg's avatar
Deike Kleberg committed
27

28
long initial_buffersize = 16 * 1024 * 1024;
29
/*  4 KB <= x < 256 MB */
30
/* 16 * 1024 * 1024; */
31
/* 16 * 1024; */
32
/* 4 * 1024; */
Deike Kleberg's avatar
Deike Kleberg committed
33

Deike Kleberg's avatar
Deike Kleberg committed
34
int maxPtype = 4;
35
int maxNnodes  = 249;
36
int tagKey = 100;
37
int maxErrorString = 100;
38

Deike Kleberg's avatar
Deike Kleberg committed
39
40
41
42
43
44
45
46
double startTime;
double accumProbe   = 0.0;
double accumRecv    = 0.0;
double accumSend    = 0.0;
double accumSuspend = 0.0;
double accumWait    = 0.0;
double accumWrite   = 0.0;

Deike Kleberg's avatar
Deike Kleberg committed
47
pioInfo * pioinfo;
Deike Kleberg's avatar
Deike Kleberg committed
48

49
50
char *token = "%";

51
/***************************************************************/
Deike Kleberg's avatar
Deike Kleberg committed
52

Deike Kleberg's avatar
Deike Kleberg committed
53
54
int setTag ( int ID, int sc )
{
55
  return ID * tagKey + sc;
Deike Kleberg's avatar
Deike Kleberg committed
56
57
58
59
}

/***************************************************************/

Deike Kleberg's avatar
Deike Kleberg committed
60
tag_t * getTag ( int tag )
Deike Kleberg's avatar
Deike Kleberg committed
61
{
Deike Kleberg's avatar
Deike Kleberg committed
62
  tag_t *rtag;
Deike Kleberg's avatar
Deike Kleberg committed
63

Deike Kleberg's avatar
Deike Kleberg committed
64
  rtag = ( tag_t * ) xmalloc ( sizeof ( tag_t ));
65
66
  rtag->id = tag / tagKey;
  rtag->command = tag % tagKey;
Deike Kleberg's avatar
Deike Kleberg committed
67
68
69
70
71
72

  return rtag;
}

/***************************************************************/

Deike Kleberg's avatar
Deike Kleberg committed
73
void ungetTag ( tag_t *rtag )
74
75
76
77
78
79
80
{
  free ( rtag );
  return;
}

/***************************************************************/

Deike Kleberg's avatar
Deike Kleberg committed
81
size_t pioFileWrite ( int fileID, int tsID, const void *buffer, size_t len )
Deike Kleberg's avatar
Deike Kleberg committed
82
{
Thomas Jahns's avatar
Thomas Jahns committed
83
  size_t iret = CDI_UNDEFID;
Deike Kleberg's avatar
Deike Kleberg committed
84

Deike Kleberg's avatar
Deike Kleberg committed
85
  switch ( commInqIOModus ())
Deike Kleberg's avatar
Deike Kleberg committed
86
    {
87
    case PIO_MPI_NONB:
Deike Kleberg's avatar
Deike Kleberg committed
88
      iret = fwMPINONB ( fileID, tsID, buffer, len );
Deike Kleberg's avatar
Deike Kleberg committed
89
      break;
Deike Kleberg's avatar
Deike Kleberg committed
90
#ifndef _SX
91
/*
Deike Kleberg's avatar
Deike Kleberg committed
92
    case PIO_POSIX_ASYNCH:
Deike Kleberg's avatar
Deike Kleberg committed
93
      iret = fwPOSIXASYNCH ( fileID, tsID, buffer, len );
Deike Kleberg's avatar
Deike Kleberg committed
94
      break;
95
*/
Deike Kleberg's avatar
Deike Kleberg committed
96
#endif
97
    case PIO_POSIX_FPGUARD_SENDRECV:
Deike Kleberg's avatar
Deike Kleberg committed
98
      iret = fwPOSIXFPGUARDSENDRECV ( fileID, tsID, buffer, len );
99
      break;
100
/*
101
    case PIO_POSIX_FPGUARD_THREAD:
Deike Kleberg's avatar
Deike Kleberg committed
102
      iret = fwPOSIXFPGUARDTHREAD ( fileID, tsID, buffer, len );
103
      break;
104
105
*/
/*
106
    case PIO_POSIX_FPGUARD_THREAD_REFUSE:
Deike Kleberg's avatar
Deike Kleberg committed
107
      iret = fwPOSIXFPGUARDTHREADREFUSE ( fileID, tsID, buffer, len );
108
      break;
109
110
*/
/*
111
    case PIO_POSIX_NONB:
Deike Kleberg's avatar
Deike Kleberg committed
112
      iret = fwPOSIXNONB ( fileID, tsID, buffer, len );
113
      break;
114
*/
Deike Kleberg's avatar
Deike Kleberg committed
115
116
117
118
119
120
121
122
123
    }

  return iret;
}

/***************************************************************/

int pioFileClose ( int id )
{
Thomas Jahns's avatar
Thomas Jahns committed
124
  int iret = CDI_UNDEFID;
Deike Kleberg's avatar
Deike Kleberg committed
125
  switch ( commInqIOModus ())
Deike Kleberg's avatar
Deike Kleberg committed
126
    {
127
128
    case PIO_MPI_NONB:
      iret = fcMPINONB ( id );
Deike Kleberg's avatar
Deike Kleberg committed
129
      break;
Deike Kleberg's avatar
Deike Kleberg committed
130
#ifndef _SX
131
/*
Deike Kleberg's avatar
Deike Kleberg committed
132
133
134
    case PIO_POSIX_ASYNCH:
      iret = fcPOSIXASYNCH ( id );
      break;
135
*/
Deike Kleberg's avatar
Deike Kleberg committed
136
#endif
137
138
139
    case PIO_POSIX_FPGUARD_SENDRECV:
      iret = fcPOSIXFPGUARDSENDRECV ( id );
      break;
140
/*
141
142
143
    case PIO_POSIX_FPGUARD_THREAD:
      iret = fcPOSIXFPGUARDTHREAD ( id );
      break;
144
145
*/
/*
146
147
148
    case PIO_POSIX_FPGUARD_THREAD_REFUSE:
      iret = fcPOSIXFPGUARDTHREADREFUSE ( id );
      break;
149
150
*/
/*
151
152
153
    case PIO_POSIX_NONB:
      iret = fcPOSIXNONB ( id );
      break;
154
*/
Deike Kleberg's avatar
Deike Kleberg committed
155
156
157
158
159
160
161
162
163
    }

  return iret;
}

/***************************************************************/

int pioFileOpenW ( const char *filename )
{
Thomas Jahns's avatar
Thomas Jahns committed
164
  int iret = CDI_UNDEFID;
165

Deike Kleberg's avatar
Deike Kleberg committed
166
  switch ( commInqIOModus ())
Deike Kleberg's avatar
Deike Kleberg committed
167
    {
168
169
    case PIO_MPI_NONB:
      iret = fowMPINONB ( filename );
Deike Kleberg's avatar
Deike Kleberg committed
170
      break;
Deike Kleberg's avatar
Deike Kleberg committed
171
#ifndef _SX
172
/*
Deike Kleberg's avatar
Deike Kleberg committed
173
174
175
    case PIO_POSIX_ASYNCH:
      iret = fowPOSIXASYNCH ( filename );
      break;
176
*/
Deike Kleberg's avatar
Deike Kleberg committed
177
#endif
178
179
180
    case PIO_POSIX_FPGUARD_SENDRECV:
      iret = fowPOSIXFPGUARDSENDRECV ( filename );
      break;
181
/*
182
183
184
    case PIO_POSIX_FPGUARD_THREAD:
      iret = fowPOSIXFPGUARDTHREAD ( filename );
      break;
185
186
*/
/*
187
188
189
    case PIO_POSIX_FPGUARD_THREAD_REFUSE:
      iret = fowPOSIXFPGUARDTHREADREFUSE ( filename );
      break;
190
191
*/
/*
192
193
194
    case PIO_POSIX_NONB:
      iret = fowPOSIXNONB ( filename );
      break;
195
*/
Deike Kleberg's avatar
Deike Kleberg committed
196
    }
197

Deike Kleberg's avatar
Deike Kleberg committed
198
199
  return iret;
}
200
201
202
203
#endif

/***************************************************************/

204
MPI_Comm backendInit ( int ptype, MPI_Comm comm, int *color, int *nnodes )
205
{
Deike Kleberg's avatar
Deike Kleberg committed
206
  int size, rank;
207
  int collectingData = 1;
Deike Kleberg's avatar
Deike Kleberg committed
208
  int IOModus = commInqIOModus ();
209

Deike Kleberg's avatar
Deike Kleberg committed
210
#ifdef USE_MPI
Deike Kleberg's avatar
Deike Kleberg committed
211
212
  xmpi ( MPI_Comm_size ( comm, &size ));
  xmpi ( MPI_Comm_rank ( comm, &rank ));
213

Deike Kleberg's avatar
Deike Kleberg committed
214
  commDefCommNode ();
215

Deike Kleberg's avatar
Deike Kleberg committed
216
  if (( IOModus == PIO_NONE ) && ( commInqNNodes () != size ))
217
    xabort ( "PIOTYPE, NNODES: not a valid combination" );
Deike Kleberg's avatar
Deike Kleberg committed
218
 
219

Deike Kleberg's avatar
Deike Kleberg committed
220
  switch ( IOModus )
Deike Kleberg's avatar
Deike Kleberg committed
221
    {
Deike Kleberg's avatar
Deike Kleberg committed
222
      /*
223
    case PIO_NONE:
Deike Kleberg's avatar
Deike Kleberg committed
224
      xmpi ( MPI_Comm_dup ( pioinfo->comm, &( pioinfo->collectorComm )));
225
      collectingData = 1;
226
      break;
Deike Kleberg's avatar
Deike Kleberg committed
227
      */
228
    case PIO_MPI_NONB:
229
      collectingData = initMPINONB ();
Deike Kleberg's avatar
Deike Kleberg committed
230
      break;
Deike Kleberg's avatar
Deike Kleberg committed
231
#ifndef _SX
232
/*
Deike Kleberg's avatar
Deike Kleberg committed
233
    case PIO_POSIX_ASYNCH:
234
      collectingData = initPOSIXASYNCH ();
Deike Kleberg's avatar
Deike Kleberg committed
235
      break;
236
*/
Deike Kleberg's avatar
Deike Kleberg committed
237
#endif
Deike Kleberg's avatar
Deike Kleberg committed
238
239
      /*
        case PIO_POSIX_FPGUARD_SENDRECV:
240
      collectingData = initPOSIXFPGUARDSENDRECV ();
241
      break;
Deike Kleberg's avatar
Deike Kleberg committed
242
      */
243
/*
244
    case PIO_POSIX_FPGUARD_THREAD:
245
      collectingData = initPOSIXFPGUARDTHREAD ();
246
      break;
247
248
*/
/*
249
    case PIO_POSIX_FPGUARD_THREAD_REFUSE:
250
      collectingData = initPOSIXFPGUARDTHREADREFUSE ();
251
      break;
252
253
*/
/*
Deike Kleberg's avatar
Deike Kleberg committed
254
    case PIO_POSIX_NONB:
255
      collectingData = initPOSIXNONB ();
256
      break;
257
*/
Deike Kleberg's avatar
Deike Kleberg committed
258
    }
259
#endif
260
261

#ifdef USE_MPI
Deike Kleberg's avatar
Deike Kleberg committed
262
263
264
  // TODO: change interface! 
  assert ( pioinfo2 != NULL && pioinfo2->commColl != MPI_COMM_NULL );
  return pioinfo2->commColl;
265
266
267
#else
  return 0;
#endif
Deike Kleberg's avatar
Deike Kleberg committed
268
269
270
271
}

/***************************************************************/

272
void backendFinalize ()
Deike Kleberg's avatar
Deike Kleberg committed
273
{
274
#ifdef USE_MPI
Deike Kleberg's avatar
Deike Kleberg committed
275
  /*
276
277
  switch ( pioinfo->type )
    {
Deike Kleberg's avatar
Deike Kleberg committed
278

279
280
281
    case PIO_POSIX_FPGUARD_THREAD:
      finalizePOSIXFPGUARDTHREAD ();
      break;
Deike Kleberg's avatar
Deike Kleberg committed
282

283
284
    }

285
  if ( pioinfo->collectorComm != MPI_COMM_NULL )
Deike Kleberg's avatar
Deike Kleberg committed
286
    xmpi ( MPI_Comm_free ( &( pioinfo->collectorComm )));
287
288

  if ( pioinfo->comm != MPI_COMM_NULL )
Deike Kleberg's avatar
Deike Kleberg committed
289
    xmpi ( MPI_Comm_free ( &( pioinfo->comm )));
290

Deike Kleberg's avatar
Deike Kleberg committed
291
  free ( pioinfo );
Deike Kleberg's avatar
Deike Kleberg committed
292
*/
293
#endif
Deike Kleberg's avatar
Deike Kleberg committed
294
}
295
296
297
298
299
300
301
302
303
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */