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 /src/HostNames.c | |
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
Diffstat (limited to 'src/HostNames.c')
-rw-r--r-- | src/HostNames.c | 173 |
1 files changed, 173 insertions, 0 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 */ |