pio.c 3.61 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
char *token = "%";

34
/***************************************************************/
Deike Kleberg's avatar
Deike Kleberg committed
35

Thomas Jahns's avatar
Thomas Jahns committed
36
37
size_t
cdiPioFileWrite(int fileID, const void *restrict buffer, size_t len, int tsID)
Deike Kleberg's avatar
Deike Kleberg committed
38
{
39
  size_t iret = 0;
Deike Kleberg's avatar
Deike Kleberg committed
40

Deike Kleberg's avatar
Deike Kleberg committed
41
  switch ( commInqIOMode ())
Deike Kleberg's avatar
Deike Kleberg committed
42
    {
Deike Kleberg's avatar
Deike Kleberg committed
43
    case PIO_MPI:
Deike Kleberg's avatar
Deike Kleberg committed
44
      iret = fwMPINONB ( fileID, tsID, buffer, len );
Deike Kleberg's avatar
Deike Kleberg committed
45
      break;
Deike Kleberg's avatar
Deike Kleberg committed
46
#ifndef _SX
Deike Kleberg's avatar
Deike Kleberg committed
47
    case PIO_ASYNCH:
48
#endif
49
50
51
    case PIO_WRITER:
      iret = pioSendWrite(fileID, tsID, buffer, len);
      break;
Deike Kleberg's avatar
Deike Kleberg committed
52
    case PIO_FPGUARD:
Deike Kleberg's avatar
Deike Kleberg committed
53
      iret = fwPOSIXFPGUARDSENDRECV ( fileID, tsID, buffer, len );
54
      break;
Deike Kleberg's avatar
Deike Kleberg committed
55
56
57
58
59
60
61
62
63
    }

  return iret;
}

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

int pioFileClose ( int id )
{
Thomas Jahns's avatar
Thomas Jahns committed
64
  int iret = CDI_UNDEFID;
Deike Kleberg's avatar
Deike Kleberg committed
65
  switch ( commInqIOMode ())
Deike Kleberg's avatar
Deike Kleberg committed
66
    {
Deike Kleberg's avatar
Deike Kleberg committed
67
    case PIO_MPI:
68
      iret = fcMPINONB ( id );
Deike Kleberg's avatar
Deike Kleberg committed
69
      break;
Deike Kleberg's avatar
Deike Kleberg committed
70
#ifndef _SX
Deike Kleberg's avatar
Deike Kleberg committed
71
    case PIO_ASYNCH:
Deike Kleberg's avatar
Deike Kleberg committed
72
#endif
73
74
75
    case PIO_WRITER:
      iret = pioSendClose(id);
      break;
Deike Kleberg's avatar
Deike Kleberg committed
76
    case PIO_FPGUARD:
77
78
      iret = fcPOSIXFPGUARDSENDRECV ( id );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
79
80
81
82
83
84
85
    }

  return iret;
}

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

86
int pioFileOpen(const char *filename, const char *mode)
Deike Kleberg's avatar
Deike Kleberg committed
87
{
Thomas Jahns's avatar
Thomas Jahns committed
88
  int iret = CDI_UNDEFID;
89

90
91
92
  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
93
  switch ( commInqIOMode ())
Deike Kleberg's avatar
Deike Kleberg committed
94
    {
Deike Kleberg's avatar
Deike Kleberg committed
95
    case PIO_MPI:
96
      iret = fowMPINONB ( filename );
Deike Kleberg's avatar
Deike Kleberg committed
97
      break;
Deike Kleberg's avatar
Deike Kleberg committed
98
#ifndef _SX
Deike Kleberg's avatar
Deike Kleberg committed
99
    case PIO_ASYNCH:
Deike Kleberg's avatar
Deike Kleberg committed
100
#endif
101
102
103
    case PIO_WRITER:
      iret = pioSendOpen(filename);
      break;
Deike Kleberg's avatar
Deike Kleberg committed
104
    case PIO_FPGUARD:
105
106
      iret = fowPOSIXFPGUARDSENDRECV ( filename );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
107
    }
108

Deike Kleberg's avatar
Deike Kleberg committed
109
110
  return iret;
}
111
112
113

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

114
void cdiPioFileWritingInit(void (*postCommSetupActions)(void))
115
{
Deike Kleberg's avatar
Deike Kleberg committed
116
  int IOMode = commInqIOMode ();
117

Deike Kleberg's avatar
Deike Kleberg committed
118
  commDefCommNode ();
119

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

Deike Kleberg's avatar
Deike Kleberg committed
122
  switch ( IOMode )
Deike Kleberg's avatar
Deike Kleberg committed
123
    {
124
    case PIO_NONE:
125
      commDefCommColl ( 1 );
Deike Kleberg's avatar
Deike Kleberg committed
126
127
128
      commSendNodeInfo ();
      commRecvNodeMap ();
      commDefCommsIO ();
129
      break;
Deike Kleberg's avatar
Deike Kleberg committed
130
    case PIO_MPI:
131
      initMPINONB(postCommSetupActions);
Deike Kleberg's avatar
Deike Kleberg committed
132
      break;
Deike Kleberg's avatar
Deike Kleberg committed
133
#ifndef _SX
Deike Kleberg's avatar
Deike Kleberg committed
134
    case PIO_ASYNCH:
Deike Kleberg's avatar
Deike Kleberg committed
135
#endif
136
    case PIO_WRITER:
137
      pioSendInitialize(postCommSetupActions);
138
      break;
Deike Kleberg's avatar
Deike Kleberg committed
139
    case PIO_FPGUARD:
140
      initPOSIXFPGUARDSENDRECV(postCommSetupActions);
141
      break;
Deike Kleberg's avatar
Deike Kleberg committed
142
143
144
145
146
    }
}

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

147
void cdiPioFileWritingFinalize(void)
148
149
150
151
{
  int IOMode = commInqIOMode ();
  switch ( IOMode )
    {
152
153
    case PIO_NONE:
      break;
Deike Kleberg's avatar
Deike Kleberg committed
154
    case PIO_MPI:
155
156
      finalizeMPINONB ();
      break;
157
#ifndef _SX
Deike Kleberg's avatar
Deike Kleberg committed
158
    case PIO_ASYNCH:
159
160
161
#endif
    case PIO_WRITER:
      pioSendFinalize();
162
      break;
Deike Kleberg's avatar
Deike Kleberg committed
163
    case PIO_FPGUARD:
Deike Kleberg's avatar
Deike Kleberg committed
164
165
      finalizePOSIXFPGUARDSENDRECV ();
      break;
166
    default:
167
      xdebug("%s", " BACKENDCLEANUP FUNCTION NOT IMPLEMENTED YET.");
168
169
170
171
172
    }
}

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

173
174
175
176
177
178
179
180
181
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */