|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2008 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Test from Edric Ellis
|
|
Packit Service |
c5cf8c |
To launch,
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Run multiple copies of "testconnect" should be run something like this:
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Path/to/testconnect /full/path/to/shared/file N
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
where each instance has one process and N instances are run
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#include "mpi.h"
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
#include <signal.h>
|
|
Packit Service |
c5cf8c |
#include <stdlib.h>
|
|
Packit Service |
c5cf8c |
#include <unistd.h>
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
char *fname;
|
|
Packit Service |
c5cf8c |
int cachedRank = -1;
|
|
Packit Service |
c5cf8c |
MPI_Comm comm;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
void term_handler(int);
|
|
Packit Service |
c5cf8c |
void segv_handler(int);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
void term_handler(int sig)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
if (sig) {
|
|
Packit Service |
c5cf8c |
printf("Saw signal %d\n", sig);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
printf("removing file: %s\n", fname);
|
|
Packit Service |
c5cf8c |
fflush(stdout);
|
|
Packit Service |
c5cf8c |
unlink(fname);
|
|
Packit Service |
c5cf8c |
if (sig != 0) {
|
|
Packit Service |
c5cf8c |
MPI_Abort(comm, 42);
|
|
Packit Service |
c5cf8c |
exit(0);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
void segv_handler(int sig)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
printf("SEGV detected!\n");
|
|
Packit Service |
c5cf8c |
fflush(stdout);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char **argv)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
MPI_Comm tmp;
|
|
Packit Service |
c5cf8c |
int size = 0;
|
|
Packit Service |
c5cf8c |
char portName[MPI_MAX_PORT_NAME];
|
|
Packit Service |
c5cf8c |
char *port = &portName[0];
|
|
Packit Service |
c5cf8c |
int doPrint = 1;
|
|
Packit Service |
c5cf8c |
int totalSize = 0;
|
|
Packit Service |
c5cf8c |
int myNum = -1;
|
|
Packit Service |
c5cf8c |
FILE *fh;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (argc < 4) {
|
|
Packit Service |
c5cf8c |
printf("Please call with a filename for the port\n");
|
|
Packit Service |
c5cf8c |
exit(1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
fname = argv[1];
|
|
Packit Service |
c5cf8c |
totalSize = atoi(argv[2]);
|
|
Packit Service |
c5cf8c |
if (argv[3])
|
|
Packit Service |
c5cf8c |
myNum = atoi(argv[3]);
|
|
Packit Service |
c5cf8c |
printf("[%d] Waiting for: %d\n", myNum, totalSize);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Init(0, 0);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* the existance of the file is used to decide which processes
|
|
Packit Service |
c5cf8c |
* first do a connect to the root process. */
|
|
Packit Service |
c5cf8c |
fh = fopen(fname, "rt");
|
|
Packit Service |
c5cf8c |
if (fh == NULL) {
|
|
Packit Service |
c5cf8c |
fh = fopen(fname, "wt");
|
|
Packit Service |
c5cf8c |
MPI_Open_port(MPI_INFO_NULL, portName);
|
|
Packit Service |
c5cf8c |
port = portName;
|
|
Packit Service |
c5cf8c |
fprintf(fh, "%s\n", portName);
|
|
Packit Service |
c5cf8c |
fclose(fh);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (doPrint) {
|
|
Packit Service |
c5cf8c |
printf("[%d] Wrote port %s to %s\n", myNum, port, fname);
|
|
Packit Service |
c5cf8c |
fflush(stdout);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
comm = MPI_COMM_WORLD;
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
char *cerr;
|
|
Packit Service |
c5cf8c |
cerr = fgets(port, MPI_MAX_PORT_NAME, fh);
|
|
Packit Service |
c5cf8c |
fclose(fh);
|
|
Packit Service |
c5cf8c |
if (doPrint) {
|
|
Packit Service |
c5cf8c |
printf("[%d] about to connect: Port from %s is: %s\n", myNum, fname, port);
|
|
Packit Service |
c5cf8c |
fflush(stdout);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPI_Comm_connect(port, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &tmp);
|
|
Packit Service |
c5cf8c |
if (doPrint) {
|
|
Packit Service |
c5cf8c |
printf("[%d] connect-side: about to perform intercomm merge\n", myNum);
|
|
Packit Service |
c5cf8c |
fflush(stdout);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPI_Intercomm_merge(tmp, 1, &comm);
|
|
Packit Service |
c5cf8c |
if (doPrint) {
|
|
Packit Service |
c5cf8c |
printf("[%d] connect-side: intercomm merge complete\n", myNum);
|
|
Packit Service |
c5cf8c |
fflush(stdout);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPI_Comm_free(&tmp);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(comm, &size);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
while (size < totalSize) {
|
|
Packit Service |
c5cf8c |
MPI_Comm_accept(port, MPI_INFO_NULL, 0, comm, &tmp);
|
|
Packit Service |
c5cf8c |
if (doPrint) {
|
|
Packit Service |
c5cf8c |
printf("[%d] accept-side: about to perform intercomm merge\n", myNum);
|
|
Packit Service |
c5cf8c |
fflush(stdout);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPI_Intercomm_merge(tmp, 0, &comm);
|
|
Packit Service |
c5cf8c |
if (doPrint) {
|
|
Packit Service |
c5cf8c |
printf("[%d] accept-side: about to perform intercomm merge\n", myNum);
|
|
Packit Service |
c5cf8c |
fflush(stdout);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(comm, &cachedRank);
|
|
Packit Service |
c5cf8c |
MPI_Comm_free(&tmp);
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(comm, &size);
|
|
Packit Service |
c5cf8c |
if (doPrint) {
|
|
Packit Service |
c5cf8c |
printf("[%d] Size of comm is %d\n", myNum, size);
|
|
Packit Service |
c5cf8c |
fflush(stdout);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
printf("[%d] All done.\n", myNum);
|
|
Packit Service |
c5cf8c |
fflush(stdout);
|
|
Packit Service |
c5cf8c |
term_handler(0);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Finalize();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
return 0;
|
|
Packit Service |
c5cf8c |
}
|