pio.c 4.2 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
    {
73
    case PIO_MPI_NONB:
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_POSIX_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      
81
    case PIO_POSIX_FPGUARD_SENDRECV:
Deike Kleberg's avatar
Deike Kleberg committed
82
      iret = fwPOSIXFPGUARDSENDRECV ( fileID, tsID, buffer, len );
83
84
      break;
    case PIO_POSIX_NONB:
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
    {
99
100
    case PIO_MPI_NONB:
      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
104
105
    case PIO_POSIX_ASYNCH:
      iret = fcPOSIXASYNCH ( id );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
106
#endif
107
108
109
110
111
112
    case PIO_POSIX_FPGUARD_SENDRECV:
      iret = fcPOSIXFPGUARDSENDRECV ( id );
      break;
    case PIO_POSIX_NONB:
      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
    {
126
127
    case PIO_MPI_NONB:
      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
131
132
    case PIO_POSIX_ASYNCH:
      iret = fowPOSIXASYNCH ( filename );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
133
#endif
134
135
136
137
138
139
    case PIO_POSIX_FPGUARD_SENDRECV:
      iret = fowPOSIXFPGUARDSENDRECV ( filename );
      break;
    case PIO_POSIX_NONB:
      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
  if ( IOMode == PIO_NONE  && commInqSizeNode () != 1 )
154
    xabort ( "PIOTYPE, NNODES: not a valid combination" );
Deike Kleberg's avatar
Deike Kleberg committed
155
 
156

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

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

184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
void backendCleanup ( void )
{
  int IOMode = commInqIOMode ();
  switch ( IOMode )
    {
    case PIO_MPI_NONB:
      finalizeMPINONB ();
      break;
    default:
      xdebug ( " backendCleanup function not implemented yet." );
    }
}

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

199
void backendFinalize ( void )
Deike Kleberg's avatar
Deike Kleberg committed
200
{
201
202
203
  commDestroy ();
  MPI_Finalize ();
  exit ( 0 );
Deike Kleberg's avatar
Deike Kleberg committed
204
}
205
#endif
206
207
208
209
210
211
212
213
214
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */