简体   繁体   中英

Can the tag of MPI_Send() be a long int?

I am working on my project which uses cpp and openmpi . Inside my program, there are many "compute units", I call them elements . For each element, I generate a unique unsigned long int to identify it, I call this integer key .

The problem is that I now need some elements to communicate with each other among processors, namely using MPI_Send() and MPI_Recv() . Since each element knows who it should send messages to and receive messages from, ie, it knows the key of the target element that they should send to or receive from, it would be intuitive to use the key as the tag in MPI_Send() and MPI_Recv() . However, I see the tag in the man page of openmpi is an int . So it is a 4 bytes integer? Is it possible for me to use an unsigned long int as the tag? Thank you very much!

No, unfortunately, tags cannot be long int s. The C bindings define the tag as int , but the set of actually allowed values is even smaller and is also implementation-dependent. For one, tags must be positive. Then there is an upper bound (UB) imposed by the MPI implementation that is available by querying MPI_COMM_WORLD for the MPI_TAG_UB attribute:

int flag;
int *tag_ub;

MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_TAG_UB, &tag_ub, &flag);
if (flag)
  cout << "Max allowed tag value is " << *tag_ub << endl;
else
  cout << "No idea what the max allowed tag value is" << endl;

Not only may the value vary between the different MPI implementations, but it may also vary given the same implementation based on the communication transport(s) selected by the job (I've seen this happen with certain MPI implementations). The standard only guarantees you that the value of the tag UB will not be less than 32767.

Your best and most portable option is to make the element ID part of the actual message data.

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