pio.c 5.16 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;

47
48
char *token = "%";

49
/***************************************************************/
Deike Kleberg's avatar
Deike Kleberg committed
50

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

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

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

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

  return rtag;
}

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

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

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

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

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

  return iret;
}

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

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

  return iret;
}

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

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

Deike Kleberg's avatar
Deike Kleberg committed
159
  switch ( commInqIOMode ())
Deike Kleberg's avatar
Deike Kleberg committed
160
    {
161
162
    case PIO_MPI_NONB:
      iret = fowMPINONB ( filename );
Deike Kleberg's avatar
Deike Kleberg committed
163
      break;
Deike Kleberg's avatar
Deike Kleberg committed
164
#ifndef _SX
Deike Kleberg's avatar
Deike Kleberg committed
165
166
167
    case PIO_POSIX_ASYNCH:
      iret = fowPOSIXASYNCH ( filename );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
168
#endif
169
170
171
    case PIO_POSIX_FPGUARD_SENDRECV:
      iret = fowPOSIXFPGUARDSENDRECV ( filename );
      break;
172
      
173
/*
174
175
176
    case PIO_POSIX_FPGUARD_THREAD:
      iret = fowPOSIXFPGUARDTHREAD ( filename );
      break;
177
178
*/
/*
179
180
181
    case PIO_POSIX_FPGUARD_THREAD_REFUSE:
      iret = fowPOSIXFPGUARDTHREADREFUSE ( filename );
      break;
182
*/
183
184
185
    case PIO_POSIX_NONB:
      iret = fowPOSIXNONB ( filename );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
186
    }
187

Deike Kleberg's avatar
Deike Kleberg committed
188
189
  return iret;
}
190
191
192
193
#endif

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

194
void backendInit ( void )
195
{
Deike Kleberg's avatar
Deike Kleberg committed
196
  int IOMode = commInqIOMode ();
197

Deike Kleberg's avatar
Deike Kleberg committed
198
#ifdef USE_MPI
Deike Kleberg's avatar
Deike Kleberg committed
199
  commDefCommNode ();
200

Deike Kleberg's avatar
Deike Kleberg committed
201
  if ( IOMode == PIO_NONE  && commInqSizeNode () != 1 )
202
    xabort ( "PIOTYPE, NNODES: not a valid combination" );
Deike Kleberg's avatar
Deike Kleberg committed
203
 
204

Deike Kleberg's avatar
Deike Kleberg committed
205
  switch ( IOMode )
Deike Kleberg's avatar
Deike Kleberg committed
206
    {
207
    case PIO_NONE:
208
      commDefCommColl ( 1 );
Deike Kleberg's avatar
Deike Kleberg committed
209
210
211
      commSendNodeInfo ();
      commRecvNodeMap ();
      commDefCommsIO ();
212
      break;
213
    case PIO_MPI_NONB:
214
      initMPINONB ();
Deike Kleberg's avatar
Deike Kleberg committed
215
      break;
Deike Kleberg's avatar
Deike Kleberg committed
216
#ifndef _SX
Deike Kleberg's avatar
Deike Kleberg committed
217
    case PIO_POSIX_ASYNCH:
218
      initPOSIXASYNCH ();
Deike Kleberg's avatar
Deike Kleberg committed
219
      break;
Deike Kleberg's avatar
Deike Kleberg committed
220
#endif
221
222
    case PIO_POSIX_FPGUARD_SENDRECV:
      initPOSIXFPGUARDSENDRECV ();
223
      break;
224
      
225
/*
226
    case PIO_POSIX_FPGUARD_THREAD:
227
      collectingData = initPOSIXFPGUARDTHREAD ();
228
      break;
229
230
*/
/*
231
    case PIO_POSIX_FPGUARD_THREAD_REFUSE:
232
      collectingData = initPOSIXFPGUARDTHREADREFUSE ();
233
      break;
234
*/
Deike Kleberg's avatar
Deike Kleberg committed
235
    case PIO_POSIX_NONB:
Deike Kleberg's avatar
Deike Kleberg committed
236
      initPOSIXNONB ();
237
      break;
Deike Kleberg's avatar
Deike Kleberg committed
238
    }
239
#endif
Deike Kleberg's avatar
Deike Kleberg committed
240
241
242
243
}

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

244
void backendFinalize ( void )
Deike Kleberg's avatar
Deike Kleberg committed
245
{
246
#ifdef USE_MPI
247
248
249
250
251
252
253
254
255
  /*
    switch ( pioinfo->type )
    {

    case PIO_POSIX_FPGUARD_THREAD:
      finalizePOSIXFPGUARDTHREAD ();
      break;
    }
  */
256
257
258
  commDestroy ();
  MPI_Finalize ();
  exit ( 0 );
259
#endif
Deike Kleberg's avatar
Deike Kleberg committed
260
}
261
262
263
264
265
266
267
268
269
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */