From 97763c1071e2d6626bf1aac9476e9de97e6e9703 Mon Sep 17 00:00:00 2001 From: Raymond Lu Date: Wed, 22 Nov 2000 14:20:35 -0500 Subject: [svn-r2997] Purpose: Update Description: Added a new testing program into this file. It shows the way that does parallel computation and serialized I/O. --- doc/html/TechNotes/openmp-hdf5.html | 141 ++++++++++++++++++++++++++++++++++-- 1 file changed, 136 insertions(+), 5 deletions(-) diff --git a/doc/html/TechNotes/openmp-hdf5.html b/doc/html/TechNotes/openmp-hdf5.html index 3902927..decf1de 100644 --- a/doc/html/TechNotes/openmp-hdf5.html +++ b/doc/html/TechNotes/openmp-hdf5.html @@ -21,9 +21,9 @@ II. Programming(SGI MPISpro compiler and C language) III. Sample Programs -Attached are three OpenMP-HDF5 test programs. The purpose of these tests is to +Attached are four OpenMP-HDF5 test programs. The purpose of these tests is to experience OpenMP parallelism with HDF5. All the tests were run on modi4 with -SGI MPISpro compiler(cc) and make. The first one is the working +SGI MPISpro compiler(cc) and make. The first two are the working program. The two following only work occasionally. I modify them directly from hdf5/examples/h5_write.c. If you want to try them out, the quickest way is @@ -38,7 +38,138 @@ is - I. First Program + I. First Program +------------------------------------------------------------------------------- +/* + * This example writes 64 datasets to a HDF5 file, using multiple threads + * (OpenMP). Each thread grab the lock while it tries to call HDF5 functions + * to write out dataset. In this way, the HDF5 calls are serialized, while + * the calculation part is in parallel. This is one of the ways to do + * OpenMP computation with HDF. As long as not to do HDF I/O in parallel, + * it is safe to use HDF. + */ + +#include +#include +#include + +#define NUM_THREADS 4 +#define NUM_MDSET 16 +#define FILE "SDS.h5" +#define NX 5 /* dataset dimensions */ +#define NY 18 +#define RANK 2 + +void CalcWriteData(hid_t, hid_t, hid_t); + +/*Global variable, OpenMP lock*/ +omp_lock_t lock; + + +int +main (void) +{ + hid_t fid; /* file and dataset handles */ + hid_t datatype, dataspace; /* handles */ + hsize_t dimsf[2]; /* dataset dimensions */ + herr_t status; + int i; + + /* + * Create a new file using H5F_ACC_TRUNC access, + * default file creation properties, and default file + * access properties. + */ + fid = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + + /* + * Describe the size of the array and create the data space for fixed + * size dataset. + */ + dimsf[0] = NX; + dimsf[1] = NY; + dataspace = H5Screate_simple(RANK, dimsf, NULL); + + /* + * Define datatype for the data in the file. + * We will store little endian INT numbers. + */ + datatype = H5Tcopy(H5T_NATIVE_DOUBLE); + status = H5Tset_order(datatype, H5T_ORDER_LE); + + /*Disable dynamic allocation of threads*/ + omp_set_dynamic(0); + + /*Allocate threads*/ + omp_set_num_threads(NUM_THREADS); + + /*Initialize lock*/ + omp_init_lock(&lock); + + /*Each thread grab one iteration in the for loop and call function + * CaclWriteData*/ + #pragma omp parallel default(shared) + { + #pragma omp for + for(i=0; i