Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove warning with mc
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / scattern.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 #include <stdlib.h>
8 #include <stdio.h>
9
10 /* This example sends a vector and receives individual elements */
11
12 int main( int argc, char **argv )
13 {
14     MPI_Datatype vec;
15     double *vecin, *vecout, ivalue;
16     int    root, i, n, stride, err = 0;
17     int    rank, size;
18
19     MPI_Init( &argc, &argv );
20     
21     MPI_Comm_size( MPI_COMM_WORLD, &size );
22     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
23
24     n = 12;
25     stride = 10;
26     vecin = (double *)malloc( n * stride * size * sizeof(double) );
27     vecout = (double *)malloc( n * sizeof(double) );
28     
29     MPI_Type_vector( n, 1, stride, MPI_DOUBLE, &vec );
30     MPI_Type_commit( &vec );
31
32     for (i=0; i<n*stride*size; i++) vecin[i] = (double)i;
33     for (root=0; root<size; root++) {
34         for (i=0; i<n; i++) vecout[i] = -1.0;
35         MPI_Scatter( vecin, 1, vec, vecout, n, MPI_DOUBLE, root, 
36                      MPI_COMM_WORLD );
37         ivalue = rank * ((n-1) * stride + 1);
38         for (i=0; i<n; i++) {
39             if (vecout[i] != ivalue) {
40                 printf( "Expected %f but found %f\n", 
41                         ivalue, vecout[i] );
42                 err++;
43             }
44             ivalue += stride;
45         }
46     }
47     i = err;
48     MPI_Allreduce( &i, &err, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
49     if (rank == 0) {
50         if (err > 0) printf( "Found %d errors!\n", err );
51         else         printf( " No Errors\n" );
52     }
53     MPI_Type_free( &vec );
54     MPI_Finalize();
55     return 0;
56        
57 }
58