Skip to Content.
Sympa Menu

h5part - Re: [H5part] Patch#1 : Win32 compiler support

h5part AT lists.psi.ch

Subject: H5Part development and discussion

List archive

Re: [H5part] Patch#1 : Win32 compiler support


Chronological Thread 
  • From: John Biddiscombe <biddisco AT cscs.ch>
  • Cc: Achim Gsell <achim.gsell AT psi.ch>, h5part AT lists.psi.ch
  • Subject: Re: [H5part] Patch#1 : Win32 compiler support
  • Date: Thu, 10 May 2007 14:29:35 +0200
  • List-archive: <https://lists.web.psi.ch/pipermail/h5part/>
  • List-id: H5Part development and discussion <h5part.lists.psi.ch>

I decided that to move things along, it'd be better to include a full patch with the _errno issue fixed cleanly

Note 1:
I also moved the
#ifdef __cplusplus
extern "C" {
#endif

in h5part.h because at the moment it is surrounding all the
#include <stdlib.h>
#include <stdarg.h>
#include <hdf5.h>
#ifdef PARALLEL_IO
#include <mpi.h>
#endif

which gcc didn't like (mpi in particular on my system - using HP mpi)

Note 2: The typedefs are necessary because
a) the malloc's have to be cast for msvc to be happy
b) once the mallocs are cast, the types have to be defined (typedefed) for gcc to be happy


Index: src/H5Block.c
===================================================================
--- src/H5Block.c (revision 2902)
+++ src/H5Block.c (working copy)
@@ -119,17 +119,17 @@
*/
if ( f->nprocs == 0 ) f->nprocs = 1;

- f->block = malloc( sizeof (*f->block) );
+ f->block = (H5BlockStruct*)malloc( sizeof (*f->block) );
if ( f->block == NULL ) {
return HANDLE_H5PART_NOMEM_ERR;
}
b = f->block;
memset ( b, 0, sizeof (*b) );
- b->user_layout = malloc ( f->nprocs * sizeof (b->user_layout[0]) );
+ b->user_layout = (H5BlockPartition*)malloc ( f->nprocs * sizeof
(b->user_layout[0]) );
if ( b->user_layout == NULL ) {
return HANDLE_H5PART_NOMEM_ERR;
}
- b->write_layout = malloc ( f->nprocs * sizeof (b->write_layout[0]) );
+ b->write_layout = (H5BlockPartition*)malloc ( f->nprocs * sizeof
(b->write_layout[0]) );
if ( b->write_layout == NULL ) {
return HANDLE_H5PART_NOMEM_ERR;
}
@@ -573,11 +573,12 @@
struct H5BlockPartition *q;
h5part_int64_t vol;
} *p_begin, *p_el, *p_max, *p_end, *p_save;
+ typedef struct list list;

memcpy ( b->write_layout, b->user_layout,
f->nprocs * sizeof (*f->block->user_layout) );

- p_begin = p_max = p_end = malloc ( sizeof ( *p_begin ) );
+ p_begin = p_max = p_end = (list*)malloc ( sizeof ( *p_begin ) );
if ( p_begin == NULL ) return HANDLE_H5PART_NOMEM_ERR;

