Create & open groups with several process

Hi,

In my computer code, I want to create several groups. Basically, the process of rank 0 should create my groups. Then all the process should access to these groups in order to write data in the dataset.

This is a piece of my code to illustrate my request:

#include "hdf5.h"
#define H5FILE_NAME "File.h5"
#define DATASETNAME "My_Array"

int main(int argc, char **argv){
      //declare variables
      hid_t file_id, group_id, plist_id;
      int world_rank, world_size;

      MPI_Init(&argc, &argv);
      MPI_Comm_rank(MPI_COMM_WORLD, & world_rank);
      MPI_Comm_size(MPI_COMM_WORLD, &world_size);

     //All process have to access to file
      plist_id = H5Pcreate(H5P_FILE_ACCESS);
      H5Pset_fapl_mpio(plist_id, MPI_COMM_WORLD, MPI_INFO_NULL);

      //Create my file
      file_id = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

      //Only process of rank 0 can create my groups, here we have one group
      if(world_rank == 0){
         group_id = H5Gcreate(file_id, "/MyGroup", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
      }
       //I want to synchronize my process
       MPI_Barrier(MPI_COMM_WORLD);
       hid_t grp;
       //All process can access on my groups
       grp = H5Gopen2(file_id, "/MyGroup", H5P_DEFAULT);

       //release ressources
       H5Gclose(grp);
       H5Gclose(group_id);
       H5Fclose(file_id);
       H5Pclose(plist_id);

      MPI_Finalize();

return 0;

}

My code compiles, but it doesn't run. In particular, I can't open my group. I have a problem about groups here.

What is my mistake in this program?

Thanks to you

Rolih

Rohlih, several APIs in parallel HDF5 must be called collectively.
H5Gcreate is one of them. A complete list can be found here:

https://www.hdfgroup.org/HDF5/doc/RM/CollectiveCalls.html

G.

···

-----Original Message-----
From: Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org] On Behalf Of MEYNARD Rolih
Sent: Wednesday, June 29, 2016 7:31 AM
To: Hdf-forum@lists.hdfgroup.org
Subject: [Hdf-forum] Create & open groups with several process

Hi,

In my computer code, I want to create several groups. Basically, the process of rank 0 should create my groups. Then all the process should access to these groups in order to write data in the dataset.

This is a piece of my code to illustrate my request:

#include "hdf5.h"
#define H5FILE_NAME "File.h5"
#define DATASETNAME "My_Array"

int main(int argc, char **argv){
      //declare variables
      hid_t file_id, group_id, plist_id;
      int world_rank, world_size;

      MPI_Init(&argc, &argv);
      MPI_Comm_rank(MPI_COMM_WORLD, & world_rank);
      MPI_Comm_size(MPI_COMM_WORLD, &world_size);

     //All process have to access to file
      plist_id = H5Pcreate(H5P_FILE_ACCESS);
      H5Pset_fapl_mpio(plist_id, MPI_COMM_WORLD, MPI_INFO_NULL);

      //Create my file
      file_id = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

      //Only process of rank 0 can create my groups, here we have one group
      if(world_rank == 0){
         group_id = H5Gcreate(file_id, "/MyGroup", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
      }
       //I want to synchronize my process
       MPI_Barrier(MPI_COMM_WORLD);
       hid_t grp;
       //All process can access on my groups
       grp = H5Gopen2(file_id, "/MyGroup", H5P_DEFAULT);

       //release ressources
       H5Gclose(grp);
       H5Gclose(group_id);
       H5Fclose(file_id);
       H5Pclose(plist_id);

      MPI_Finalize();

return 0;

}

My code compiles, but it doesn't run. In particular, I can't open my group. I have a problem about groups here.

What is my mistake in this program?

Thanks to you

Rolih

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

If you want one process to create the file’s groups then you need to close the file before all the processors access the file again, this is what you would do:

#include "hdf5.h"
#define H5FILE_NAME "File.h5"
#define DATASETNAME "My_Array"

int main(int argc, char **argv){
     //declare variables
     hid_t file_id, group_id, plist_id;
     int world_rank, world_size;

     MPI_Init(&argc, &argv);
     MPI_Comm_rank(MPI_COMM_WORLD, & world_rank);
     MPI_Comm_size(MPI_COMM_WORLD, &world_size);

    //All process have to access to file
     plist_id = H5Pcreate(H5P_FILE_ACCESS);
     H5Pset_fapl_mpio(plist_id, MPI_COMM_WORLD, MPI_INFO_NULL);

     //Create my file
     if(world_rank == 0){
       file_id = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

     //Only process of rank 0 can create my groups, here we have one group
       group_id = H5Gcreate(file_id, "/MyGroup", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

       H5Gclose(group_id);
       H5Fclose(file_id);
     }
      //I want to synchronize my process
      MPI_Barrier(MPI_COMM_WORLD);

      file_id = H5Fopen(H5FILE_NAME, H5F_ACC_RDWR, plist_id);

      hid_t grp;
      //All process can access on my groups
      grp = H5Gopen2(file_id, "/MyGroup", H5P_DEFAULT);

      //release ressources
      H5Gclose(grp);
      H5Fclose(file_id);
      H5Pclose(plist_id);

     MPI_Finalize();

return 0;

}

Thank you very much Scot, it works )
Quoting Scot Breitenfeld <brtnfld@hdfgroup.org>:

···

If you want one process to create the file’s groups then you need to close the file before all the processors access the file again, this is what you would do:

#include "hdf5.h"
#define H5FILE_NAME "File.h5"
#define DATASETNAME "My_Array"

int main(int argc, char **argv){
     //declare variables
     hid_t file_id, group_id, plist_id;
     int world_rank, world_size;

     MPI_Init(&argc, &argv);
     MPI_Comm_rank(MPI_COMM_WORLD, & world_rank);
     MPI_Comm_size(MPI_COMM_WORLD, &world_size);

    //All process have to access to file
     plist_id = H5Pcreate(H5P_FILE_ACCESS);
     H5Pset_fapl_mpio(plist_id, MPI_COMM_WORLD, MPI_INFO_NULL);

     //Create my file
     if(world_rank == 0){
       file_id = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

     //Only process of rank 0 can create my groups, here we have one group
       group_id = H5Gcreate(file_id, "/MyGroup", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

       H5Gclose(group_id);
       H5Fclose(file_id);
     }
      //I want to synchronize my process
      MPI_Barrier(MPI_COMM_WORLD);

      file_id = H5Fopen(H5FILE_NAME, H5F_ACC_RDWR, plist_id);

      hid_t grp;
      //All process can access on my groups
      grp = H5Gopen2(file_id, "/MyGroup", H5P_DEFAULT);

      //release ressources
      H5Gclose(grp);
      H5Fclose(file_id);
      H5Pclose(plist_id);

     MPI_Finalize();

return 0;

}

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5