diff --git a/examples/main.c b/examples/main.c index a35cf8776c78b6cc7fcab40163fea0b9ea8f1439..1d8263d5f6bde99befe0745ca56744389bf3ca7e 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 a69a1a74648d76aeb13126d37a3c1265397dc2bf..c2ddaaf177f7278e1007349e02edabb6198ea080 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 cd5c253c5a2cc5d2968a8b99262660a3b59978df..803ba54d4ae3579e859fab4c1f304bf7e847222f 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 f1e9add6a903d5939ce717d9bb43c42dfca0675c..400cc197e5e003cd5a784b9beeaf2cc1c26f87e3 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 90e9f90602c120ddd10f4cdefb9b08cedbf45e0f..735058e15f09d31396bc97d6906c5853fed17db9 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 db98f7893250b93c5ec78b42bf14431c5238dcee..c73040b903d3e8c0280f37c05ac67b0b4e9029ed 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 6670bfaebf874c06bca1d078de104456a69a1b29..21156a37b3bc76d8c3ba01385cb991b2fe213a85 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 6b788d7376ba4bdc95f1b1d918ab52a9514e7b4a..dfdac883f9713eb57bb2dc45eb97774983e3a9b2 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 9ce52ea5404db727f29d0f1cf898f5f5a4f6d935..b28039a30724fa0c086f9111470af2566933e3ac 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 64c694aea295c13810a20b626055fc6c15eb0af8..a867f7bc36cc8865d28d751565663641d92aa7fb 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 d545fb086fa4bc63fe58dee2bfe85d9586997850..94ef4e59c0ede0cba2b09b9342b538d0efa042b7 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 ad7b9e77d484c997527d32c934bf1b85d7d54e41..d53c0f2a5784ef25654309741b4455e3dbcc3e0c 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 3e6bdc7370b005b32bafcbb20dd2ddbf807996ae..e9b7fabd58f241426454f49b65f8d174957e3b86 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;