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

5
6
7

#ifdef USE_MPI

8
9
10
#include <ctype.h>
#include <yaxt.h>

11
#include "file.h"
12
13
#include "cdi_int.h"
#include "namespace.h"
14

15
#include "pio.h"
Deike Kleberg's avatar
Deike Kleberg committed
16
17
#include "cdi.h"
#include "pio_comm.h"
Deike Kleberg's avatar
Deike Kleberg committed
18
#include "pio_impl.h"
19
20
#include "pio_interface.h"
#include "pio_rpc.h"
21
#include "pio_util.h"
Deike Kleberg's avatar
Deike Kleberg committed
22

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

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

33
34
35
enum {
  tagKey = 100,
};
36

Deike Kleberg's avatar
Deike Kleberg committed
37
38
39
40
41
42
43
double accumProbe   = 0.0;
double accumRecv    = 0.0;
double accumSend    = 0.0;
double accumSuspend = 0.0;
double accumWait    = 0.0;
double accumWrite   = 0.0;

44
45
char *token = "%";

46
/***************************************************************/
Deike Kleberg's avatar
Deike Kleberg committed
47

48
int encodeFileOpTag(int ID, int sc)
Deike Kleberg's avatar
Deike Kleberg committed
49
{
50
  return ID * tagKey + sc;
Deike Kleberg's avatar
Deike Kleberg committed
51
52
53
54
}

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

55
struct fileOpTag decodeFileOpTag(int tag)
Deike Kleberg's avatar
Deike Kleberg committed
56
{
57
  struct fileOpTag rtag;
Deike Kleberg's avatar
Deike Kleberg committed
58

59
60
  rtag.id = tag / tagKey;
  rtag.command = tag % tagKey;
Deike Kleberg's avatar
Deike Kleberg committed
61
62
63
64
65
66

  return rtag;
}

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

Thomas Jahns's avatar
Thomas Jahns committed
67
68
size_t
cdiPioFileWrite(int fileID, const void *restrict buffer, size_t len, int tsID)
Deike Kleberg's avatar
Deike Kleberg committed
69
{
Thomas Jahns's avatar
Thomas Jahns committed
70
  size_t iret = CDI_UNDEFID;
Deike Kleberg's avatar
Deike Kleberg committed
71

Deike Kleberg's avatar
Deike Kleberg committed
72
  switch ( commInqIOMode ())
Deike Kleberg's avatar
Deike Kleberg committed
73
    {
Deike Kleberg's avatar
Deike Kleberg committed
74
    case PIO_MPI:
Deike Kleberg's avatar
Deike Kleberg committed
75
      iret = fwMPINONB ( fileID, tsID, buffer, len );
Deike Kleberg's avatar
Deike Kleberg committed
76
      break;
Deike Kleberg's avatar
Deike Kleberg committed
77
#ifndef _SX
Deike Kleberg's avatar
Deike Kleberg committed
78
    case PIO_ASYNCH:
79
#endif
80
81
82
    case PIO_WRITER:
      iret = pioSendWrite(fileID, tsID, buffer, len);
      break;
Deike Kleberg's avatar
Deike Kleberg committed
83
    case PIO_FPGUARD:
Deike Kleberg's avatar
Deike Kleberg committed
84
      iret = fwPOSIXFPGUARDSENDRECV ( fileID, tsID, buffer, len );
85
      break;
Deike Kleberg's avatar
Deike Kleberg committed
86
87
88
89
90
91
92
93
94
    }

  return iret;
}

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

int pioFileClose ( int id )
{
Thomas Jahns's avatar
Thomas Jahns committed
95
  int iret = CDI_UNDEFID;
Deike Kleberg's avatar
Deike Kleberg committed
96
  switch ( commInqIOMode ())
Deike Kleberg's avatar
Deike Kleberg committed
97
    {
Deike Kleberg's avatar
Deike Kleberg committed
98
    case PIO_MPI:
99
      iret = fcMPINONB ( id );
Deike Kleberg's avatar
Deike Kleberg committed
100
      break;
Deike Kleberg's avatar
Deike Kleberg committed
101
#ifndef _SX
Deike Kleberg's avatar
Deike Kleberg committed
102
    case PIO_ASYNCH:
Deike Kleberg's avatar
Deike Kleberg committed
103
#endif
104
105
106
    case PIO_WRITER:
      iret = pioSendClose(id);
      break;
Deike Kleberg's avatar
Deike Kleberg committed
107
    case PIO_FPGUARD:
108
109
      iret = fcPOSIXFPGUARDSENDRECV ( id );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
110
111
112
113
114
115
116
    }

  return iret;
}

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

