[mpich-discuss] Send/Recv Array of Numbers
Reuti
reuti at staff.uni-marburg.de
Fri May 4 10:16:33 CDT 2012
Hi,
Am 04.05.2012 um 17:01 schrieb Mis Nat:
> I'm trying to send random numbers in array which are generated in process 0 to process 1. I'm running in circles and I can't find out why process 1 receive only 6 of 10 numbers? Can please someone give me any advice what I'm doing wrong?
I wonder why the first ones are correct at all. For rank 1 you never allocate any memory AFAICS for the array. Allocating it for rank 1 too should fix it.
-- Reuti
> Thank you!
>
> Best regards,
>
> Nat
>
>
> void Test(int *Array, int ArraySize, int rank, int size)
> {
> int n=0;
> MPI_Status status;
>
> if (rank == 0)
> {
> MPI_Send(Array, ArraySize, MPI_INT, 1, 0, MPI_COMM_WORLD);
> }
> else if (rank == 1)
> {
> printf("\nReceiving:\n");
> MPI_Recv(Array, ArraySize, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
>
> for (n=0; n<=ArraySize; n++)
> printf("Proces %d array[%d]: %d \n", rank, n, Array[n]);
> }
> }
>
> int main(int argc, char *argv[])
> {
> int ArraySize;
> int *Array;
> int MyRank, npes;
> int n=0;
>
> MPI_Status status;
> MPI_Init(&argc,&argv);
>
> MPI_Comm_rank(MPI_COMM_WORLD,&MyRank);
> MPI_Comm_size(MPI_COMM_WORLD,&npes);
>
> if(MyRank==0)
> {
> ArraySize=10;
> Array=(int *)malloc(ArraySize*sizeof(int));
>
> if(Array==0)
> printf("Malloc memory error!");
>
> srand(time(NULL));
> for(n=0;n<ArraySize;n++)
> {
> Array[n]=(int)rand()%1000;
> printf("%d ",Array[n]);
> }
> printf("\n");
> }
>
> MPI_Bcast(&ArraySize,1,MPI_INT,0,MPI_COMM_WORLD);
> Test(Array,ArraySize, MyRank, npes);
>
> MPI_Finalize();
> return 0;
> }
>
>
> OUTPUT:
> D:\examples\Release>mpiexec -n 2 -machinefile mf.txt -path "D:\examples\Release"
> Sortiranje.exe
> 4 359 104 338 565 244 132 891 450 557
> ☺ 5☻ ˘ äProces 1 array[0]: 4
> Proces 1 array[1]: 359
> Proces 1 array[2]: 104
> Proces 1 array[3]: 338
> Proces 1 array[4]: 565
> Proces 1 array[5]: 244
> Proces 1 array[6]: 1869762692
> Proces 1 array[7]: 544433507
> Proces 1 array[8]: 1918967857
> Proces 1 array[9]: 1534681458
> Proces 1 array[10]: 540695856
>
>
>
> _______________________________________________
> mpich-discuss mailing list mpich-discuss at mcs.anl.gov
> To manage subscription options or unsubscribe:
> https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss
More information about the mpich-discuss
mailing list