Hello!<div><br></div><div>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? </div>
<div><br></div><div>Thank you!</div><div><br></div><div>Best regards,</div><div><br></div><div>Nat</div><div><br></div><div><br></div><div><div>void Test(int *Array, int ArraySize, int rank, int size)</div><div>{<span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>int n=0;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>MPI_Status status;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (rank == 0)</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span> MPI_Send(Array, ArraySize, MPI_INT, 1, 0, MPI_COMM_WORLD);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> }</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> else if (rank == 1)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>printf("\nReceiving:\n");</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>MPI_Recv(Array,
ArraySize, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);<span class="Apple-tab-span" style="white-space:pre">        </span></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>for (n=0; n<=ArraySize; n++)</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>printf("Proces %d array[%d]: %d \n", rank, n, Array[n]);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> }<span class="Apple-tab-span" style="white-space:pre">                        </span></div>
<div>}</div><div><br></div><div>int main(int argc, char *argv[])</div><div>{<span class="Apple-tab-span" style="white-space:pre">        </span></div><div> int ArraySize;</div><div> int *Array;</div><div> int MyRank, npes;</div>
<div> int n=0;</div><div><br></div><div> MPI_Status status;</div><div> MPI_Init(&argc,&argv);</div><div><br></div><div> MPI_Comm_rank(MPI_COMM_WORLD,&MyRank);</div><div> MPI_Comm_size(MPI_COMM_WORLD,&npes);</div>
<div><br></div><div> if(MyRank==0)</div><div> {</div><div> ArraySize=10;</div><div> Array=(int *)malloc(ArraySize*sizeof(int));</div><div><br></div><div> if(Array==0)</div><div> printf("Malloc memory error!");</div>
<div><br></div><div> srand(time(NULL));</div><div> for(n=0;n<ArraySize;n++)</div><div> {</div><div> Array[n]=(int)rand()%1000;</div><div> printf("%d ",Array[n]);</div>
<div> }</div><div> printf("\n");</div><div> }</div><div><br></div><div>MPI_Bcast(&ArraySize,1,MPI_INT,0,MPI_COMM_WORLD);</div><div>Test(Array,ArraySize, MyRank, npes);</div><div><br></div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>MPI_Finalize();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>return 0;<span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div>}</div></div><div><br></div><div><br></div><div>OUTPUT:</div><div><div>D:\examples\Release>mpiexec -n 2 -machinefile mf.txt -path "D:\examples\Release"</div><div> Sortiranje.exe</div><div>4 359 104 338 565 244 132 891 450 557</div>
<div>☺ 5☻ ˘ äProces 1 array[0]: 4</div><div>Proces 1 array[1]: 359</div><div>Proces 1 array[2]: 104</div><div>Proces 1 array[3]: 338</div><div>Proces 1 array[4]: 565</div><div>Proces 1 array[5]: 244</div><div>Proces 1 array[6]: 1869762692</div>
<div>Proces 1 array[7]: 544433507</div><div>Proces 1 array[8]: 1918967857</div><div>Proces 1 array[9]: 1534681458</div><div>Proces 1 array[10]: 540695856</div></div><div><br></div><div><br></div><div><br></div>