memset ( p_begin, 0, sizeof ( *p_begin ) );
@@ -590,7 +591,7 @@
proc_q++, q++ ) {

if ( _have_ghostzone ( p, q ) ) {
- p_el = malloc ( sizeof ( *p_el ) );
+ p_el = (list*)malloc ( sizeof ( *p_el ) );
if ( p_el == NULL )
return HANDLE_H5PART_NOMEM_ERR;

Index: src/H5BlockTypes.h
===================================================================
--- src/H5BlockTypes.h (revision 2902)
+++ src/H5BlockTypes.h (working copy)
@@ -26,6 +26,9 @@
hid_t field_group_id;
};

+typedef struct H5BlockStruct H5BlockStruct;
+typedef struct H5BlockPartition H5BlockPartition;
+
#define H5PART_ERR_LAYOUT -100
#define H5PART_ERR_NOENT -101

Index: src/H5Part.c
===================================================================
--- src/H5Part.c (revision 2902)
+++ src/H5Part.c (working copy)
@@ -78,7 +78,6 @@
#include <stdlib.h>
#include <stdarg.h> /* va_arg - System dependent ?! */
#include <string.h>
-#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <hdf5.h>
@@ -88,10 +87,18 @@
#include "H5PartPrivate.h"
#include "H5PartErrors.h"

+#ifndef WIN32
+ #include <unistd.h>
+#else
+ #include <io.h>
+ #define open _open
+ #define close _close
+#endif
+
/********* Private Variable Declarations *************/

-static unsigned _debug = 0;
-static h5part_int64_t _errno = H5PART_SUCCESS;
+static unsigned _debug = 0;
+static h5part_int64_t _h5errno = H5PART_SUCCESS;
static h5part_error_handler _err_handler = H5PartReportErrorHandler;
static char *__funcname = "NONE";

@@ -125,7 +132,7 @@
HANDLE_H5PART_INIT_ERR;
return NULL;
}
- _errno = H5PART_SUCCESS;
+ _h5errno = H5PART_SUCCESS;
H5PartFile *f = NULL;

f = (H5PartFile*) malloc( sizeof (H5PartFile) );
@@ -158,7 +165,7 @@
goto error_cleanup;
}

- f->pnparticles = malloc (f->nprocs * sizeof (h5part_int64_t));
+ f->pnparticles = (h5part_int64_t*)malloc (f->nprocs * sizeof
(h5part_int64_t));
if (f->pnparticles == NULL) {
HANDLE_H5PART_NOMEM_ERR;
goto error_cleanup;
@@ -366,7 +373,7 @@

SET_FNAME ( "H5PartCloseFile" );
herr_t r = 0;
- _errno = H5PART_SUCCESS;
+ _h5errno = H5PART_SUCCESS;

CHECK_FILEHANDLE ( f );

@@ -419,7 +426,7 @@
}
free( f );

- return _errno;
+ return _h5errno;
}

/*============== File Writing Functions ==================== */
@@ -524,35 +531,35 @@
/*
acquire the number of particles to be written from each MPI process
*/
- r = MPI_Allgather (
- &nparticles, 1, MPI_LONG_LONG,
- f->pnparticles, 1, MPI_LONG_LONG,
- f->comm);
- if ( r != MPI_SUCCESS) {
- return HANDLE_MPI_ALLGATHER_ERR;
- }
- if ( f->myproc == 0 ) {
- _H5Part_print_debug ( "Particle offsets:" );
- for(i=0;i<f->nprocs;i++)
- _H5Part_print_debug ( "\tnp=%lld",
- (long long) f->pnparticles[i] );
- }
- /* should I create a selection here? */
+ r = MPI_Allgather (
+ &nparticles, 1, MPI_LONG_LONG,
+ f->pnparticles, 1, MPI_LONG_LONG,
+ f->comm);
+ if ( r != MPI_SUCCESS) {
+ return HANDLE_MPI_ALLGATHER_ERR;
+ }
+ if ( f->myproc == 0 ) {
+ _H5Part_print_debug ( "Particle offsets:" );
+ for(i=0;i<f->nprocs;i++)
+ _H5Part_print_debug ( "\tnp=%lld",
+ (long long) f->pnparticles[i]
);
+ }
+ /* should I create a selection here? */

- /* compute start offsets */
- stride[0] = 1;
- start[0] = 0;
- for (i=0; i<f->myproc; i++) {
- start[0] += f->pnparticles[i];
- }
-
+ /* compute start offsets */
+ stride[0] = 1;
+ start[0] = 0;
+ for (i=0; i<f->myproc; i++) {
+ start[0] += f->pnparticles[i];
+ }
+


- /* compute total nparticles */
- total = 0;
- for (i=0; i < f->nprocs; i++) {
- total += f->pnparticles[i];
- }
+ /* compute total nparticles */
+ total = 0;
+ for (i=0; i < f->nprocs; i++) {
+ total += f->pnparticles[i];
+ }

