From eaf71a2e7455965a18e78325885b97770c1488ec Mon Sep 17 00:00:00 2001 From: Rolf vandeVaart Date: Wed, 28 Feb 2007 21:38:02 +0000 Subject: [PATCH] Add simple test that sends a message between all the ranks in the job. Useful to prove a cluster is up and working. Reviewed by Jeff Squyres. This commit was SVN r13857. --- examples/Makefile | 6 ++-- examples/Makefile.include | 4 ++- examples/connectivity_c.c | 67 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 examples/connectivity_c.c diff --git a/examples/Makefile b/examples/Makefile index 83121e0cb2..321fd9a8a7 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -9,7 +9,7 @@ # University of Stuttgart. All rights reserved. # Copyright (c) 2004-2005 The Regents of the University of California. # All rights reserved. -# Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. +# Copyright (c) 2006-2007 Sun Microsystems, Inc. All rights reserved. # $COPYRIGHT$ # # Additional copyrights may follow @@ -41,12 +41,12 @@ FCFLAGS = -g # Example programs to build EXAMPLES = hello_c hello_cxx hello_f77 hello_f90 \ - ring_c ring_cxx ring_f77 ring_f90 + ring_c ring_cxx ring_f77 ring_f90 connectivity_c # Default target. Always build the C example. Only build the others # if Open MPI was build with the relevant language bindings. -all: hello_c ring_c +all: hello_c ring_c connectivity_c @ if test "`ompi_info --parsable | grep bindings:cxx:yes`" != ""; then \ $(MAKE) hello_cxx ring_cxx; \ fi diff --git a/examples/Makefile.include b/examples/Makefile.include index 679e63c48d..724ccdf605 100644 --- a/examples/Makefile.include +++ b/examples/Makefile.include @@ -11,6 +11,7 @@ # Copyright (c) 2004-2005 The Regents of the University of California. # All rights reserved. # Copyright (c) 2006 Cisco Systems, Inc. All rights reserved. +# Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. # $COPYRIGHT$ # # Additional copyrights may follow @@ -37,4 +38,5 @@ EXTRA_DIST += \ examples/ring_c.c \ examples/ring_cxx.cc \ examples/ring_f77.f \ - examples/ring_f90.f90 + examples/ring_f90.f90 \ + examples/connectivity_c.c diff --git a/examples/connectivity_c.c b/examples/connectivity_c.c new file mode 100644 index 0000000000..f52c8a301a --- /dev/null +++ b/examples/connectivity_c.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. + */ + +/* + * Test the connectivity between all processes. + */ + +#include +#include +#include +#include +#include +#include +#include + +int +main(int argc, char **argv) +{ + MPI_Status status; + int verbose = 0; + int rank; + int np; /* number of processes in job */ + int peer; + int i; + int j; + int length; + char name[MPI_MAX_PROCESSOR_NAME+1]; + + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &np); + + /* + * If we cannot get the name for whatever reason, just + * set it to unknown. */ + if (MPI_SUCCESS != MPI_Get_processor_name(name, &length)) { + strcpy(name, "unknown"); + } + + if (argc>1 && strcmp(argv[1], "-v")==0) + verbose = 1; + + for (i=0; ii) { + /* receive from and reply to rank i */ + MPI_Recv(&peer, 1, MPI_INT, i, i, MPI_COMM_WORLD, &status); + MPI_Send(&rank, 1, MPI_INT, i, rank, MPI_COMM_WORLD); + } + } + + MPI_Barrier(MPI_COMM_WORLD); + if (rank==0) + printf("Connectivity test on %d processes PASSED.\n", np); + + MPI_Finalize(); + return 0; +}