From b6e8d2b6d3d8c216d307cf86b20110aa956abc1f Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <matthieu.schaller@durham.ac.uk> Date: Fri, 3 Jun 2016 12:14:45 +0100 Subject: [PATCH] lock_type --> swift_lock_type --- examples/main.c | 4 ---- src/cell.h | 2 +- src/engine.c | 29 +++++++++++++++-------------- src/engine.h | 5 ++++- src/lock.h | 6 +++--- src/parser.c | 5 ++--- src/parser.h | 8 ++++++++ src/queue.c | 2 +- src/queue.h | 2 +- src/scheduler.h | 2 +- src/single_io.c | 6 ++++++ src/space.h | 2 +- src/task.h | 2 +- 13 files changed, 44 insertions(+), 31 deletions(-) diff --git a/examples/main.c b/examples/main.c index a35cf8776c..1d8263d5f6 100644 --- a/examples/main.c +++ b/examples/main.c @@ -431,10 +431,6 @@ int main(int argc, char *argv[]) { /* Write the state of the system before starting time integration. */ if (!dry_run) engine_dump_snapshot(&e); - /* Now that everything is ready, no need for the parameters any more */ - free(params); - params = NULL; - /* Init the runner history. */ #ifdef HIST for (k = 0; k < runner_hist_N; k++) runner_hist_bins[k] = 0; diff --git a/src/cell.h b/src/cell.h index a69a1a7464..c2ddaaf177 100644 --- a/src/cell.h +++ b/src/cell.h @@ -136,7 +136,7 @@ struct cell { int hold, ghold; /* Spin lock for various uses. */ - lock_type lock, glock; + swift_lock_type lock, glock; /* ID of the previous owner, e.g. runner. */ int owner; diff --git a/src/engine.c b/src/engine.c index cd5c253c5a..803ba54d4a 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1997,7 +1997,7 @@ void engine_step(struct engine *e) { clocks_gettime(&time1); e->tic_step = getticks(); - + /* Collect the cell data. */ for (int k = 0; k < s->nr_cells; k++) if (s->cells[k].nodeID == e->nodeID) { @@ -2505,6 +2505,7 @@ void engine_init(struct engine *e, struct space *s, e->physical_constants = physical_constants; e->hydro_properties = hydro; e->external_potential = potential; + e->parameter_file = params; engine_rank = nodeID; /* Make the space link back to the engine. */ @@ -2555,7 +2556,7 @@ void engine_init(struct engine *e, struct space *s, if (nodeID == 0) message("prefer NUMA-distant CPUs"); /* Get list of numa nodes of all available cores. */ - int *nodes = malloc( nr_affinity_cores * sizeof(int)); + int *nodes = malloc(nr_affinity_cores * sizeof(int)); int nnodes = 0; for (int i = 0; i < nr_affinity_cores; i++) { nodes[i] = numa_node_of_cpu(cpuid[i]); @@ -2564,7 +2565,7 @@ void engine_init(struct engine *e, struct space *s, nnodes += 1; /* Count cores per node. */ - int *core_counts = malloc( nnodes * sizeof(int)); + int *core_counts = malloc(nnodes * sizeof(int)); for (int i = 0; i < nr_affinity_cores; i++) { core_counts[nodes[i]] = 0; } @@ -2573,7 +2574,7 @@ void engine_init(struct engine *e, struct space *s, } /* Index cores within each node. */ - int *core_indices = malloc( nr_affinity_cores * sizeof(int)); + int *core_indices = malloc(nr_affinity_cores * sizeof(int)); for (int i = nr_affinity_cores - 1; i >= 0; i--) { core_indices[i] = core_counts[nodes[i]]; core_counts[nodes[i]] -= 1; @@ -2585,13 +2586,13 @@ void engine_init(struct engine *e, struct space *s, while (!done) { done = 1; for (int i = 1; i < nr_affinity_cores; i++) { - if ( core_indices[i] < core_indices[i-1] ) { - int t = cpuid[i-1]; - cpuid[i-1] = cpuid[i]; + if (core_indices[i] < core_indices[i - 1]) { + int t = cpuid[i - 1]; + cpuid[i - 1] = cpuid[i]; cpuid[i] = t; - t = core_indices[i-1]; - core_indices[i-1] = core_indices[i]; + t = core_indices[i - 1]; + core_indices[i - 1] = core_indices[i]; core_indices[i] = t; done = 0; } @@ -2604,11 +2605,10 @@ void engine_init(struct engine *e, struct space *s, } } #endif - } - else { + } else { if (nodeID == 0) message("no processor affinity used"); - }/* with_aff */ + } /* with_aff */ /* Avoid (unexpected) interference between engine and runner threads. We can * do this once we've made at least one call to engine_entry_affinity and @@ -2771,7 +2771,8 @@ void engine_init(struct engine *e, struct space *s, error("Failed to create runner thread."); /* Try to pin the runner to a given core */ - if (with_aff && (e->policy & engine_policy_setaffinity) == engine_policy_setaffinity) { + if (with_aff && + (e->policy & engine_policy_setaffinity) == engine_policy_setaffinity) { #if defined(HAVE_SETAFFINITY) /* Set a reasonable queue ID. */ @@ -2800,7 +2801,7 @@ void engine_init(struct engine *e, struct space *s, e->runners[k].qid = k * nr_queues / e->nr_threads; } if (verbose) { - if (with_aff) + if (with_aff) message("runner %i on cpuid=%i with qid=%i.", e->runners[k].id, e->runners[k].cpuid, e->runners[k].qid); else diff --git a/src/engine.h b/src/engine.h index f1e9add6a9..400cc197e5 100644 --- a/src/engine.h +++ b/src/engine.h @@ -189,6 +189,9 @@ struct engine { /* Properties of external gravitational potential */ const struct external_potential *external_potential; + + /* The (parsed) parameter file */ + const struct swift_params *parameter_file; }; /* Function prototypes. */ @@ -197,7 +200,7 @@ void engine_compute_next_snapshot_time(struct engine *e); void engine_dump_snapshot(struct engine *e); void engine_init(struct engine *e, struct space *s, const struct swift_params *params, int nr_nodes, int nodeID, - int nr_threads, int with_aff, int policy, int verbose, + int nr_threads, int with_aff, int policy, int verbose, const struct phys_const *physical_constants, const struct hydro_props *hydro, const struct external_potential *potential); diff --git a/src/lock.h b/src/lock.h index 90e9f90602..735058e15f 100644 --- a/src/lock.h +++ b/src/lock.h @@ -27,7 +27,7 @@ #ifdef PTHREAD_SPINLOCK #include <pthread.h> -#define lock_type pthread_spinlock_t +#define swift_lock_type pthread_spinlock_t #define lock_init(l) (pthread_spin_init(l, PTHREAD_PROCESS_PRIVATE) != 0) #define lock_destroy(l) (pthread_spin_destroy(l) != 0) #define lock_lock(l) (pthread_spin_lock(l) != 0) @@ -36,7 +36,7 @@ #define lock_unlock_blind(l) pthread_spin_unlock(l) #elif defined(PTHREAD_LOCK) #include <pthread.h> -#define lock_type pthread_mutex_t +#define swift_lock_type pthread_mutex_t #define lock_init(l) (pthread_mutex_init(l, NULL) != 0) #define lock_destroy(l) (pthread_mutex_destroy(l) != 0) #define lock_lock(l) (pthread_mutex_lock(l) != 0) @@ -44,7 +44,7 @@ #define lock_unlock(l) (pthread_mutex_unlock(l) != 0) #define lock_unlock_blind(l) pthread_mutex_unlock(l) #else -#define lock_type volatile int +#define swift_lock_type volatile int #define lock_init(l) (*(l) = 0) #define lock_destroy(l) 0 INLINE static int lock_lock(volatile int *l) { diff --git a/src/parser.c b/src/parser.c index db98f78932..c73040b903 100644 --- a/src/parser.c +++ b/src/parser.c @@ -303,7 +303,7 @@ static void parse_value(char *line, struct swift_params *params) { strcpy(params->data[params->paramCount].value, token); if (params->paramCount == PARSER_MAX_NO_OF_PARAMS - 1) { error( - "MMaximal number of parameters in parameter file reached. Aborting " + "Maximal number of parameters in parameter file reached. Aborting " "!"); } else { params->paramCount++; @@ -361,8 +361,7 @@ static void parse_section_param(char *line, int *isFirstParam, strcpy(params->data[params->paramCount].name, paramName); strcpy(params->data[params->paramCount].value, token); if (params->paramCount == PARSER_MAX_NO_OF_PARAMS - 1) { - error( - "MMaximal number of parameters in parameter file reached. Aborting !"); + error("Maximal number of parameters in parameter file reached. Aborting !"); } else { params->paramCount++; } diff --git a/src/parser.h b/src/parser.h index 6670bfaebf..21156a37b3 100644 --- a/src/parser.h +++ b/src/parser.h @@ -22,6 +22,10 @@ /* Config parameters. */ #include "../config.h" +#if defined(HAVE_HDF5) +#include <hdf5.h> +#endif + /* Some constants. */ #define PARSER_MAX_LINE_SIZE 256 #define PARSER_MAX_NO_OF_PARAMS 256 @@ -60,4 +64,8 @@ double parser_get_param_double(const struct swift_params *params, void parser_get_param_string(const struct swift_params *params, const char *name, char *retParam); +#if defined(HAVE_HDF5) +void parser_write_params_to_hdf5(const struct swift_params *params, hid_t grp); +#endif + #endif /* SWIFT_PARSER_H */ diff --git a/src/queue.c b/src/queue.c index 6b788d7376..dfdac883f9 100644 --- a/src/queue.c +++ b/src/queue.c @@ -133,7 +133,7 @@ void queue_init(struct queue *q, struct task *tasks) { struct task *queue_gettask(struct queue *q, const struct task *prev, int blocking) { - lock_type *qlock = &q->lock; + swift_lock_type *qlock = &q->lock; struct task *res = NULL; /* Grab the task lock. */ diff --git a/src/queue.h b/src/queue.h index 9ce52ea540..b28039a307 100644 --- a/src/queue.h +++ b/src/queue.h @@ -41,7 +41,7 @@ extern int queue_counter[queue_counter_count]; struct queue { /* The lock to access this queue. */ - lock_type lock; + swift_lock_type lock; /* Size, count and next element. */ int size, count; diff --git a/src/scheduler.h b/src/scheduler.h index 64c694aea2..a867f7bc36 100644 --- a/src/scheduler.h +++ b/src/scheduler.h @@ -89,7 +89,7 @@ struct scheduler { int nr_unlocks, size_unlocks; /* Lock for this scheduler. */ - lock_type lock; + swift_lock_type lock; /* Waiting queue. */ pthread_mutex_t sleep_mutex; diff --git a/src/single_io.c b/src/single_io.c index d545fb086f..94ef4e59c0 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -562,6 +562,12 @@ void write_output_single(struct engine* e, const char* baseName, writeSPHflavour(h_grp); H5Gclose(h_grp); + /* Print the runtime parameters */ + h_grp = H5Gcreate(h_file, "/Parameters", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (h_grp < 0) error("Error while creating parameters group"); + parser_write_params_to_hdf5(e->parameter_file, h_grp); + H5Gclose(h_grp); + /* Print the system of Units */ writeUnitSystem(h_file, us); diff --git a/src/space.h b/src/space.h index ad7b9e77d4..d53c0f2a57 100644 --- a/src/space.h +++ b/src/space.h @@ -97,7 +97,7 @@ struct space { int periodic; /* General-purpose lock for this space. */ - lock_type lock; + swift_lock_type lock; /* Number of queues in the system. */ int nr_queues; diff --git a/src/task.h b/src/task.h index 3e6bdc7370..e9b7fabd58 100644 --- a/src/task.h +++ b/src/task.h @@ -77,7 +77,7 @@ struct task { char skip, tight, implicit; int flags, wait, rank, weight; - lock_type lock; + swift_lock_type lock; struct cell *ci, *cj; -- GitLab