|
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 |
|
|
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 row[MAX_PROCESSES];
|
|
Packit |
0848f5 |
int errors = 0;
|
|
Packit |
0848f5 |
int participants;
|
|
Packit |
0848f5 |
MPI_Comm comm;
|
|
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 |
comm = MPI_COMM_WORLD;
|
|
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 |
MPI_Comm_split(MPI_COMM_WORLD, rank < MAX_PROCESSES, rank, &comm);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
participants = size;
|
|
Packit |
0848f5 |
MPI_Comm_dup(MPI_COMM_WORLD, &comm);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if ((rank < participants)) {
|
|
Packit |
0848f5 |
int send_count = MAX_PROCESSES;
|
|
Packit |
0848f5 |
int recv_count = MAX_PROCESSES;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* If I'm the root (process 0), then fill out the big table */
|
|
Packit |
0848f5 |
if (rank == 0)
|
|
Packit |
0848f5 |
for (i = 0; i < participants; i++)
|
|
Packit |
0848f5 |
for (j = 0; j < MAX_PROCESSES; j++)
|
|
Packit |
0848f5 |
table[i][j] = i + j;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* Scatter the big table to everybody's little table */
|
|
Packit |
0848f5 |
MPI_Scatter(&table[0][0], send_count, MPI_INT, &row[0], recv_count, MPI_INT, 0, comm);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* Now see if our row looks right */
|
|
Packit |
0848f5 |
for (i = 0; i < MAX_PROCESSES; i++)
|
|
Packit |
0848f5 |
if (row[i] != i + rank)
|
|
Packit |
0848f5 |
errors++;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Comm_free(&comm);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Finalize(errors);
|
|
Packit |
0848f5 |
MPI_Finalize();
|
|
Packit |
0848f5 |
return MTestReturnValue(errors);
|
|
Packit |
0848f5 |
}
|