Quantcast

Create & open groups with several process

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Create & open groups with several process

MEYNARD Rolih

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.
[hidden email]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Create & open groups with several process

Gerd Heber
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:[hidden email]] On Behalf Of MEYNARD Rolih
Sent: Wednesday, June 29, 2016 7:31 AM
To: [hidden email]
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.
[hidden email]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

_______________________________________________
Hdf-forum is for HDF software users discussion.
[hidden email]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Create & open groups with several process

Scot Breitenfeld
In reply to this post by MEYNARD Rolih
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.
[hidden email]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Create & open groups with several process

MEYNARD Rolih
Thank you very much Scot, it works )
Quoting Scot Breitenfeld <[hidden email]>:

> 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.
> [hidden email]
> http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
> Twitter: https://twitter.com/hdf5



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