pio.c 4.26 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
#include "pio.h"
Deike Kleberg's avatar
Deike Kleberg committed
9
10
#include "cdi.h"
#include "pio_comm.h"
Deike Kleberg's avatar
Deike Kleberg committed
11
#include "pio_impl.h"
12
#include "pio_util.h"
Deike Kleberg's avatar
Deike Kleberg committed
13

14
char * command2charP[6] = {"IO_Open_file", "IO_Close_file",
15
16
                           "IO_Get_fp","IO_Set_fp",
                           "IO_Send_buffer", "IO_Finalize"};
Deike Kleberg's avatar
Deike Kleberg committed
17

18
long initial_buffersize = 16 * 1024 * 1024;
19
/*  4 KB <= x < 256 MB */
20
/* 16 * 1024 * 1024; */
21
/* 16 * 1024; */
22
/* 4 * 1024; */
Deike Kleberg's avatar
Deike Kleberg committed
23

24
int tagKey = 100;
25
int maxErrorString = 100;
26

Deike Kleberg's avatar
Deike Kleberg committed
27
28
29
30
31
32
33
34
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;

35
36
char *token = "%";

37
/***************************************************************/
Deike Kleberg's avatar
Deike Kleberg committed
38

Deike Kleberg's avatar
Deike Kleberg committed
39
40
int setTag ( int ID, int sc )
{
41
  return ID * tagKey + sc;
Deike Kleberg's avatar
Deike Kleberg committed
42
43
44
45
}

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

Deike Kleberg's avatar
Deike Kleberg committed
46
tag_t * getTag ( int tag )
Deike Kleberg's avatar
Deike Kleberg committed
47
{
Deike Kleberg's avatar
Deike Kleberg committed
48
  tag_t *rtag;
Deike Kleberg's avatar
Deike Kleberg committed
49

Deike Kleberg's avatar
Deike Kleberg committed
50
  rtag = ( tag_t * ) xmalloc ( sizeof ( tag_t ));
51
52
  rtag->id = tag / tagKey;
  rtag->command = tag % tagKey;
Deike Kleberg's avatar
Deike Kleberg committed
53
54
55
56
57
58

  return rtag;
}

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

Deike Kleberg's avatar
Deike Kleberg committed
59
void ungetTag ( tag_t *rtag )
60
61
62
63
64
65
66
{
  free ( rtag );
  return;
}

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

Deike Kleberg's avatar
Deike Kleberg committed
67
size_t pioFileWrite ( int fileID, int tsID, const void *buffer, size_t len )
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:
Deike Kleberg's avatar
Deike Kleberg committed
78
      iret = fwPOSIXASYNCH ( fileID, tsID, buffer, len );
Deike Kleberg's avatar
Deike Kleberg committed
79
      break;
Deike Kleberg's avatar
Deike Kleberg committed
80
#endif      
Deike Kleberg's avatar
Deike Kleberg committed
81
    case PIO_FPGUARD:
Deike Kleberg's avatar
Deike Kleberg committed
82
      iret = fwPOSIXFPGUARDSENDRECV ( fileID, tsID, buffer, len );
83
      break;
Deike Kleberg's avatar
Deike Kleberg committed
84
    case PIO_WRITER:
Deike Kleberg's avatar
Deike Kleberg committed
85
      iret = fwPOSIXNONB ( 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
105
      iret = fcPOSIXASYNCH ( id );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
106
#endif
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
    case PIO_WRITER:
111
112
      iret = fcPOSIXNONB ( id );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
113
114
115
116
117
118
119
120
121
    }

  return iret;
}

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

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

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
132
      iret = fowPOSIXASYNCH ( filename );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
133
#endif
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
    case PIO_WRITER:
138
139
      iret = fowPOSIXNONB ( filename );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
140
    }
141

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

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

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

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

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

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

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

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

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

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