Hi Bruno,

On Sep 26, 2011, at 7:11 AM, Bruno Magalhaes wrote:

> Hi,
> 
> We are trying to use parallel HDF5 to write data to a file.
> 
> The execution seems to be going well, but the H5Fclose hangs the execution.
> I.e the following message is printed:
> "All parallel hdf5 content written, closing file...\n"
> but the
> "Done"
> never gets to be printed.
> 
> Any suggestion or amendment to the following code?

        Your problem is that you are modifying metadata independently (in the 
"if(mpiRank == 0)" block, which is not allowed (currently).  You'll need to 
change that so that all the H5A/H5D calls in that block are executed 
collectively, so that all the processes have the same "view" of the file's 
state.  (We are working to change this, but it'll be a while before it gets 
implemented)

        Quincey

> Thanks
> 
> Bruno Magalhaes, Blue Brain Project, EPFL, Lausanne CH [+41 2169 31805]
> 
> 
> 
> 
> //------------------- BEGINNING OF SOURCE CODE --------------------
> 
> #include <stdio.h>
> #include <cstdlib>
> 
> #include <mpi.h>
> 
> #define H5_USE_16_API 1
> #include "hdf5.h"
> 
> #define NUMVALUES 19
> 
> using namespace std;
> 
> int main(int argc, char** argv) {
> 
>    MPI_Init(&argc, &argv);
> 
>    int mpiRank=-1, mpiSize=-1;
>    MPI_Comm_rank(MPI_COMM_WORLD, &mpiRank);
>    MPI_Comm_size(MPI_COMM_WORLD, &mpiSize);
> 
>    if (mpiRank==0) printf("Writing header...\n");
> 
>    int numOfNeurons = 100;
> 
>    hid_t file_id = 0;
>    herr_t status;
>    hsize_t dims[2];
>    char filename[1024] = "/bgscratch/bmagalha/delete.h5";
> 
>    //Set up file access property list with parallel I/O access
>    hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS);
>    H5Pset_fapl_mpio(plist_id, MPI_COMM_WORLD, MPI_INFO_NULL) ;
> 
>    //Create a new file collectively and release property list identifier.
>    file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, plist_id);
>    H5Pclose(plist_id);
> 
>    if (mpiRank == 0) {
>        //Initialize the attribute data.
>        int info_version_data = 3;
>        int info_numberOfFiles_data = 1;
> 
>        hsize_t info_dims = 1;
>        hid_t filespace_h = H5Screate_simple(0,&info_dims, NULL);
>        hid_t dset_id_info = H5Dcreate(file_id, "/info", H5T_NATIVE_FLOAT, 
> filespace_h, H5P_DEFAULT);
> 
>        //Create the data space for the attribute.
>        hid_t info_dataspace_id = H5Screate_simple(1, &info_dims, NULL);
> 
>        //Create a dataset attribute and count of files.
>        hid_t info_version_id = H5Acreate(dset_id_info, "version", 
> H5T_STD_I32BE, info_dataspace_id, H5P_DEFAULT);
>        hid_t info_numberOfFiles_id = H5Acreate(dset_id_info, "numberOfFiles", 
> H5T_STD_I32BE, info_dataspace_id, H5P_DEFAULT);
> 
>        //Write the attribute and files Countdata.
>        H5Awrite(info_version_id, H5T_NATIVE_INT, &info_version_data);
>        H5Awrite(info_numberOfFiles_id, H5T_NATIVE_INT, 
> &info_numberOfFiles_data);
> 
>    //Create property list for individual dataset write (default).
>        plist_id = H5Pcreate(H5P_DATASET_XFER);
>    H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_INDEPENDENT);
> 
>    //to write data collectively, use:
> //      plist_id = H5Pcreate(H5P_DATASET_XFER);
> //      H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
> 
>        //Close the attributes, dataspace and dataset.
>        status = H5Aclose(info_version_id);
>        status = H5Aclose(info_numberOfFiles_id);
>        status = H5Dclose(dset_id_info);
>        status = H5Sclose(info_dataspace_id);
>    }
> 
>    if (mpiRank==0) printf("Writing body...\n");
> 
>    char name[512];
>    float *allSynapsesSendBuff;
>    for (int i = 0; i < numOfNeurons; i++) {
> 
>        dims[0] = 2000; // Create the dataset.
>        allSynapsesSendBuff = new float[NUMVALUES * dims[0]];
> 
>    dims[1] = NUMVALUES;
>    hid_t filespace = H5Screate_simple(2, dims, NULL);
> 
>    sprintf(name, "a.%d.%d", mpiRank, i);
> 
>    //Create dataset with default properties and close filespace
>    hid_t dset_id = H5Dcreate(file_id, name, H5T_NATIVE_FLOAT, filespace, 
> H5P_DEFAULT);
> 
>    //Create property list for independent dataset write
>    hid_t plist_id = H5Pcreate(H5P_DATASET_XFER);
>    H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_INDEPENDENT);
> 
>    H5Dwrite(dset_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, plist_id, 
> allSynapsesSendBuff);
> 
>    // End access to the dataset and release resources used by it.
>    status = H5Dclose(dset_id);
>    status = H5Sclose(filespace);
>    status = H5Pclose(plist_id);
>    }
> 
>    MPI_Barrier(MPI_COMM_WORLD);
>    if (mpiRank==0) printf("All parallel hdf5 content written, closing 
> file...\n");
>    fflush(stdout);
> 
>    // Terminates access to the file.
>    status = H5Fclose(file_id);
>    MPI_Barrier(MPI_COMM_WORLD);
> 
>    if (mpiRank==0) printf("Done.\n");
>    MPI_Finalize();
>    return 0;
> }
> 
> 
> //------------------- END OF SOURCE CODE --------------------
> 
> 
> _______________________________________________
> Hdf-forum is for HDF software users discussion.
> [email protected]
> http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org


_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

Reply via email to