/* declare overall datasize */
f->shape = H5Screate_simple (1, &total, &total);
@@ -568,14 +575,14 @@
if (f->memshape < 0)
return HANDLE_H5S_CREATE_SIMPLE_ERR ( f->nparticles );

- count[0] = nparticles;
- r = H5Sselect_hyperslab (
- f->diskshape,
- H5S_SELECT_SET,
- start,
- stride,
- count, NULL );
- if ( r < 0 ) return HANDLE_H5S_SELECT_HYPERSLAB_ERR;
+ count[0] = nparticles;
+ r = H5Sselect_hyperslab (
+ f->diskshape,
+ H5S_SELECT_SET,
+ start,
+ stride,
+ count, NULL );
+ if ( r < 0 ) return HANDLE_H5S_SELECT_HYPERSLAB_ERR;

if ( f->timegroup < 0 ) {
r = _H5Part_set_step ( f, 0 );
@@ -1380,7 +1387,7 @@
void *operator_data /*!< [in,out] data passed to the iterator */
) {

- struct _iter_op_data *data = operator_data;
+ struct _iter_op_data *data = (_iter_op_data*)operator_data;
herr_t herr;
H5G_stat_t objinfo;

@@ -2330,7 +2337,7 @@
H5PartGetErrno (
void
) {
- return _errno;
+ return _h5errno;
}

/*!
@@ -2349,14 +2356,14 @@
...
) {

- _errno = eno;
+ _h5errno = eno;
if ( _debug > 0 ) {
va_list ap;
va_start ( ap, fmt );
_H5Part_vprint_error ( fmt, ap );
va_end ( ap );
}
- return _errno;
+ return _h5errno;
}

/*!
@@ -2373,7 +2380,7 @@
...
) {

- _errno = eno;
+ _h5errno = eno;
if ( _debug > 0 ) {
va_list ap;
va_start ( ap, fmt );
@@ -2381,7 +2388,7 @@
vfprintf ( stderr, fmt, ap );
fprintf ( stderr, "\n" );
}
- exit (-_errno);
+ exit (-_h5errno);
}

/*!
@@ -2417,7 +2424,7 @@
const char *fmt,
va_list ap
) {
- char *fmt2 = malloc( strlen ( prefix ) +strlen ( fmt ) + strlen (
__funcname ) + 16 );
+ char *fmt2 = (char*)malloc( strlen ( prefix ) +strlen ( fmt ) +
strlen ( __funcname ) + 16 );
if ( fmt2 == NULL ) return;
sprintf ( fmt2, "%s: %s: %s\n", prefix, __funcname, fmt );
vfprintf ( stderr, fmt2, ap );
Index: src/H5Part.h
===================================================================
--- src/H5Part.h (revision 2902)
+++ src/H5Part.h (working copy)
@@ -1,16 +1,17 @@
#ifndef _H5Part_H_
#define _H5Part_H_

-#ifdef __cplusplus
-extern "C" {
-#endif
-
#include <stdlib.h>
#include <stdarg.h>
#include <hdf5.h>
#ifdef PARALLEL_IO
#include <mpi.h>
#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include "H5PartTypes.h"


Index: src/H5PartPrivate.h
===================================================================
--- src/H5PartPrivate.h (revision 2902)
+++ src/H5PartPrivate.h (working copy)
@@ -21,6 +21,8 @@
char *pattern;
};

+typedef struct _iter_op_data _iter_op_data;
+
h5part_int64_t
_H5Part_set_step (
H5PartFile *f,
Index: src/H5PartTypes.h
===================================================================
--- src/H5PartTypes.h (revision 2902)
+++ src/H5PartTypes.h (working copy)
@@ -5,6 +5,12 @@
#ifndef _H5PARTTYPES_H_
#define _H5PARTTYPES_H_

+#ifdef _WIN32
+ typedef __int64 int64_t;
+ typedef int errno_t;
+#else
+ typedef int64_t errno_t;
+#endif

typedef int64_t h5part_int64_t;
typedef double h5part_float64_t;



Archive powered by MHonArc 2.6.19.

Top of Page