pio.c 5.65 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
void backendInit ( void )
205
206
{
  int collectingData = 1;
Deike Kleberg's avatar
Deike Kleberg committed
207
  int IOModus = commInqIOModus ();
208

Deike Kleberg's avatar
Deike Kleberg committed
209
#ifdef USE_MPI
Deike Kleberg's avatar
Deike Kleberg committed
210
  commDefCommNode ();
211

Deike Kleberg's avatar
Deike Kleberg committed
212
  if (( IOModus == PIO_NONE ) && ( commInqSizeNode () != 1 ))
213
    xabort ( "PIOTYPE, NNODES: not a valid combination" );
Deike Kleberg's avatar
Deike Kleberg committed
214
 
215

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

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

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

268
void backendFinalize ()
Deike Kleberg's avatar
Deike Kleberg committed
269
{
270
#ifdef USE_MPI
Deike Kleberg's avatar
Deike Kleberg committed
271
  /*
272
273
  switch ( pioinfo->type )
    {
Deike Kleberg's avatar
Deike Kleberg committed
274

275
276
277
    case PIO_POSIX_FPGUARD_THREAD:
      finalizePOSIXFPGUARDTHREAD ();
      break;
Deike Kleberg's avatar
Deike Kleberg committed
278

279
280
    }

281
  if ( pioinfo->collectorComm != MPI_COMM_NULL )
Deike Kleberg's avatar
Deike Kleberg committed
282
    xmpi ( MPI_Comm_free ( &( pioinfo->collectorComm )));
283
284

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

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