pio.c 4.25 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
#include "cdi.h"
17
#include "cdipio.h"
Deike Kleberg's avatar
Deike Kleberg committed
18
#include "pio_comm.h"
Deike Kleberg's avatar
Deike Kleberg committed
19
#include "pio_impl.h"
20
21
#include "pio_interface.h"
#include "pio_rpc.h"
22
#include "pio_util.h"
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

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

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

45
46
char *token = "%";

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

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

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

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

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

  return rtag;
}

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

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

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

  return iret;
}

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

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

  return iret;
}

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

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

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

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

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

146
void backendInit(void (*postCommSetupActions)(void))
147
{
Deike Kleberg's avatar
Deike Kleberg committed
148
  int IOMode = commInqIOMode ();
149

Deike Kleberg's avatar
Deike Kleberg committed
150
  commDefCommNode ();
151

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

Deike Kleberg's avatar
Deike Kleberg committed
154
  switch ( IOMode )
Deike Kleberg's avatar
Deike Kleberg committed
155
    {
156
    case PIO_NONE:
157
      commDefCommColl ( 1 );
Deike Kleberg's avatar
Deike Kleberg committed
158
159
160
      commSendNodeInfo ();
      commRecvNodeMap ();
      commDefCommsIO ();
161
      break;
Deike Kleberg's avatar
Deike Kleberg committed
162
    case PIO_MPI:
163
      initMPINONB(postCommSetupActions);
Deike Kleberg's avatar
Deike Kleberg committed
164
      break;
Deike Kleberg's avatar
Deike Kleberg committed
165
#ifndef _SX
Deike Kleberg's avatar
Deike Kleberg committed
166
    case PIO_ASYNCH:
Deike Kleberg's avatar
Deike Kleberg committed
167
#endif
168
    case PIO_WRITER:
169
      pioSendInitialize(postCommSetupActions);
170
      break;
Deike Kleberg's avatar
Deike Kleberg committed
171
    case PIO_FPGUARD:
172
      initPOSIXFPGUARDSENDRECV(postCommSetupActions);
173
      break;
Deike Kleberg's avatar
Deike Kleberg committed
174
175
176
177
178
    }
}

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

179
180
181
182
183
void backendCleanup ( void )
{
  int IOMode = commInqIOMode ();
  switch ( IOMode )
    {
184
185
    case PIO_NONE:
      break;
Deike Kleberg's avatar
Deike Kleberg committed
186
    case PIO_MPI:
187
188
      finalizeMPINONB ();
      break;
189
#ifndef _SX
Deike Kleberg's avatar
Deike Kleberg committed
190
    case PIO_ASYNCH:
191
192
193
#endif
    case PIO_WRITER:
      pioSendFinalize();
194
      break;
Deike Kleberg's avatar
Deike Kleberg committed
195
    case PIO_FPGUARD:
Deike Kleberg's avatar
Deike Kleberg committed
196
197
      finalizePOSIXFPGUARDSENDRECV ();
      break;
198
    default:
199
      xdebug("%s", " BACKENDCLEANUP FUNCTION NOT IMPLEMENTED YET.");
200
201
202
203
204
    }
}

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

205
void backendFinalize ( void )
Deike Kleberg's avatar
Deike Kleberg committed
206
{
207
208
  commDestroy ();
  MPI_Finalize ();
209
  exit ( EXIT_SUCCESS );
Deike Kleberg's avatar
Deike Kleberg committed
210
}
211
#endif
212
213
214
215
216
217
218
219
220
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */