1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2001 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
9 #include "mpicolltest.h"
11 #define MAX_PROCESSES 10
13 int main(int argc, char **argv)
16 int table[MAX_PROCESSES][MAX_PROCESSES];
20 MTest_Init(&argc, &argv);
21 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
22 MPI_Comm_size(MPI_COMM_WORLD, &size);
24 /* A maximum of MAX_PROCESSES processes can participate */
25 if (size > MAX_PROCESSES)
26 participants = MAX_PROCESSES;
30 if (MAX_PROCESSES % participants) {
31 fprintf(stderr, "Number of processors must divide %d\n", MAX_PROCESSES);
32 MPI_Abort(MPI_COMM_WORLD, 1);
34 if ((rank < participants)) {
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;
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;
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);
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))
65 MTest_Finalize(errors);
67 return MTestReturnValue(errors);