MPI - receive multiple int from task 0 (root) -
i solving problem. implementing cycling mapping, have 4 processors, 1 task mapped on processor 1 (root), , 3 others workers. using cyclic mapping, , have input several integers, e.g. 0-40. want each worker receive (in case 10 integers each worker), counting , save it.
i using mpi_send send integers root, don't how multiply receive numbers same process (root). send int buffer size fixed on 1, when there number e.g. 12, bad things. how check length of int?
any advice appreciated. thanks
i'll assume you're working in c++, though question doesn't say. anyway, let's @ arguments of mpi_send:
mpi_send(buf, count, datatype, dest, tag, comm)
the second argument specifies how many data items want send. call means "buf
points point in memory there count
number of values, of them of type datatype
, 1 after other: send them". lets send contents of entire array, this:
int values[10]; (int i=0; i<10; i++) values[i] = i; mpi_send(values, 10, mpi_integer, 1, 0, mpi_comm_world);
this start reading memory @ start of values
, , keep reading until 10 mpi_integer
s have been read.
for case of distributing numbers between processes, how mpi_send:
int values[40]; (int i=0; i<40; i++) values[i] = i; (int i=1; i<4; i++) // start @ rank 1: don't send ourselves mpi_send(values+10*i, 10, mpi_integer, i, 0, mpi_comm_world);
however, such common operation in distributed computing mpi gives own function, mpi_scatter. scatter want: takes 1 array , divides evenly between processes call it. collective communication call, advanced topic, if you're learning mpi (which sounds are), feel free skip until you're comfortable using mpi_send , mpi_recv.
Comments
Post a Comment