From 542daf7fc2143af0bf1b436961768004eae8b992 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Fri, 23 Jun 2017 15:37:46 +0200 Subject: [PATCH] C examples: - define dummy MPI macros to be used in serial compilation, closing #10 - cleanup some "unused variable" warnings - fix some format warnings, using C99 format macros --- examples/H5/attach_file.c | 1 + examples/H5/openclose.c | 6 ++---- examples/H5/query.c | 2 ++ examples/H5/read_file_attribs.c | 1 + examples/H5/read_step_attribs.c | 1 + examples/H5/write_file_attribs.c | 1 + examples/H5/write_step_attribs.c | 1 + examples/H5Block/attach_field_attributes.c | 6 +----- examples/H5Block/dump_field_attributes.c | 11 +++++++---- examples/H5Block/fields.c | 10 ++++++++++ examples/H5Block/has_field.c | 11 +++++++---- examples/H5Block/read_write_scalar_field.c | 3 ++- examples/H5Block/write_field.c | 1 + examples/H5Part/query.c | 1 + examples/H5Part/read_canonicalview.c | 3 +-- examples/H5Part/read_core_vfd.c | 3 +-- examples/H5Part/read_setnparticles.c | 1 + examples/H5Part/read_setview.c | 1 + examples/H5Part/read_strided.c | 1 + examples/H5Part/write_core_vfd.c | 3 +-- examples/H5Part/write_setnparticles.c | 3 +-- examples/H5Part/write_setview.c | 3 +-- examples/H5Part/write_strided.c | 3 +-- examples/include/examples.h | 13 +++++++++++++ 24 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 examples/include/examples.h diff --git a/examples/H5/attach_file.c b/examples/H5/attach_file.c index c480de9..20d7485 100644 --- a/examples/H5/attach_file.c +++ b/examples/H5/attach_file.c @@ -17,6 +17,7 @@ #define VERBOSITY H5_VERBOSE_ERROR #define DEBUG_MSK H5_DEBUG_ALL +#include "examples.h" int main ( diff --git a/examples/H5/openclose.c b/examples/H5/openclose.c index f23d658..78ff99a 100644 --- a/examples/H5/openclose.c +++ b/examples/H5/openclose.c @@ -9,6 +9,8 @@ #include "H5hut.h" +#include "examples.h" + int main ( int argc, @@ -16,11 +18,7 @@ main ( ) { MPI_Comm comm = MPI_COMM_WORLD; - int myproc; - int nprocs; MPI_Init (&argc, &argv); - MPI_Comm_size (comm, &nprocs); - MPI_Comm_rank (comm, &myproc); h5_prop_t prop = H5CreateFileProp (); H5SetPropFileMPIOCollective (prop, &comm); diff --git a/examples/H5/query.c b/examples/H5/query.c index 658b75b..43a834b 100644 --- a/examples/H5/query.c +++ b/examples/H5/query.c @@ -9,6 +9,8 @@ #include "H5hut.h" +#include "examples.h" + #define FNAME1 "example_file_attribs.h5" #define FNAME2 "example_step_attribs.h5" diff --git a/examples/H5/read_file_attribs.c b/examples/H5/read_file_attribs.c index a035b33..03488bc 100644 --- a/examples/H5/read_file_attribs.c +++ b/examples/H5/read_file_attribs.c @@ -8,6 +8,7 @@ */ #include "H5hut.h" +#include "examples.h" #include diff --git a/examples/H5/read_step_attribs.c b/examples/H5/read_step_attribs.c index 08b91c7..d9b1369 100644 --- a/examples/H5/read_step_attribs.c +++ b/examples/H5/read_step_attribs.c @@ -8,6 +8,7 @@ */ #include "H5hut.h" +#include "examples.h" #include diff --git a/examples/H5/write_file_attribs.c b/examples/H5/write_file_attribs.c index 7de68c0..b709d77 100644 --- a/examples/H5/write_file_attribs.c +++ b/examples/H5/write_file_attribs.c @@ -8,6 +8,7 @@ */ #include "H5hut.h" +#include "examples.h" #define FNAME "example_file_attribs.h5" diff --git a/examples/H5/write_step_attribs.c b/examples/H5/write_step_attribs.c index 131f46b..2fad09a 100644 --- a/examples/H5/write_step_attribs.c +++ b/examples/H5/write_step_attribs.c @@ -8,6 +8,7 @@ */ #include "H5hut.h" +#include "examples.h" #define FNAME "example_step_attribs.h5" diff --git a/examples/H5Block/attach_field_attributes.c b/examples/H5Block/attach_field_attributes.c index 6da8cbe..355b510 100644 --- a/examples/H5Block/attach_field_attributes.c +++ b/examples/H5Block/attach_field_attributes.c @@ -8,6 +8,7 @@ */ #include "H5hut.h" +#include "examples.h" // name of output file const char* fname = "example_field.h5"; @@ -23,11 +24,6 @@ main ( // initialize MPI & H5hut MPI_Init (&argc, &argv); - MPI_Comm comm = MPI_COMM_WORLD; - int comm_size = 1; - MPI_Comm_size (comm, &comm_size); - int comm_rank = 0; - MPI_Comm_rank (comm, &comm_rank); H5AbortOnError (); H5SetVerbosityLevel (h5_verbosity); //H5SetDebugMask (-1); diff --git a/examples/H5Block/dump_field_attributes.c b/examples/H5Block/dump_field_attributes.c index 06a5e7b..090ea51 100644 --- a/examples/H5Block/dump_field_attributes.c +++ b/examples/H5Block/dump_field_attributes.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2015, The Regents of the University of California, + Copyright (c) 2006-2017, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy) and the Paul Scherrer Institut (Switzerland). All rights reserved. @@ -8,6 +8,9 @@ */ #include "H5hut.h" +#include "examples.h" + +#include // name of output file const char* fname = "example_field.h5"; @@ -30,9 +33,9 @@ dump_int64_attrib ( attrib_data); printf ("Attribute: '%s'\n", attrib_name); printf (" Type: H5_INT64_T\n"); - printf (" Data: %lld", attrib_data[0]); + printf (" Data: %" PRId64, attrib_data[0]); for (size_t i = 1; i < attrib_nelems; i++) { - printf (", %lld", attrib_data[i]); + printf (", %" PRId64, attrib_data[i]); } printf ("\n"); } @@ -174,7 +177,7 @@ main ( h5_ssize_t n_attribs = H5BlockGetNumFieldAttribs ( file, field_name); - printf ("Field has %lld attributes attached.\n", + printf ("Field has %" PRId64 " attributes attached.\n", n_attribs); // dump all attached attributes diff --git a/examples/H5Block/fields.c b/examples/H5Block/fields.c index bdf2a70..6cbb109 100644 --- a/examples/H5Block/fields.c +++ b/examples/H5Block/fields.c @@ -1,4 +1,14 @@ +/* + Copyright (c) 2006-2017, The Regents of the University of California, + through Lawrence Berkeley National Laboratory (subject to receipt of any + required approvals from the U.S. Dept. of Energy) and the Paul Scherrer + Institut (Switzerland). All rights reserved. + + License: see file COPYING in top level of source distribution. +*/ + #include +#include "examples.h" #define XSIZE 8 #define YSIZE 8 diff --git a/examples/H5Block/has_field.c b/examples/H5Block/has_field.c index 90f5179..2cc8427 100644 --- a/examples/H5Block/has_field.c +++ b/examples/H5Block/has_field.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2015, The Regents of the University of California, + Copyright (c) 2006-2017, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy) and the Paul Scherrer Institut (Switzerland). All rights reserved. @@ -8,6 +8,9 @@ */ #include "H5hut.h" +#include "examples.h" + +#include // name of output file const char* fname = "example_write_field.h5"; @@ -69,10 +72,10 @@ main ( } else if (type == H5_STRING_T) { stype = "H5_STRING_T"; } - printf ("rank of field: %lld\n", field_rank); - printf ("dims of field: [%lld, %lld, %lld]\n", + printf ("rank of field: %" PRId64 "\n", field_rank); + printf ("dims of field: [%" PRId64 ", %" PRId64 ", %" PRId64"]\n", field_dims[0], field_dims[1], field_dims[2]); - printf ("rank of field data: %lld\n", elem_rank); + printf ("rank of field data: %" PRId64 "\n", elem_rank); printf ("type of field data: '%s'\n", stype); done: // done diff --git a/examples/H5Block/read_write_scalar_field.c b/examples/H5Block/read_write_scalar_field.c index 047457a..04a09bb 100644 --- a/examples/H5Block/read_write_scalar_field.c +++ b/examples/H5Block/read_write_scalar_field.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2015, The Regents of the University of California, + Copyright (c) 2006-2017, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy) and the Paul Scherrer Institut (Switzerland). All rights reserved. @@ -8,6 +8,7 @@ */ #include "H5hut.h" +#include "examples.h" #include diff --git a/examples/H5Block/write_field.c b/examples/H5Block/write_field.c index d5b9f64..850960b 100644 --- a/examples/H5Block/write_field.c +++ b/examples/H5Block/write_field.c @@ -8,6 +8,7 @@ */ #include "H5hut.h" +#include "examples.h" // name of output file const char* fname = "example_field.h5"; diff --git a/examples/H5Part/query.c b/examples/H5Part/query.c index 86cab89..f1d08cf 100644 --- a/examples/H5Part/query.c +++ b/examples/H5Part/query.c @@ -8,6 +8,7 @@ */ #include "H5hut.h" +#include "examples.h" #define FNAME "example_setview.h5" #define VERBOSITY H5_VERBOSE_ERROR diff --git a/examples/H5Part/read_canonicalview.c b/examples/H5Part/read_canonicalview.c index ee7c62d..5b21394 100644 --- a/examples/H5Part/read_canonicalview.c +++ b/examples/H5Part/read_canonicalview.c @@ -8,6 +8,7 @@ */ #include "H5hut.h" +#include "examples.h" #include @@ -25,8 +26,6 @@ main ( // initialize MPI & H5hut MPI_Init (&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; - int comm_size = 1; - MPI_Comm_size (comm, &comm_size); int comm_rank = 0; MPI_Comm_rank (comm, &comm_rank); H5AbortOnError (); diff --git a/examples/H5Part/read_core_vfd.c b/examples/H5Part/read_core_vfd.c index 4e4ca0b..163db49 100644 --- a/examples/H5Part/read_core_vfd.c +++ b/examples/H5Part/read_core_vfd.c @@ -14,6 +14,7 @@ the VFD core driver. */ #include "H5hut.h" +#include "examples.h" #include @@ -32,8 +33,6 @@ main ( // initialize MPI & H5hut MPI_Init (&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; - int comm_size = 1; - MPI_Comm_size (comm, &comm_size); int comm_rank = 0; MPI_Comm_rank (comm, &comm_rank); H5AbortOnError (); diff --git a/examples/H5Part/read_setnparticles.c b/examples/H5Part/read_setnparticles.c index 12f6366..e8cc33e 100644 --- a/examples/H5Part/read_setnparticles.c +++ b/examples/H5Part/read_setnparticles.c @@ -8,6 +8,7 @@ */ #include "H5hut.h" +#include "examples.h" #include diff --git a/examples/H5Part/read_setview.c b/examples/H5Part/read_setview.c index 85c28fe..47deba1 100644 --- a/examples/H5Part/read_setview.c +++ b/examples/H5Part/read_setview.c @@ -8,6 +8,7 @@ */ #include "H5hut.h" +#include "examples.h" #include diff --git a/examples/H5Part/read_strided.c b/examples/H5Part/read_strided.c index ed80d97..1e21ce3 100644 --- a/examples/H5Part/read_strided.c +++ b/examples/H5Part/read_strided.c @@ -8,6 +8,7 @@ */ #include "H5hut.h" +#include "examples.h" #include diff --git a/examples/H5Part/write_core_vfd.c b/examples/H5Part/write_core_vfd.c index f29c252..49a7137 100644 --- a/examples/H5Part/write_core_vfd.c +++ b/examples/H5Part/write_core_vfd.c @@ -14,6 +14,7 @@ the VFD core driver. */ #include "H5hut.h" +#include "examples.h" // name of output file const char* fname = "example_core_vfd.h5"; @@ -33,8 +34,6 @@ main ( // initialize MPI & H5hut MPI_Init (&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; - int comm_size = 1; - MPI_Comm_size (comm, &comm_size); int comm_rank = 0; MPI_Comm_rank (comm, &comm_rank); H5AbortOnError (); diff --git a/examples/H5Part/write_setnparticles.c b/examples/H5Part/write_setnparticles.c index 5c8715e..392575c 100644 --- a/examples/H5Part/write_setnparticles.c +++ b/examples/H5Part/write_setnparticles.c @@ -8,6 +8,7 @@ */ #include "H5hut.h" +#include "examples.h" // name of output file const char* fname = "example_setnparticles.h5"; @@ -27,8 +28,6 @@ main ( // initialize MPI & H5hut MPI_Init (&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; - int comm_size = 1; - MPI_Comm_size (comm, &comm_size); int comm_rank = 0; MPI_Comm_rank (comm, &comm_rank); H5AbortOnError (); diff --git a/examples/H5Part/write_setview.c b/examples/H5Part/write_setview.c index 480f3c9..6f56c48 100644 --- a/examples/H5Part/write_setview.c +++ b/examples/H5Part/write_setview.c @@ -8,6 +8,7 @@ */ #include "H5hut.h" +#include "examples.h" // name of output file const char* fname = "example_setview.h5"; @@ -28,8 +29,6 @@ main ( // initialize MPI & H5hut MPI_Init (&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; - int comm_size = 1; - MPI_Comm_size (comm, &comm_size); int comm_rank = 0; MPI_Comm_rank (comm, &comm_rank); H5AbortOnError (); diff --git a/examples/H5Part/write_strided.c b/examples/H5Part/write_strided.c index fd7d452..96511e4 100644 --- a/examples/H5Part/write_strided.c +++ b/examples/H5Part/write_strided.c @@ -8,6 +8,7 @@ */ #include "H5hut.h" +#include "examples.h" // name of output file const char* fname = "example_strided.h5"; @@ -27,8 +28,6 @@ main ( // initialize MPI & H5hut MPI_Init (&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; - int comm_size = 1; - MPI_Comm_size (comm, &comm_size); int comm_rank = 0; MPI_Comm_rank (comm, &comm_rank); H5AbortOnError (); diff --git a/examples/include/examples.h b/examples/include/examples.h new file mode 100644 index 0000000..abed2c1 --- /dev/null +++ b/examples/include/examples.h @@ -0,0 +1,13 @@ +#ifndef __EXAMPLES_H +#define __EXAMPLES_H + +#if !defined (PARALLEL_IO) + +#define MPI_COMM_WORLD (0) +#define MPI_Init(argc, argv) +#define MPI_Comm_size(comm,nprocs) {comm = 0; *nprocs = 1;} +#define MPI_Comm_rank(comm,rank) {comm = 0; (void)(comm); *rank = 0;} +#define MPI_Finalize() + +#endif +#endif -- GitLab