Commit 6b948d09 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Move PIO-specific code from file operations.

parent ebd63c51
......@@ -19,13 +19,7 @@ size_t getpagesize(void);
#include "error.h"
#include "file.h"
#ifdef USE_MPI
#include "cdi.h"
#include "namespace.h"
#include "pio.h"
#include "pio_comm.h"
#include "pio_util.h"
#endif
#if ! defined(O_BINARY)
#define O_BINARY 0
......@@ -1068,6 +1062,13 @@ void fileSetBufferSize(int fileID, long buffersize)
* Open a file. Returns file ID, or -1 on error
*/
int fileOpen(const char *filename, const char *mode)
{
int (*myFileOpen)(const char *filename, const char *mode)
= namespaceSwitchGet(NSSWITCH_FILE_OPEN);
return myFileOpen(filename, mode);
}
int fileOpen_serial(const char *filename, const char *mode)
{
FILE *fp = NULL; /* file pointer (used for write) */
int fd = -1; /* file descriptor (used for read) */
......@@ -1076,11 +1077,6 @@ int fileOpen(const char *filename, const char *mode)
struct stat filestat;
bfile_t *fileptr = NULL;
#ifdef USE_MPI
if ( mode[0] == 'w' && commInqIOMode () != PIO_NONE )
return pioFileOpenW ( filename );
#endif
FILE_INIT();
fmode = tolower((int) mode[0]);
......@@ -1162,20 +1158,19 @@ int fileOpen(const char *filename, const char *mode)
* Close a file.
*/
int fileClose(int fileID)
{
int (*myFileClose)(int fileID)
= namespaceSwitchGet(NSSWITCH_FILE_CLOSE);
return myFileClose(fileID);
}
int fileClose_serial(int fileID)
{
char *name;
int ret;
char *fbtname[] = {"unknown", "standard", "mmap"};
char *ftname[] = {"unknown", "open", "fopen"};
bfile_t *fileptr;
fileptr = file_to_pointer(fileID);
#ifdef USE_MPI
if (((fileptr && fileptr->mode == 'w') || !fileptr)
&& commInqIOMode () != PIO_NONE )
return pioFileClose ( fileID );
#endif
bfile_t *fileptr = file_to_pointer(fileID);
if ( fileptr == NULL )
{
......
......@@ -25,7 +25,9 @@ int fileSetBufferType(int fileID, int type);
void fileSetBufferSize(int fileID, long buffersize);
int fileOpen(const char *filename, const char *mode);
int fileOpen_serial(const char *filename, const char *mode);
int fileClose(int fileID);
int fileClose_serial(int fileID);
char *fileInqName(int fileID);
int fileInqMode(int fileID);
......
......@@ -8,6 +8,7 @@
#include "serialize.h"
#include "error.h"
#include "cdf_int.h"
#include "file.h"
static int nNamespaces = 1;
static int activeNamespace = 0;
......@@ -23,6 +24,8 @@ static int activeNamespace = 0;
serializeGetSizeInCore, \
serializePackInCore, \
serializeUnpackInCore, \
fileOpen_serial, \
fileClose_serial, \
CDI_NETCDF_SWITCHES \
}
......
......@@ -25,6 +25,8 @@ enum namespaceSwitch
NSSWITCH_SERIALIZE_GET_SIZE,
NSSWITCH_SERIALIZE_PACK,
NSSWITCH_SERIALIZE_UNPACK,
NSSWITCH_FILE_OPEN,
NSSWITCH_FILE_CLOSE,
#ifdef HAVE_LIBNETCDF
NSSWITCH_NC__CREATE,
NSSWITCH_CDF_DEF_VAR,
......
......@@ -5,6 +5,8 @@
#ifdef USE_MPI
#include "file.h"
#include "pio.h"
#include "cdi.h"
#include "pio_comm.h"
......@@ -104,10 +106,13 @@ int pioFileClose ( int id )
/***************************************************************/
int pioFileOpenW ( const char *filename )
int pioFileOpen(const char *filename, const char *mode)
{
int iret = CDI_UNDEFID;
if ((mode[0] != 'w' && mode[0] != 'W') || mode[0] == 0 || mode[1] != 0)
xabort("Unsupported mode \"%s\" in parallel file open.", mode);
switch ( commInqIOMode ())
{
case PIO_MPI:
......
......@@ -12,7 +12,7 @@
void backendCleanup ( void );
void backendInit ( void );
void backendFinalize ( void );
int pioFileOpenW ( const char* );
int pioFileOpen(const char *filename, const char *mode);
int pioFileClose ( int );
size_t pioFileWrite ( int, int, const void*, size_t );
......
......@@ -18,6 +18,7 @@
#ifdef USE_MPI
#include "namespace.h"
#include "pio.h"
#include "pio_serialize.h"
#include "pio_interface.h"
#include "pio_comm.h"
......@@ -818,6 +819,8 @@ pioInit(MPI_Comm commGlob, int nProcsIO, int IOMode,
{
serializeSetMPI();
namespaceSwitchSet(NSSWITCH_ABORT, cdiAbortC_MPI);
namespaceSwitchSet(NSSWITCH_FILE_OPEN, pioFileOpen);
namespaceSwitchSet(NSSWITCH_FILE_CLOSE, pioFileClose);
IOServer ();
namespaceDelete(0);
commDestroy ();
......
......@@ -171,9 +171,9 @@ void listInitialize ( void )
* created, before we register the listDestroy exit handler */
{
int null_id;
null_id = fileOpen("/dev/null", "r");
null_id = fileOpen_serial("/dev/null", "r");
if (null_id != -1)
fileClose(null_id);
fileClose_serial(null_id);
}
atexit ( listDestroy );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment