parallel processing - MPI: all to all broadcast on one dimensional array -


i have number of processors , 1 array, , each processor fills work into, 1 dimensional array like:

  • dense_process_array process 1: |process1|0000000000000|
  • dense_process_array process 2: |000000|process2|000000|

each process fills interval, want processors have others results same array.

  • process 1 => dense_process_array |process1|process2|.....|processn|
  • process 2 ... process n

(like all2all bcast) therefore, every process calls function:

void docommunication(int id, int numprocs, int start_point, int end_point) {     int size_of_length = end_point - start_point + 1;     mpi_scatter(dense_process_array+start_point, size_of_length, mpi_double, dense _process_array +start_point, size_of_length, mpi_double, id, mpi_comm_world;                                                                                                                                                                                                                                                                              } 

but, in end when looked array process, seen can not results of other processes, can suggest anything?

not: i'm new in mpi, , basicly want all2all bcast.

i believe you're looking mpi_allgather:

#include <stdio.h> #include <stdlib.h> #include <mpi.h>  void printdata(int size, int rank, int n, int *data) {     printf("rank %d\n",rank);     (int j=0; j<size*n; j++)         printf("%d ",data[j]);     printf("\n"); }  int main(int argc, char **argv) {     const int n=3;     int ierr, rank, size;     int *datain, *dataout;      ierr = mpi_init(&argc, &argv);     ierr|= mpi_comm_size(mpi_comm_world,&size);     ierr|= mpi_comm_rank(mpi_comm_world,&rank);      datain = (int *)malloc(n*size*sizeof(int));     dataout = (int *)malloc(n*size*sizeof(int));     (int i=0; i<n*size; i++)         datain[i]=9;     (int i=0; i<n; i++)         datain[rank*n+i]=rank;      if (rank == 0) printf("before:\n");     printdata(size, rank, n, datain);      mpi_allgather(&(datain[rank*n]), n, mpi_int, dataout, n, mpi_int, mpi_comm_world);      if (rank == 0) printf("after:\n");     printdata(size, rank, n, dataout);      free(datain);     free(dataout);     mpi_finalize();     return 0; } 

running gives

$ mpirun -np 3 ./allgather before: rank 0 0 0 0 9 9 9 9 9 9  rank 1 9 9 9 1 1 1 9 9 9  rank 2 9 9 9 9 9 9 2 2 2  after: rank 0 0 0 0 1 1 1 2 2 2  rank 1 0 0 0 1 1 1 2 2 2  rank 2 0 0 0 1 1 1 2 2 2  

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -