|
Packit |
0848f5 |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
*
|
|
Packit |
0848f5 |
* (C) 2003 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 |
/*
|
|
Packit |
0848f5 |
static char MTEST_Descrip[] = "Test of broadcast with various roots and datatypes";
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int main(int argc, char *argv[])
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
int errs = 0, err;
|
|
Packit |
0848f5 |
int rank, size, root;
|
|
Packit |
0848f5 |
int minsize = 2, count;
|
|
Packit |
0848f5 |
MPI_Comm comm;
|
|
Packit |
0848f5 |
MTestDatatype sendtype, recvtype;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Init(&argc, &argv);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* The following illustrates the use of the routines to
|
|
Packit |
0848f5 |
* run through a selection of communicators and datatypes.
|
|
Packit |
0848f5 |
* Use subsets of these for tests that do not involve combinations
|
|
Packit |
0848f5 |
* of communicators, datatypes, and counts of datatypes */
|
|
Packit |
0848f5 |
while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
|
|
Packit |
0848f5 |
if (comm == MPI_COMM_NULL)
|
|
Packit |
0848f5 |
continue;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
#if defined BCAST_COMM_WORLD_ONLY
|
|
Packit |
0848f5 |
if (comm != MPI_COMM_WORLD) {
|
|
Packit |
0848f5 |
MTestFreeComm(&comm);
|
|
Packit |
0848f5 |
continue;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
#endif /* BCAST_COMM_WORLD_ONLY */
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* Determine the sender and receiver */
|
|
Packit |
0848f5 |
MPI_Comm_rank(comm, &rank;;
|
|
Packit |
0848f5 |
MPI_Comm_size(comm, &size);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* To improve reporting of problems about operations, we
|
|
Packit |
0848f5 |
* change the error handler to errors return */
|
|
Packit |
0848f5 |
MPI_Errhandler_set(comm, MPI_ERRORS_RETURN);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTEST_DATATYPE_FOR_EACH_COUNT(count) {
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* To shorten test time, only run the default version of datatype tests
|
|
Packit |
0848f5 |
* for comm world and run the minimum version for other communicators. */
|
|
Packit |
0848f5 |
#if defined BCAST_MIN_DATATYPES_ONLY
|
|
Packit |
0848f5 |
MTestInitMinDatatypes();
|
|
Packit |
0848f5 |
#endif /* BCAST_MIN_DATATYPES_ONLY */
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
|
|
Packit |
0848f5 |
for (root = 0; root < size; root++) {
|
|
Packit |
0848f5 |
if (rank == root) {
|
|
Packit |
0848f5 |
sendtype.InitBuf(&sendtype);
|
|
Packit |
0848f5 |
err = MPI_Bcast(sendtype.buf, sendtype.count,
|
|
Packit |
0848f5 |
sendtype.datatype, root, comm);
|
|
Packit |
0848f5 |
if (err) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
MTestPrintError(err);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
recvtype.InitBuf(&recvtype);
|
|
Packit |
0848f5 |
err = MPI_Bcast(recvtype.buf, recvtype.count,
|
|
Packit |
0848f5 |
recvtype.datatype, root, comm);
|
|
Packit |
0848f5 |
if (err) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "Error with communicator %s and datatype %s\n",
|
|
Packit |
0848f5 |
MTestGetIntracommName(), MTestGetDatatypeName(&recvtype));
|
|
Packit |
0848f5 |
MTestPrintError(err);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
err = MTestCheckRecv(0, &recvtype);
|
|
Packit |
0848f5 |
if (err) {
|
|
Packit |
0848f5 |
errs += errs;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
MTestFreeDatatype(&recvtype);
|
|
Packit |
0848f5 |
MTestFreeDatatype(&sendtype);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
MTestFreeComm(&comm);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Finalize(errs);
|
|
Packit |
0848f5 |
MPI_Finalize();
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|