Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove warning with mc
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / coll4.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 <stdio.h>
8 #include "mpitest.h"
9
10 #define MAX_PROCESSES 10
11
12 int main( int argc, char **argv )
13 {
14     int              rank, size, i,j;
15     int              table[MAX_PROCESSES][MAX_PROCESSES];
16     int              row[MAX_PROCESSES];
17     int              errors=0;
18     int              participants;
19     MPI_Comm         comm;
20
21     MTest_Init( &argc, &argv );
22     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
23     MPI_Comm_size( MPI_COMM_WORLD, &size );
24
25     comm = MPI_COMM_WORLD;
26
27     /* A maximum of MAX_PROCESSES processes can participate */
28     if ( size > MAX_PROCESSES ) {
29         participants = MAX_PROCESSES;
30         MPI_Comm_split( MPI_COMM_WORLD, rank < MAX_PROCESSES, rank, &comm );
31     }
32     else  {
33         participants = size;
34         MPI_Comm_dup( MPI_COMM_WORLD, &comm );
35     }
36     if ( (rank < participants) ) {
37         int send_count = MAX_PROCESSES;
38         int recv_count = MAX_PROCESSES;
39
40         /* If I'm the root (process 0), then fill out the big table */
41         if (rank == 0) 
42             for ( i=0; i<participants; i++) 
43                 for ( j=0; j<MAX_PROCESSES; j++ ) 
44                     table[i][j] = i+j;
45         
46         /* Scatter the big table to everybody's little table */
47         MPI_Scatter(&table[0][0], send_count, MPI_INT, 
48                     &row[0]     , recv_count, MPI_INT, 0, comm );
49         
50         /* Now see if our row looks right */
51         for (i=0; i<MAX_PROCESSES; i++) 
52             if ( row[i] != i+rank ) errors++;
53     } 
54     
55     MPI_Comm_free( &comm );
56
57     MTest_Finalize( errors );
58     MPI_Finalize();
59     return MTestReturnValue( errors );
60 }