|
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 row[MAX_PROCESSES];
|
|
Packit Service |
c5cf8c |
int errors = 0;
|
|
Packit Service |
c5cf8c |
int participants;
|
|
Packit Service |
c5cf8c |
int displs[MAX_PROCESSES];
|
|
Packit Service |
c5cf8c |
int send_counts[MAX_PROCESSES];
|
|
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 ((rank < participants)) {
|
|
Packit Service |
c5cf8c |
int recv_count = MAX_PROCESSES;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* If I'm the root (process 0), then fill out the big table */
|
|
Packit Service |
c5cf8c |
/* and setup send_counts and displs arrays */
|
|
Packit Service |
c5cf8c |
if (rank == 0)
|
|
Packit Service |
c5cf8c |
for (i = 0; i < participants; i++) {
|
|
Packit Service |
c5cf8c |
send_counts[i] = recv_count;
|
|
Packit Service |
c5cf8c |
displs[i] = i * MAX_PROCESSES;
|
|
Packit Service |
c5cf8c |
for (j = 0; j < MAX_PROCESSES; j++)
|
|
Packit Service |
c5cf8c |
table[i][j] = i + j;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Scatter the big table to everybody's little table */
|
|
Packit Service |
c5cf8c |
MPI_Scatterv(&table[0][0], send_counts, displs, MPI_INT,
|
|
Packit Service |
c5cf8c |
&row[0], recv_count, MPI_INT, 0, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Now see if our row looks right */
|
|
Packit Service |
c5cf8c |
for (i = 0; i < MAX_PROCESSES; i++)
|
|
Packit Service |
c5cf8c |
if (row[i] != i + rank)
|
|
Packit Service |
c5cf8c |
errors++;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Finalize(errors);
|
|
Packit Service |
c5cf8c |
return MTestReturnValue(errors);
|
|
Packit Service |
c5cf8c |
}
|