I am solving this problem. I am implementing cycling mapping, I have 4 processors, so one task is mapped on processor 1 (root), and then three others are workers. I am using cyclic mapping, and I have as a input several integers, e.g. 0-40. I want from each worker to receive (in this case it would be 10 integers for each worker), do some counting and save it.
I am using MPI_Send to send integers from root, but I don’t how to multiply receive some numbers from the same process (root). Also I send int with buffer size fixed on 1, when there is number e.g. 12, it would do bad things. How to check length of an int?
Any advice would be appreciated. Thanks
I’ll assume you’re working in C++, though your question doesn’t say. Anyway, let’s look at the arguments of MPI_Send:
The second argument specifies how many data items you want to send. This call basically means “
bufpoints to a point in memory where there arecountnumber of values, all of them of typedatatype, one after the other: send them”. This lets you send the contents of an entire array, like this:This will start reading memory at the start of
values, and keep reading until 10MPI_INTEGERs have been read.For your case of distributing numbers between processes, this is how you do it with MPI_Send:
However, this is such a common operation in distributed computing that MPI gives it its very own function, MPI_Scatter. Scatter does exactly what you want: it takes one array and divides it up evenly between all processes who call it. This is a collective communication call, which is a slightly advanced topic, so if you’re just learning MPI (which it sounds like you are), then feel free to skip it until you’re comfortable using MPI_Send and MPI_Recv.