aboutsummaryrefslogtreecommitdiff
path: root/src/HostNames.c
blob: d46505bb6207e25ed4cdb7404b96012b641c35b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
 /*@@
   @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"
#include "util_Network.h"
#endif

#include <stdlib.h>

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif /* HAVE_SYS_TIME_H */
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif /* HAVE_SYS_TYPES_H */
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif /* HAVE_SYS_SOCKET_H */
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif /* HAVE_NETINET_IN_H */
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif /* HAVE_NETDB_H */
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
#endif /* HAVE_WINSOCK2_H */
#include <errno.h>

#ifdef CCTK_MPI
#include "mpi.h"
#endif /* CCTK_MPI */

#include "httpextra_HostNames.h"

static const char *rcsid = "$Header$";

CCTK_FILEVERSION(CactusConnect_HTTPDExtra_HostNames_c)

/********************************************************************
 *********************     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 = 0;
  int nprocs = 1;
  char thisdata[HOSTDATALENGTH+1];

  Util_GetHostName(thisdata, HOSTDATALENGTH);

  thisdata[HOSTDATALENGTH] = 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);
#endif
  
  if(rank == 0)
  {
    hostdata=(char *)malloc((HOSTDATALENGTH+1)*nprocs);
    
    if(!hostdata)
    {
      CCTK_WARN(0, "Could not allocate memory");
    }
  }
  
#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 = 0;
  int nprocs = 1;

#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);
#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 */