diff options
author | goodale <goodale@61ea717e-8e0c-4c3c-b38e-e9c67f54f1f1> | 2000-11-08 06:15:17 +0000 |
---|---|---|
committer | goodale <goodale@61ea717e-8e0c-4c3c-b38e-e9c67f54f1f1> | 2000-11-08 06:15:17 +0000 |
commit | dd49a1d7a2be2f622f656cba118a8e91716e81ac (patch) | |
tree | 33fb361ec926f1ec8c8a311939227e0fdb723197 | |
parent | eab0002a95addb6f61fee182edde617bd6d516cd (diff) |
Routines to collect data about al hosts in cactus run.
Tom
git-svn-id: http://svn.cactuscode.org/arrangements/CactusConnect/HTTPDExtra/trunk@17 61ea717e-8e0c-4c3c-b38e-e9c67f54f1f1
-rw-r--r-- | src/HostNames.c | 173 | ||||
-rw-r--r-- | src/httpextra_HostNames.h | 27 | ||||
-rw-r--r-- | src/make.code.defn | 2 |
3 files changed, 201 insertions, 1 deletions
diff --git a/src/HostNames.c b/src/HostNames.c new file mode 100644 index 0000000..318b943 --- /dev/null +++ b/src/HostNames.c @@ -0,0 +1,173 @@ + /*@@ + @file HostNames.c + @date Tue Nov 7 17:36:35 2000 + @author Tom Goodale + @desc + Routines to collect data about all hosts in a Ccatus job. + @enddesc + @version $Header$ + @@*/ + +#ifndef TEST_HOSTNAMES +#include "cctk.h" +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif /* HAVE_UNISTD_H */ + +#ifdef CCTK_MPI +#include "mpi.h" +#endif /* CCTK_MPI */ + +#include "httpextra_HostNames.h" + +static char *rcsid = "$Header$"; + +#ifdef CCTK_FILEVERSION +CCTK_FILEVERSION(CactusConnect_HTTPDExtra_HostNames_c) +#endif + +/******************************************************************** + ********************* Local Data Types *********************** + ********************************************************************/ + +#define HOSTDATALENGTH 255 + +/******************************************************************** + ********************* Local Routine Prototypes ********************* + ********************************************************************/ + +/******************************************************************** + ********************* Other Routine Prototypes ********************* + ********************************************************************/ + +/******************************************************************** + ********************* Local Data ***************************** + ********************************************************************/ + +char *hostdata = NULL; + +/******************************************************************** + ********************* External Routines ********************** + ********************************************************************/ + + /*@@ + @routine HTTPDExtra_CollateHostData + @date Tue Nov 7 18:10:01 2000 + @author Tom Goodale + @desc + Gets data about all hosts in the parallel job. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +void HTTPDExtra_CollateHostData(void) +{ + int rank; + int nprocs; + char thisdata[HOSTDATALENGTH+1]; + + gethostname(thisdata, HOSTDATALENGTH); + + thisdata[HOSTDATALENGTH+1] = 0; + +#ifdef CCTK_MPI + /* Work out how many processes there are. */ + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + /* Work out if this is proc 0 or not. */ + MPI_Comm_rank(MPI_COMM_WORLD, &rank); +#else + nprocs = 1; + rank = 0; +#endif + + if(rank == 0) + { + hostdata=(char *)malloc((HOSTDATALENGTH+1)*nprocs); + + if(!hostdata) + { + exit(999); + } + } + +#ifdef CCTK_MPI + MPI_Gather(thisdata, HOSTDATALENGTH+1, MPI_BYTE, + hostdata, HOSTDATALENGTH+1, MPI_BYTE, + 0, MPI_COMM_WORLD); +#else + strncpy(hostdata, thisdata, HOSTDATALENGTH); +#endif + +} + + /*@@ + @routine HTTPDExtra_RemoteHostData + @date Tue Nov 7 18:10:38 2000 + @author Tom Goodale + @desc + Gets name of a remote host indexed by host process number. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +const char *HTTPDExtra_RemoteHostName(int host) +{ + return hostdata+host*(HOSTDATALENGTH+1); +} + +/******************************************************************** + ********************* Local Routines ************************* + ********************************************************************/ + +#ifdef TEST_HOSTNAMES + +int main(int argc, char *argv[]) +{ + int rank; + int nprocs; + +#ifdef CCTK_MPI + MPI_Init(&argc, &argv); + + /* Work out how many processes there are. */ + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + + /* Work out if this is proc 0 or not. */ + MPI_Comm_rank(MPI_COMM_WORLD, &rank); +#else + nprocs = 1; + rank = 0; +#endif + + HTTPDExtra_CollateHostData(); + + if(rank == 0) + { + for(rank = 0; rank < nprocs; rank++) + { + printf("Host %d is %s\n", rank, HTTPDExtra_RemoteHostName(rank)); + } + } + +#ifdef CCTK_MPI + MPI_Finalize(); +#endif + + return 0; +} + +#endif /* TESTHOSTNAMES */ diff --git a/src/httpextra_HostNames.h b/src/httpextra_HostNames.h new file mode 100644 index 0000000..640c6d7 --- /dev/null +++ b/src/httpextra_HostNames.h @@ -0,0 +1,27 @@ + /*@@ + @header httpextra_HostNames.h + @date Tue Nov 7 23:57:31 2000 + @author Tom Goodale + @desc + Prototypes for routines which give data about hosts in the machine. + @enddesc + @version $Header$ + @@*/ + +#ifndef _HOSTNAMES_H_ +#define _HOSTNAMES_H_ 1 + +#ifdef __cplusplus +extern "C" +{ +#endif + +void HTTPDExtra_CollateHostData(void); + +const char *HTTPDExtra_RemoteHostName(int host); + +#ifdef __cplusplus +} +#endif + +#endif /* _HOSTNAMES_H_ */ diff --git a/src/make.code.defn b/src/make.code.defn index 60cd782..32cee1f 100644 --- a/src/make.code.defn +++ b/src/make.code.defn @@ -2,7 +2,7 @@ # $Header$ # Source files in this directory -SRCS = Groups.c Startup.c IO.c +SRCS = Groups.c Startup.c IO.c HostNames.c # Subdirectories containing source files SUBDIRS = |