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