<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><div dir="ltr">Hi<div>when i execute this program (I use two processes) i have a error in the display part :</div><div>* RESULT OF EXECUTION:</div><div><div>0<span class="" style="white-space:pre">        </span>1<span class="" style="white-space:pre"> </span>2<span class="" style="white-space:pre"> </span>3<span class="" style="white-space:pre"> </span>4<span class="" style="white-space:pre"> </span>5<span class="" style="white-space:pre"> </span>6<span class="" style="white-space:pre"> </span>7<span class="" style="white-space:pre"> </span>8<span class="" style="white-space:pre"> </span>9<span class="" style="white-space:pre"> </span></div><div>>> (1,6) << </div><div><br></div><div><span class="" style="white-space:pre">      </span>>>>><span class="" style="white-space:pre">  </span></div><div><br></div><div><span class="" style="white-space:pre">  </span>> 1 <<span class="" style="white-space:pre">       </span></div><div>* -6277438562204192500000000000000000000000000000000000000000000000000<span class="" style="white-space:pre">     </span>* -6277438562204192500000000000000000000000000000000000000000000000000<span class="" style="white-space:pre">    </span>* -6277438562204192500000000000000000000000000000000000000000000000000<span class="" style="white-space:pre">    </span>* -6277438562204192500000000000000000000000000000000000000000000000000<span class="" style="white-space:pre">    </span>* -6277438562204192500000000000000000000000000000000000000000000000000<span class="" style="white-space:pre">    </span>* -6277438562204192500000000000000000000000000000000000000000000000000<span class="" style="white-space:pre">    </span></div><div>0<span class="" style="white-space:pre">  </span>1<span class="" style="white-space:pre"> </span>2<span class="" style="white-space:pre"> </span>3<span class="" style="white-space:pre"> </span>4<span class="" style="white-space:pre"> </span>5<span class="" style="white-space:pre"> </span>6<span class="" style="white-space:pre"> </span>7<span class="" style="white-space:pre"> </span>8<span class="" style="white-space:pre"> </span>9<span class="" style="white-space:pre"> </span></div><div>0  1  2  3  </div><div>4  5  6  7  8  9  </div><div>>> (0,4) << </div><div><br></div><div><span class="" style="white-space:pre">        </span>>>>><span class="" style="white-space:pre">  </span></div><div><br></div><div><span class="" style="white-space:pre">  </span>> 0 <<span class="" style="white-space:pre">       </span></div><div>* 0<span class="" style="white-space:pre">        </span>* 1<span class="" style="white-space:pre">       </span>* 2<span class="" style="white-space:pre">       </span>* 3 </div></div><div>* PROGRAM</div><div><div>#include <malloc.h></div><div>#include <stdlib.h></div><div>#include <stdio.h></div><div>#include <time.h></div><div>#include "math.h"</div><div>#include "mpi.h"</div><div><br></div><div>int main(int argc, char** argv)</div><div>{</div><div><span class="" style="white-space:pre">    </span>int          taskid, ntasks;</div><div><span class="" style="white-space:pre">      </span>int          ierr, i, itask;</div><div><span class="" style="white-space:pre">      </span>int<span class="" style="white-space:pre">       </span>         sendcounts[2048], displs[2048], recvcount;</div><div><span class="" style="white-space:pre">       </span>double       **sendbuff, *recvbuff, buffsum, buffsums[2048];</div><div><span class="" style="white-space:pre">        </span>double       inittime, totaltime;</div><div><span class="" style="white-space:pre">   </span>const int nbr_etat = 10;</div><div><span class="" style="white-space:pre">   </span>double tab[nbr_etat];</div><div><br></div><div><span class="" style="white-space:pre">     </span>for (int i = 0; i < nbr_etat; i++)</div><div><span class="" style="white-space:pre">              </span>tab[i] = i;</div><div><br></div><div><span class="" style="white-space:pre">       </span>for (int i = 0; i < nbr_etat; i++)</div><div><span class="" style="white-space:pre">              </span>printf("%0.0f<span class="" style="white-space:pre">        </span>", tab[i]);</div><div><span class="" style="white-space:pre">   </span>printf("\n");</div><div><span class="" style="white-space:pre">    </span>int nbr_elm[2] = { 4, 6 };</div><div><span class="" style="white-space:pre"> </span>int dpl[2] = { 0, 4 };</div><div><br></div><div><span class="" style="white-space:pre">    </span>MPI_Init(&argc, &argv);</div><div><span class="" style="white-space:pre">    </span>MPI_Comm_rank(MPI_COMM_WORLD, &taskid);</div><div><span class="" style="white-space:pre">        </span>MPI_Comm_size(MPI_COMM_WORLD, &ntasks);</div><div><br></div><div><br></div><div><span class="" style="white-space:pre">      </span>recvbuff = (double *)malloc(sizeof(double)*nbr_etat);</div><div><span class="" style="white-space:pre">      </span>if (taskid == 0)</div><div><span class="" style="white-space:pre">   </span>{</div><div><span class="" style="white-space:pre">          </span>sendbuff = (double **)malloc(sizeof(double *)*ntasks);// on execute pour deux proc</div><div><span class="" style="white-space:pre">         </span>sendbuff[0] = (double *)malloc(sizeof(double)*ntasks*nbr_etat);</div><div><span class="" style="white-space:pre">            </span>for (i = 1; i < ntasks; i++)</div><div><span class="" style="white-space:pre">            </span>{</div><div><span class="" style="white-space:pre">                  </span>sendbuff[i] = sendbuff[i - 1] + nbr_etat;</div><div><span class="" style="white-space:pre">              </span>}</div><div><span class="" style="white-space:pre">  </span>}</div><div><span class="" style="white-space:pre">  </span>else</div><div><span class="" style="white-space:pre">       </span>{</div><div><span class="" style="white-space:pre">          </span>sendbuff = (double **)malloc(sizeof(double *)* 1);</div><div><span class="" style="white-space:pre">         </span>sendbuff[0] = (double *)malloc(sizeof(double)* 1);</div><div><span class="" style="white-space:pre"> </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span>if (taskid == 0){</div><div><br></div><div><br></div><div><br></div><div><br></div><div><span class="" style="white-space:pre">              </span>srand((unsigned)time(NULL) + taskid);</div><div><span class="" style="white-space:pre">          </span>for (itask = 0; itask<ntasks; itask++)</div><div><span class="" style="white-space:pre">          </span>{</div><div><span class="" style="white-space:pre">                  </span>int k;</div><div><span class="" style="white-space:pre">                     </span>displs[itask] = dpl[itask];</div><div><span class="" style="white-space:pre">                        </span>int s = displs[itask];</div><div><span class="" style="white-space:pre">                     </span>sendcounts[itask] = nbr_elm[itask];</div><div><span class="" style="white-space:pre">                </span></div><div><br></div><div><span class="" style="white-space:pre">                  </span>for (i = 0; i<sendcounts[itask]; i++)</div><div><span class="" style="white-space:pre">                   </span>{</div><div><span class="" style="white-space:pre">                          </span>k = i + s;</div><div><span class="" style="white-space:pre">                             </span>sendbuff[itask][i] = tab[k];</div><div><span class="" style="white-space:pre">                               </span>printf("%0.0f  ", sendbuff[itask][i]);</div><div><span class="" style="white-space:pre">                      </span>}</div><div><span class="" style="white-space:pre">                  </span>printf("\n");</div><div><span class="" style="white-space:pre">            </span>}</div><div><br></div><div><br></div><div><span class="" style="white-space:pre">        </span>}</div><div><br></div><div><br></div><div><span class="" style="white-space:pre">        </span>recvcount = nbr_elm[taskid];</div><div><br></div><div><span class="" style="white-space:pre">      </span>inittime = MPI_Wtime();</div><div><br></div><div><span class="" style="white-space:pre">   </span>ierr = MPI_Scatterv(sendbuff[0], sendcounts, displs, MPI_DOUBLE,</div><div><span class="" style="white-space:pre">           </span>recvbuff, recvcount, MPI_DOUBLE,</div><div><span class="" style="white-space:pre">           </span>0, MPI_COMM_WORLD);</div><div><br></div><div><span class="" style="white-space:pre">       </span>totaltime = MPI_Wtime() - inittime;</div><div>                            </div><div><span class="" style="white-space:pre">  </span>printf("\n<span class="" style="white-space:pre">   </span>>>>><span class="" style="white-space:pre">  </span>\n");</div><div><span class="" style="white-space:pre"> </span>buffsum = 0.0;</div><div><span class="" style="white-space:pre">     </span>printf("\n<span class="" style="white-space:pre">   </span>> %d <<span class="" style="white-space:pre">      </span>\n",taskid);</div><div><span class="" style="white-space:pre">  </span>for (i = 0; i<recvcount; i++)</div><div><span class="" style="white-space:pre">   </span>{<span class="" style="white-space:pre"> </span></div><div><span class="" style="white-space:pre">   </span>printf("* %0.0f<span class="" style="white-space:pre">      </span>", recvbuff[i]);</div><div><span class="" style="white-space:pre">      </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span>printf("\n");                                  </div><div><span class="" style="white-space:pre">     </span>if (taskid == 0){</div><div><span class="" style="white-space:pre">          </span>free(sendbuff[0]);</div><div><span class="" style="white-space:pre">         </span>free(sendbuff);</div><div><span class="" style="white-space:pre">    </span>}</div><div><span class="" style="white-space:pre">  </span>else{</div><div><span class="" style="white-space:pre">              </span>free(sendbuff[0]);</div><div><span class="" style="white-space:pre">         </span>free(sendbuff);</div><div><span class="" style="white-space:pre">            </span>free(recvbuff);</div><div><span class="" style="white-space:pre">    </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span>/*===============================================================*/</div><div><span class="" style="white-space:pre">        </span>/* Finalisation de MPI                                           */</div><div><span class="" style="white-space:pre">       </span>MPI_Finalize();</div><div><br></div><div>}</div></div><div><br></div></div>