Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Also include hostfile into the archive since makecheck needs that
[simgrid.git] / examples / smpi / alltoall2.c
index ae47160..0b1c918 100644 (file)
 
 #define MAXLEN 10000
  
-void main()
+int main( int argc, char *argv[] )
 {
-   int out[1000000],in[1000000],i,j,k;
+#define N 1000000
+   int *out, *in,i,j,k;
    int myself,tasks;
  
-   MPI_Init(0,0);
+   out = malloc(N*sizeof(int));
+   in  = malloc(N*sizeof(int));
+   if ((out==NULL) || (in==NULL)) {
+           printf("Error: cannot allocate N bytes for in or out arrays\n");
+           exit(1);
+   }
+   MPI_Init( &argc,&argv );
    MPI_Comm_rank(MPI_COMM_WORLD,&myself);
    MPI_Comm_size(MPI_COMM_WORLD,&tasks);
    for(j=1;j<=MAXLEN;j*=10)  {
-      for(i=0;i<j*tasks;i++)  out[i] = myself;
-      MPI_Alltoall(out,j,MPI_INT,in,j,MPI_INT,MPI_COMM_WORLD);
-      for(i=0;i<tasks;i++)  {
-         for(k=0;k<j;k++) {
-            if(in[k+i*j] != i) {  printf("bad answer (%d) at index %d of %d (should be %d)\n",in[k+i*j],k+i*j,j*tasks,i); break; }
-         }
-      }
+           if ( 0 == myself ) {
+                   printf("* calling MPI_Alltoall with buffers of %d ints\n",j);
+           }
+           for(i=0;i<j*tasks;i++)  
+                   out[i] = myself;
+
+           MPI_Alltoall(out,j,MPI_INT,in,j,MPI_INT,MPI_COMM_WORLD);
+
+           for(i=0;i<tasks;i++)  {
+                   for(k=0;k<j;k++) {
+                           if(in[k+i*j] != i) {  
+                                   printf("<%d> bad answer (%d) at index %d of %d (should be %d)\n",myself,in[k+i*j],k+i*j,j*tasks,i); 
+                                   break; 
+                           }
+                   }
+           }
    }
    MPI_Barrier(MPI_COMM_WORLD);
    if(myself==0)  printf("TEST COMPLETE\n");