117
int pioFileOpen(const char *filename, const char *mode)
Deike Kleberg's avatar
Deike Kleberg committed
118
{
Thomas Jahns's avatar
Thomas Jahns committed
119
  int iret = CDI_UNDEFID;
120

121
122
123
  if ((mode[0] != 'w' && mode[0] != 'W') || mode[0] == 0 || mode[1] != 0)
    xabort("Unsupported mode \"%s\" in parallel file open.", mode);

Deike Kleberg's avatar
Deike Kleberg committed
124
  switch ( commInqIOMode ())
Deike Kleberg's avatar
Deike Kleberg committed
125
    {
Deike Kleberg's avatar
Deike Kleberg committed
126
    case PIO_MPI:
127
      iret = fowMPINONB ( filename );
Deike Kleberg's avatar
Deike Kleberg committed
128
      break;
Deike Kleberg's avatar
Deike Kleberg committed
129
#ifndef _SX
Deike Kleberg's avatar
Deike Kleberg committed
130
    case PIO_ASYNCH:
Deike Kleberg's avatar
Deike Kleberg committed
131
#endif
132
133
134
    case PIO_WRITER:
      iret = pioSendOpen(filename);
      break;
Deike Kleberg's avatar
Deike Kleberg committed
135
    case PIO_FPGUARD:
136
137
      iret = fowPOSIXFPGUARDSENDRECV ( filename );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
138
    }
139

Deike Kleberg's avatar
Deike Kleberg committed
140
141
  return iret;
}
142
143
144

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

145
146
int
cdiPioStreamOpen(const char *filename, const char *filemode,
147
148
                 int filetype, stream_t *streamptr,
                 int recordBufIsToBeCreated)
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
{
  if ( tolower ( * filemode ) == 'w' )
    {
      statusCode nspStatus = namespaceInqResStatus ();
      switch ( nspStatus )
        {
        case STAGE_DEFINITION:
          break;
        case STAGE_TIMELOOP:
          pioBufferFuncCall(STREAMOPEN, 2, filename, filetype);
          break;
        case STAGE_CLEANUP:
          xabort ( "TRANSITION TO IO PROCESSES ALREADY FINISHED." );
          break;
        default:
          xabort ( "INTERNAL ERROR" );
        }
    }
  else
    Error("cdiPIO read support not implemented");
  return 1;
}

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

174
void backendInit ( void )
175
{
Deike Kleberg's avatar
Deike Kleberg committed
176
  int IOMode = commInqIOMode ();
177

Deike Kleberg's avatar
Deike Kleberg committed
178
  commDefCommNode ();
179

Deike Kleberg's avatar
Deike Kleberg committed
180
  xassert ( IOMode != PIO_NONE  || commInqSizeNode () == 1 );
181

Deike Kleberg's avatar
Deike Kleberg committed
182
  switch ( IOMode )
Deike Kleberg's avatar
Deike Kleberg committed
183
    {
184
    case PIO_NONE:
185
      commDefCommColl ( 1 );
Deike Kleberg's avatar
Deike Kleberg committed
186
187
188
      commSendNodeInfo ();
      commRecvNodeMap ();
      commDefCommsIO ();
189
      break;
Deike Kleberg's avatar
Deike Kleberg committed
190
    case PIO_MPI:
191
      initMPINONB ();
Deike Kleberg's avatar
Deike Kleberg committed
192
      break;
Deike Kleberg's avatar
Deike Kleberg committed
193
#ifndef _SX
Deike Kleberg's avatar
Deike Kleberg committed
194
    case PIO_ASYNCH:
Deike Kleberg's avatar
Deike Kleberg committed
195
#endif
196
197
198
    case PIO_WRITER:
      pioSendInitialize();
      break;
Deike Kleberg's avatar
Deike Kleberg committed
199
    case PIO_FPGUARD:
200
      initPOSIXFPGUARDSENDRECV ();
201
      break;
Deike Kleberg's avatar
Deike Kleberg committed
202
203
204
205
206
    }
}

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

207
208
209
210
211
void backendCleanup ( void )
{
  int IOMode = commInqIOMode ();
  switch ( IOMode )
    {
212
213
    case PIO_NONE:
      break;
Deike Kleberg's avatar
Deike Kleberg committed
214
    case PIO_MPI:
215
216
      finalizeMPINONB ();
      break;
217
#ifndef _SX
Deike Kleberg's avatar
Deike Kleberg committed
218
    case PIO_ASYNCH:
219
220
221
#endif
    case PIO_WRITER:
      pioSendFinalize();
222
      break;
Deike Kleberg's avatar
Deike Kleberg committed
223
    case PIO_FPGUARD:
Deike Kleberg's avatar
Deike Kleberg committed
224
225
      finalizePOSIXFPGUARDSENDRECV ();
      break;
226
    default:
227
      xdebug("%s", " BACKENDCLEANUP FUNCTION NOT IMPLEMENTED YET.");
228
229
230
231
232
    }
}

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

233
void backendFinalize ( void )
Deike Kleberg's avatar
Deike Kleberg committed
234
{
235
236
  commDestroy ();
  MPI_Finalize ();
237
  exit ( EXIT_SUCCESS );
Deike Kleberg's avatar
Deike Kleberg committed
238
}
239
#endif
240
241
242
243
244
245
246
247
248
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */