Blame test/mpi/coll/coll2.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *  (C) 2001 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
#include "mpi.h"
Packit 0848f5
#include <stdio.h>
Packit 0848f5
#include "mpitest.h"
Packit 0848f5
#include "mpicolltest.h"
Packit 0848f5
Packit 0848f5
#define MAX_PROCESSES 10
Packit 0848f5
Packit 0848f5
int main(int argc, char **argv)
Packit 0848f5
{
Packit 0848f5
    int rank, size, i, j;
Packit 0848f5
    int table[MAX_PROCESSES][MAX_PROCESSES];
Packit 0848f5
    int errors = 0;
Packit 0848f5
    int participants;
Packit 0848f5
Packit 0848f5
    MTest_Init(&argc, &argv);
Packit 0848f5
    MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
Packit 0848f5
    MPI_Comm_size(MPI_COMM_WORLD, &size);
Packit 0848f5
Packit 0848f5
    /* A maximum of MAX_PROCESSES processes can participate */
Packit 0848f5
    if (size > MAX_PROCESSES)
Packit 0848f5
        participants = MAX_PROCESSES;
Packit 0848f5
    else
Packit 0848f5
        participants = size;
Packit 0848f5
Packit 0848f5
    if (MAX_PROCESSES % participants) {
Packit 0848f5
        fprintf(stderr, "Number of processors must divide %d\n", MAX_PROCESSES);
Packit 0848f5
        MPI_Abort(MPI_COMM_WORLD, 1);
Packit 0848f5
    }
Packit 0848f5
    if ((rank < participants)) {
Packit 0848f5
Packit 0848f5
        /* Determine what rows are my responsibility */
Packit 0848f5
        int block_size = MAX_PROCESSES / participants;
Packit 0848f5
        int begin_row = rank * block_size;
Packit 0848f5
        int end_row = (rank + 1) * block_size;
Packit 0848f5
        int send_count = block_size * MAX_PROCESSES;
Packit 0848f5
        int recv_count = send_count;
Packit 0848f5
Packit 0848f5
        /* Paint my rows my color */
Packit 0848f5
        for (i = begin_row; i < end_row; i++)
Packit 0848f5
            for (j = 0; j < MAX_PROCESSES; j++)
Packit 0848f5
                table[i][j] = rank + 10;
Packit 0848f5
Packit 0848f5
        /* Gather everybody's result together - sort of like an */
Packit 0848f5
        /* inefficient allgather */
Packit 0848f5
        for (i = 0; i < participants; i++) {
Packit 0848f5
            void *sendbuf = (i == rank ? MPI_IN_PLACE : &table[begin_row][0]);
Packit 0848f5
            MTest_Gather(sendbuf, send_count, MPI_INT,
Packit 0848f5
                         &table[0][0], recv_count, MPI_INT, i, MPI_COMM_WORLD);
Packit 0848f5
        }
Packit 0848f5
Packit 0848f5
        /* Everybody should have the same table now,  */
Packit 0848f5
        /* This test does not in any way guarantee there are no errors */
Packit 0848f5
        /* Print out a table or devise a smart test to make sure it's correct */
Packit 0848f5
        for (i = 0; i < MAX_PROCESSES; i++) {
Packit 0848f5
            if ((table[i][0] - table[i][MAX_PROCESSES - 1] != 0))
Packit 0848f5
                errors++;
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MTest_Finalize(errors);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return MTestReturnValue(errors);
Packit 0848f5
}