pio.c 4.15 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
8
#include <ctype.h>
#include <yaxt.h>

9
#include "file.h"
10
11
#include "cdi_int.h"
#include "namespace.h"
12

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

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

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

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

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

43
44
char *token = "%";

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

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

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

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

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

  return rtag;
}

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

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

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

  return iret;
}

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

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

  return iret;
}

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

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

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

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

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

144
void cdiPioFileWritingInit(void (*postCommSetupActions)(void))
145
{
Deike Kleberg's avatar
Deike Kleberg committed
146
  int IOMode = commInqIOMode ();
147

Deike Kleberg's avatar
Deike Kleberg committed
148
  commDefCommNode ();
149

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

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

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

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

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

203
204
205
206
207
208
209
210
211
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */