Commit a4cb085a authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Merge branch 'print_hostname' into 'master'

Print hostname

Prints the name of the host at runtime for each MPI rank when the verbosity level is set to 2 and the name of the host by default when MPI is not activated.

See merge request !263
parents ad6dadd8 6e8be9b9
...@@ -262,12 +262,21 @@ int main(int argc, char *argv[]) { ...@@ -262,12 +262,21 @@ int main(int argc, char *argv[]) {
message( message(
"Executing a dry run. No i/o or time integration will be performed."); "Executing a dry run. No i/o or time integration will be performed.");
/* Report CPU frequency. */ /* Report CPU frequency.*/
cpufreq = clocks_get_cpufreq(); cpufreq = clocks_get_cpufreq();
if (myrank == 0) { if (myrank == 0) {
message("CPU frequency used for tick conversion: %llu Hz", cpufreq); message("CPU frequency used for tick conversion: %llu Hz", cpufreq);
} }
/* Report host name(s). */
#ifdef WITH_MPI
if (myrank == 0 || verbose > 1) {
message("Rank %d running on: %s", myrank, hostname());
}
#else
message("Running on: %s", hostname());
#endif
/* Do we choke on FP-exceptions ? */ /* Do we choke on FP-exceptions ? */
if (with_fp_exceptions) { if (with_fp_exceptions) {
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
......
...@@ -3409,13 +3409,14 @@ void engine_init(struct engine *e, struct space *s, ...@@ -3409,13 +3409,14 @@ void engine_init(struct engine *e, struct space *s,
nr_nodes * nr_threads); nr_nodes * nr_threads);
e->file_timesteps = fopen(timestepsfileName, "w"); e->file_timesteps = fopen(timestepsfileName, "w");
fprintf(e->file_timesteps, fprintf(e->file_timesteps,
"# Branch: %s\n# Revision: %s\n# Compiler: %s, Version: %s \n# " "# Host: %s\n# Branch: %s\n# Revision: %s\n# Compiler: %s, "
"Version: %s \n# "
"Number of threads: %d\n# Number of MPI ranks: %d\n# Hydrodynamic " "Number of threads: %d\n# Number of MPI ranks: %d\n# Hydrodynamic "
"scheme: %s\n# Hydrodynamic kernel: %s\n# No. of neighbours: %.2f " "scheme: %s\n# Hydrodynamic kernel: %s\n# No. of neighbours: %.2f "
"+/- %.2f\n# Eta: %f\n", "+/- %.2f\n# Eta: %f\n",
git_branch(), git_revision(), compiler_name(), compiler_version(), hostname(), git_branch(), git_revision(), compiler_name(),
e->nr_threads, e->nr_nodes, SPH_IMPLEMENTATION, kernel_name, compiler_version(), e->nr_threads, e->nr_nodes, SPH_IMPLEMENTATION,
e->hydro_properties->target_neighbours, kernel_name, e->hydro_properties->target_neighbours,
e->hydro_properties->delta_neighbours, e->hydro_properties->delta_neighbours,
e->hydro_properties->eta_neighbours); e->hydro_properties->eta_neighbours);
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
/* Config parameters. */ /* Config parameters. */
#include "../config.h" #include "../config.h"
/* Needed for gethostname() */
#include <unistd.h>
/* MPI headers. */ /* MPI headers. */
#ifdef WITH_MPI #ifdef WITH_MPI
#include <mpi.h> #include <mpi.h>
...@@ -47,6 +50,24 @@ ...@@ -47,6 +50,24 @@
/* Local headers. */ /* Local headers. */
#include "version_string.h" #include "version_string.h"
/**
* @brief Return the hostname
*
* Will return the name of the host.
*
* @result the hostname.
*/
const char *hostname(void) {
static char buf[256];
static int initialised = 0;
if (!initialised) {
buf[255] = '\0';
if (gethostname(buf, 255)) sprintf(buf, "%s", "Unknown host");
initialised = 1;
}
return buf;
}
/** /**
* @brief Return the source code git revision * @brief Return the source code git revision
* *
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
const char* package_description(void); const char* package_description(void);
const char* package_version(void); const char* package_version(void);
const char* hostname(void);
const char* git_revision(void); const char* git_revision(void);
const char* git_branch(void); const char* git_branch(void);
const char* compiler_name(void); const char* compiler_name(void);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment