Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix dist
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / coll2.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 #include "mpicolltest.h"
10
11 #define MAX_PROCESSES 10
12
13 int main(int argc, char **argv)
14 {
15     int rank, size, i, j;
16     int table[MAX_PROCESSES][MAX_PROCESSES];
17     int errors = 0;
18     int participants;
19
20     MTest_Init(&argc, &argv);
21     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
22     MPI_Comm_size(MPI_COMM_WORLD, &size);
23
24     /* A maximum of MAX_PROCESSES processes can participate */
25     if (size > MAX_PROCESSES)
26         participants = MAX_PROCESSES;
27     else
28         participants = size;
29
30     if (MAX_PROCESSES % participants) {
31         fprintf(stderr, "Number of processors must divide %d\n", MAX_PROCESSES);
32         MPI_Abort(MPI_COMM_WORLD, 1);
33     }
34     if ((rank < participants)) {
35
36         /* Determine what rows are my responsibility */
37         int block_size = MAX_PROCESSES / participants;
38         int begin_row = rank * block_size;
39         int end_row = (rank + 1) * block_size;
40         int send_count = block_size * MAX_PROCESSES;
41         int recv_count = send_count;
42
43         /* Paint my rows my color */
44         for (i = begin_row; i < end_row; i++)
45             for (j = 0; j < MAX_PROCESSES; j++)
46                 table[i][j] = rank + 10;
47
48         /* Gather everybody's result together - sort of like an */
49         /* inefficient allgather */
50         for (i = 0; i < participants; i++) {
51             void *sendbuf = (i == rank ? MPI_IN_PLACE : &table[begin_row][0]);
52             MTest_Gather(sendbuf, send_count, MPI_INT,
53                          &table[0][0], recv_count, MPI_INT, i, MPI_COMM_WORLD);
54         }
55
56         /* Everybody should have the same table now,  */
57         /* This test does not in any way guarantee there are no errors */
58         /* Print out a table or devise a smart test to make sure it's correct */
59         for (i = 0; i < MAX_PROCESSES; i++) {
60             if ((table[i][0] - table[i][MAX_PROCESSES - 1] != 0))
61                 errors++;
62         }
63     }
64
65     MTest_Finalize(errors);
66     MPI_Finalize();
67     return MTestReturnValue(errors);
68 }