简体   繁体   中英

mpi4py - Get process's own communicator

We are currently working on an mpi4py project where we want to group processes in different groups. We then assign these groups to their own communicators. Theses steps are done by the process 0.

Now the question is how can the other processes find out what communicator they belong to?

Please note that the groups are of different sizes, eg group one contains 5 processes and group two 3 ones. So, how can process 4 (in group one) get the communicator from group one.

MPI does this for you. Take a look at MPI_COMM_SPLIT, or in mpi4py it would be COMM.Split(). The important parameters are the 'color' (which group processes will end up in) and 'key' (what order a process will be in that group).

It sounds like you already know how you want to 'color' your processes. COMM.Split() is collective over the parent communicator, so you'll compute on each node what the color should be, then split the communicator. You can likely leave the key alone, in which case the processes will be sorted according to their rank in the parent communicator.

We solved the issue by simply letting every process do the same initialisation, ie every process creates every group and communicator and assigns the processes to these groups according to the same schema. This way, the processes know their corresponding communicators.

Interestingly we found out, that, although every process creates all the groups and communicators, they only know the communicators (and groups) they belong to. If, for instance, process 4, which belongs to communicator 1 but not 2, wants to use the communicator 2, it will crash. According to the error message, this is due because it does not know the communicator, although it initialised it at the beginning.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM