pio.c 3.57 KB
Newer Older
Deike Kleberg's avatar
Deike Kleberg committed
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef NOMPI

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

#include "mpi.h"

#include "cdi.h"
#include "pio.h"
#include "pio_impl.h"

13
bool ddebug = false;
Deike Kleberg's avatar
Deike Kleberg committed
14

Deike Kleberg's avatar
Deike Kleberg committed
15
16
long initial_buffer_size = 16 * 1024 * 1024; 
/* 16 * 1024 * 1024, 4 KB <= x < 256 MB */
Deike Kleberg's avatar
Deike Kleberg committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

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;

pioInfo *pioinfo;

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

void check_mpi ( int line, int iret )
{
  char error_string[MPI_MAX_ERROR_STRING+1];
  int len;

  if  ( iret != MPI_SUCCESS ) 
    {
      MPI_Error_string ( iret, error_string, &len ); 
      error_string[len] = '\0';
      fprintf ( stderr,"\nLine %8d MPI error %4d: %s\n\n", line, iret, 
		error_string ); 
    }

  return;
}

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

Deike Kleberg's avatar
Deike Kleberg committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
int setTag ( int ID, int sc )
{
  return ID * 1000 + sc;
}

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

rTag * getTag ( int tag )
{
  rTag *rtag;

  rtag = ( rTag * ) malloc ( sizeof ( rTag ));
  rtag->id = tag / 1000;
  rtag->command = tag % 1000;

  return rtag;
}

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

Deike Kleberg's avatar
Deike Kleberg committed
68
69
70
71
72
73
74
75
76
size_t pioFileWrite ( int id, int tsId, const void *buffer, size_t len )
{
  size_t iret;

  switch ( pioinfo->type )
    {
    case PIO_POSIX_FPGUARD_SENDRECV:
      iret = fwPOSIXFPGUARDSENDRECV ( id, tsId, buffer, len );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
77
78
79
    case PIO_POSIX_ASYNCH:
      iret = fwPOSIXASYNCH ( id, tsId, buffer, len );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
    }

  return iret;
}

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

int pioFileClose ( int id )
{
  int iret;
  
  switch ( pioinfo->type )
    {
    case PIO_POSIX_FPGUARD_SENDRECV:
      iret = fcPOSIXFPGUARDSENDRECV ( id );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
96
97
98
    case PIO_POSIX_ASYNCH:
      iret = fcPOSIXASYNCH ( id );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
    }

  return iret;
}

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

int pioFileOpenW ( const char *filename )
{
  int iret;
  
  switch ( pioinfo->type )
    {
    case PIO_POSIX_FPGUARD_SENDRECV:
      iret = fowPOSIXFPGUARDSENDRECV ( filename );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
115
116
117
    case PIO_POSIX_ASYNCH:
      iret = fowPOSIXASYNCH ( filename );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
    }
  
  return iret;
}

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

int pioInit ( int ptype, int comm, int *ncollectors )
{
  int collectingData;
  int size;

  pioinfo = ( pioInfo * ) malloc ( sizeof ( pioInfo ));

  pioinfo->type = ptype;
  pioinfo->comm  = ( MPI_Comm ) comm;
  MPI_Comm_rank ( pioinfo->comm, &( pioinfo->rank ));
  MPI_Comm_size ( pioinfo->comm, &( pioinfo->size ));

  if ( pioinfo->type == PIO_NONE && pioinfo->size != 1 )
    {
      fprintf ( stderr, 
		"PTYPE should be set to a parallel I/O type or npe should be 1." );
      fprintf ( stderr, "PTYPE = %d, npe = %d\n", 
		pioinfo->type , pioinfo->size );
      MPI_Abort ( pioinfo->comm, 1 );
    }

  if ( ddebug && pioinfo->rank == 0 )
    fprintf ( stdout, 
	      "pe%d in pioDefPtype(), ptype=%d, initial_buffer_size=%ld: init pioinfo ...\n", 
	      pioinfo->rank, pioinfo->type, initial_buffer_size );

  switch ( pioinfo->type )
    {
    case PIO_POSIX_FPGUARD_SENDRECV:
      collectingData = initPOSIXFPGUARDSENDRECV ( ncollectors );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
156
157
158
    case PIO_POSIX_ASYNCH:
      collectingData = initPOSIXASYNCH ( ncollectors );
      break;
Deike Kleberg's avatar
Deike Kleberg committed
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
    }

  return collectingData;
}

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

void pioFinalize ()
{
  free ( pioinfo );

  return;
}

#endif