diff --git a/examples/main.c b/examples/main.c index c8af2d98bd3b3962b3c288cf21544d5f081a398b..32ed12bfcc2fc7c1c0400c348a8222e2d6b86d0c 100644 --- a/examples/main.c +++ b/examples/main.c @@ -432,7 +432,7 @@ int main(int argc, char *argv[]) { } /* Read the parameter file */ - struct swift_params *params = malloc(sizeof(struct swift_params)); + struct swift_params *params = (struct swift_params *)malloc(sizeof(struct swift_params)); if (params == NULL) error("Error allocating memory for the parameter file."); if (myrank == 0) { message("Reading runtime parameters from file '%s'", paramFileName); diff --git a/src/atomic.h b/src/atomic.h index 4f180c643a304a801a9d70940fd12f9f193941e1..b09ed3dd22001586cfde8545e636de67a819c003 100644 --- a/src/atomic.h +++ b/src/atomic.h @@ -26,9 +26,10 @@ #include "inline.h" #define atomic_add(v, i) __sync_fetch_and_add(v, i) +#define atomic_sub(v, i) __sync_fetch_and_sub(v, i) #define atomic_or(v, i) __sync_fetch_and_or(v, i) #define atomic_inc(v) atomic_add(v, 1) -#define atomic_dec(v) atomic_add(v, -1) +#define atomic_dec(v) atomic_sub(v, 1) #define atomic_cas(v, o, n) __sync_val_compare_and_swap(v, o, n) #define atomic_swap(v, n) __sync_lock_test_and_set(v, n) diff --git a/src/common_io.c b/src/common_io.c index 7d0b0cb3ef026eb7bbbe17b82fb072f83c395305..78bbba804ca8a2bf445bdf44180945d84d253aad 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -418,7 +418,7 @@ void io_copy_mapper(void* restrict temp, int N, void* restrict extra_data) { const size_t copySize = typeSize * props.dimension; /* How far are we with this chunk? */ - char* restrict temp_c = temp; + char* restrict temp_c = (char *)temp; const ptrdiff_t delta = (temp_c - props.start_temp_c) / copySize; for (int k = 0; k < N; k++) { @@ -440,7 +440,7 @@ void io_convert_part_f_mapper(void* restrict temp, int N, const size_t dim = props.dimension; /* How far are we with this chunk? */ - float* restrict temp_f = temp; + float* restrict temp_f = (float *)temp; const ptrdiff_t delta = (temp_f - props.start_temp_f) / dim; for (int i = 0; i < N; i++) @@ -460,7 +460,7 @@ void io_convert_part_d_mapper(void* restrict temp, int N, const size_t dim = props.dimension; /* How far are we with this chunk? */ - double* restrict temp_d = temp; + double* restrict temp_d = (double *)temp; const ptrdiff_t delta = (temp_d - props.start_temp_d) / dim; for (int i = 0; i < N; i++) @@ -480,7 +480,7 @@ void io_convert_gpart_f_mapper(void* restrict temp, int N, const size_t dim = props.dimension; /* How far are we with this chunk? */ - float* restrict temp_f = temp; + float* restrict temp_f = (float *)temp; const ptrdiff_t delta = (temp_f - props.start_temp_f) / dim; for (int i = 0; i < N; i++) @@ -500,7 +500,7 @@ void io_convert_gpart_d_mapper(void* restrict temp, int N, const size_t dim = props.dimension; /* How far are we with this chunk? */ - double* restrict temp_d = temp; + double* restrict temp_d = (double *)temp; const ptrdiff_t delta = (temp_d - props.start_temp_d) / dim; for (int i = 0; i < N; i++) @@ -531,7 +531,7 @@ void io_copy_temp_buffer(void* temp, const struct engine* e, if (props.conversion == 0) { /* No conversion */ /* Prepare some parameters */ - char* temp_c = temp; + char* temp_c = (char *)temp; props.start_temp_c = temp_c; /* Copy the whole thing into a buffer */ @@ -543,8 +543,8 @@ void io_copy_temp_buffer(void* temp, const struct engine* e, if (props.convert_part_f != NULL) { /* Prepare some parameters */ - float* temp_f = temp; - props.start_temp_f = temp; + float* temp_f = (float *)temp; + props.start_temp_f = (float *)temp; props.e = e; /* Copy the whole thing into a buffer */ @@ -555,8 +555,8 @@ void io_copy_temp_buffer(void* temp, const struct engine* e, } else if (props.convert_part_d != NULL) { /* Prepare some parameters */ - double* temp_d = temp; - props.start_temp_d = temp; + double* temp_d = (double *)temp; + props.start_temp_d = (double *)temp; props.e = e; /* Copy the whole thing into a buffer */ @@ -567,8 +567,8 @@ void io_copy_temp_buffer(void* temp, const struct engine* e, } else if (props.convert_gpart_f != NULL) { /* Prepare some parameters */ - float* temp_f = temp; - props.start_temp_f = temp; + float* temp_f = (float *)temp; + props.start_temp_f = (float *)temp; props.e = e; /* Copy the whole thing into a buffer */ @@ -579,8 +579,8 @@ void io_copy_temp_buffer(void* temp, const struct engine* e, } else if (props.convert_gpart_d != NULL) { /* Prepare some parameters */ - double* temp_d = temp; - props.start_temp_d = temp; + double* temp_d = (double *)temp; + props.start_temp_d = (double *)temp; props.e = e; /* Copy the whole thing into a buffer */ @@ -601,10 +601,10 @@ void io_copy_temp_buffer(void* temp, const struct engine* e, /* message("Converting ! factor=%e", factor); */ if (io_is_double_precision(props.type)) { - swift_declare_aligned_ptr(double, temp_d, temp, IO_BUFFER_ALIGNMENT); + swift_declare_aligned_ptr(double, temp_d, (double *)temp, IO_BUFFER_ALIGNMENT); for (size_t i = 0; i < num_elements; ++i) temp_d[i] *= factor; } else { - swift_declare_aligned_ptr(float, temp_f, temp, IO_BUFFER_ALIGNMENT); + swift_declare_aligned_ptr(float, temp_f, (float *)temp, IO_BUFFER_ALIGNMENT); for (size_t i = 0; i < num_elements; ++i) temp_f[i] *= factor; } } diff --git a/src/engine.c b/src/engine.c index 7967bdf01aa726655326998eb020a0ed0492ba31..7c1a695c7d6e7361a1a04464e0c3848761df62c3 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2070,7 +2070,7 @@ void engine_exchange_proxy_multipoles(struct engine *e) { /* Also allocate the MPI requests */ const int count_requests = count_send_requests + count_recv_requests; - MPI_Request *requests = malloc(sizeof(MPI_Request) * count_requests); + MPI_Request *requests = (MPI_Request *)malloc(sizeof(MPI_Request) * count_requests); if (requests == NULL) error("Unable to allocate memory for MPI requests"); int this_request = 0; @@ -2121,7 +2121,7 @@ void engine_exchange_proxy_multipoles(struct engine *e) { } /* Wait for all the requests to arrive home */ - MPI_Status *stats = malloc(count_requests * sizeof(MPI_Status)); + MPI_Status *stats = (MPI_Status *)malloc(count_requests * sizeof(MPI_Status)); int res; if ((res = MPI_Waitall(count_requests, requests, stats)) != MPI_SUCCESS) { for (int k = 0; k < count_requests; ++k) { @@ -2311,7 +2311,7 @@ void engine_make_self_gravity_tasks(struct engine *e) { task_subtype_none, 0, 0, NULL, NULL); /* Create a grid of ghosts to deal with the dependencies */ - if ((ghosts = malloc(n_ghosts * sizeof(struct task *))) == 0) + if ((ghosts = (struct task **)malloc(n_ghosts * sizeof(struct task *))) == 0) error("Error allocating memory for gravity fft ghosts"); /* Make the ghosts implicit and add the dependencies */ @@ -3022,7 +3022,7 @@ void engine_maketasks(struct engine *e) { e->size_links += s->tot_cells * self_grav_tasks_per_cell; /* Allocate the new list */ - if ((e->links = malloc(sizeof(struct link) * e->size_links)) == NULL) + if ((e->links = (struct link *)malloc(sizeof(struct link) * e->size_links)) == NULL) error("Failed to allocate cell-task links."); e->nr_links = 0; @@ -5208,7 +5208,7 @@ void engine_init( parser_get_param_string(params, "Snapshots:basename", e->snapshotBaseName); e->snapshotCompression = parser_get_opt_param_int(params, "Snapshots:compression", 0); - e->snapshotUnits = malloc(sizeof(struct unit_system)); + e->snapshotUnits = (struct unit_system *)malloc(sizeof(struct unit_system)); units_init_default(e->snapshotUnits, params, "Snapshots", internal_units); e->snapshotOutputCount = 0; e->dt_min = parser_get_param_double(params, "TimeIntegration:dt_min"); @@ -5309,7 +5309,7 @@ void engine_config(int restart, struct engine *e, if (nr_cores > CPU_SETSIZE) /* Unlikely, except on e.g. SGI UV. */ error("must allocate dynamic cpu_set_t (too many cores per node)"); - char *buf = malloc((nr_cores + 1) * sizeof(char)); + char *buf = (char *)malloc((nr_cores + 1) * sizeof(char)); buf[nr_cores] = '\0'; for (int j = 0; j < nr_cores; ++j) { /* Reversed bit order from convention, but same as e.g. Intel MPI's @@ -5324,7 +5324,7 @@ void engine_config(int restart, struct engine *e, if (with_aff) { - cpuid = malloc(nr_affinity_cores * sizeof(int)); + cpuid = (int *)malloc(nr_affinity_cores * sizeof(int)); int skip = 0; for (int k = 0; k < nr_affinity_cores; k++) { @@ -5342,7 +5342,7 @@ void engine_config(int restart, struct engine *e, 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 = (int *)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]); @@ -5351,7 +5351,7 @@ void engine_config(int restart, struct engine *e, nnodes += 1; /* Count cores per node. */ - int *core_counts = malloc(nnodes * sizeof(int)); + int *core_counts = (int *)malloc(nnodes * sizeof(int)); for (int i = 0; i < nr_affinity_cores; i++) { core_counts[nodes[i]] = 0; } @@ -5360,7 +5360,7 @@ void engine_config(int restart, struct engine *e, } /* Index cores within each node. */ - int *core_indices = malloc(nr_affinity_cores * sizeof(int)); + int *core_indices = (int *)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; @@ -5843,53 +5843,53 @@ void engine_struct_restore(struct engine *e, FILE *stream) { /* Now for the other pointers, these use their own restore functions. */ /* Note all this memory leaks, but is used once. */ - struct space *s = malloc(sizeof(struct space)); + struct space *s = (struct space *)malloc(sizeof(struct space)); space_struct_restore(s, stream); e->s = s; s->e = e; - struct unit_system *us = malloc(sizeof(struct unit_system)); + struct unit_system *us = (struct unit_system *)malloc(sizeof(struct unit_system)); units_struct_restore(us, stream); e->internal_units = us; - us = malloc(sizeof(struct unit_system)); + us = (struct unit_system *)malloc(sizeof(struct unit_system)); units_struct_restore(us, stream); e->snapshotUnits = us; #ifdef WITH_MPI - struct repartition *reparttype = malloc(sizeof(struct repartition)); + struct repartition *reparttype = (strunct repartition *)malloc(sizeof(struct repartition)); partition_struct_restore(reparttype, stream); e->reparttype = reparttype; #endif - struct phys_const *physical_constants = malloc(sizeof(struct phys_const)); + struct phys_const *physical_constants = (struct phys_const *)malloc(sizeof(struct phys_const)); phys_const_struct_restore(physical_constants, stream); e->physical_constants = physical_constants; - struct hydro_props *hydro_properties = malloc(sizeof(struct hydro_props)); + struct hydro_props *hydro_properties = (struct hydro_props *)malloc(sizeof(struct hydro_props)); hydro_props_struct_restore(hydro_properties, stream); e->hydro_properties = hydro_properties; struct gravity_props *gravity_properties = - malloc(sizeof(struct gravity_props)); + (struct gravity_props *)malloc(sizeof(struct gravity_props)); gravity_props_struct_restore(gravity_properties, stream); e->gravity_properties = gravity_properties; struct external_potential *external_potential = - malloc(sizeof(struct external_potential)); + (struct external_potential *)malloc(sizeof(struct external_potential)); potential_struct_restore(external_potential, stream); e->external_potential = external_potential; struct cooling_function_data *cooling_func = - malloc(sizeof(struct cooling_function_data)); + (struct cooling_function_data *)malloc(sizeof(struct cooling_function_data)); cooling_struct_restore(cooling_func, stream); e->cooling_func = cooling_func; - struct sourceterms *sourceterms = malloc(sizeof(struct sourceterms)); + struct sourceterms *sourceterms = (struct sourceterms *)malloc(sizeof(struct sourceterms)); sourceterms_struct_restore(sourceterms, stream); e->sourceterms = sourceterms; - struct swift_params *parameter_file = malloc(sizeof(struct swift_params)); + struct swift_params *parameter_file = (struct swift_params *)malloc(sizeof(struct swift_params)); parser_struct_restore(parameter_file, stream); e->parameter_file = parameter_file; diff --git a/src/hydro_space.c b/src/hydro_space.c index c4a6f9c1495a44050c5477ebfdf0bb76a64bfc51..442945caf83a692efadf7755ebf463ebde38e0a4 100644 --- a/src/hydro_space.c +++ b/src/hydro_space.c @@ -47,6 +47,5 @@ __attribute__((always_inline)) INLINE void hydro_space_init( } } #else -__attribute__((always_inline)) INLINE void hydro_space_init( - struct hydro_space *hs, const struct space *s) {} +void hydro_space_init(struct hydro_space *hs, const struct space *s) {} #endif diff --git a/src/inline.h b/src/inline.h index 538f6f520c9d6187dc02f1cbd5d59480aac7bdb2..282164a802fe713a12e16a691f40d1d731414902 100644 --- a/src/inline.h +++ b/src/inline.h @@ -27,11 +27,16 @@ * @brief Defines inline */ #ifndef INLINE +#ifdef __cplusplus +#define INLINE inline +#define restrict +#else #if __GNUC__ && !__GNUC_STDC_INLINE__ #define INLINE extern inline #else #define INLINE inline #endif #endif +#endif #endif /* SWIFT_INLINE_H */ diff --git a/src/logger.c b/src/logger.c index 0e0bc930c0841f985da2c353357a69b69aba5d91..38cb220b94dd14680584e9edca75883e1df16907 100644 --- a/src/logger.c +++ b/src/logger.c @@ -108,7 +108,7 @@ void logger_log_part(struct part *p, unsigned int mask, size_t *offset, /* Allocate a chunk of memory in the dump of the right size. */ size_t offset_new; - char *buff = dump_get(dump, size, &offset_new); + char *buff = (char *)dump_get(dump, size, &offset_new); /* Write the header. */ uint64_t temp = (((uint64_t)(offset_new - *offset)) & 0xffffffffffffffULL) | @@ -192,7 +192,7 @@ void logger_log_gpart(struct gpart *p, unsigned int mask, size_t *offset, /* Allocate a chunk of memory in the dump of the right size. */ size_t offset_new; - char *buff = dump_get(dump, size, &offset_new); + char *buff = (char *)dump_get(dump, size, &offset_new); /* Write the header. */ uint64_t temp = (((uint64_t)(offset_new - *offset)) & 0xffffffffffffffULL) | @@ -244,7 +244,7 @@ void logger_log_timestamp(unsigned long long int timestamp, size_t *offset, /* Allocate a chunk of memory in the dump of the right size. */ size_t offset_new; - char *buff = dump_get(dump, size, &offset_new); + char *buff = (char *)dump_get(dump, size, &offset_new); /* Write the header. */ uint64_t temp = (((uint64_t)(offset_new - *offset)) & 0xffffffffffffffULL) | diff --git a/src/parser.c b/src/parser.c index cbd63e913010066cbd39418b81609f4669404213..af9ef5fd6b7228dd4ad96640b59322175586862b 100644 --- a/src/parser.c +++ b/src/parser.c @@ -110,9 +110,9 @@ void parser_set_param(struct swift_params *params, const char *namevalue) { value[0] = '\0'; /* Name is part until second colon. */ - char *p1 = strchr(namevalue, ':'); + const char *p1 = strchr(namevalue, ':'); if (p1 != NULL) { - char *p2 = strchr(p1 + 1, ':'); + const char *p2 = strchr(p1 + 1, ':'); if (p2 != NULL) { memcpy(name, namevalue, p2 - namevalue); name[p2 - namevalue] = '\0'; diff --git a/src/partition.c b/src/partition.c index b46172d859e1e19221ee86ecf2c28650715281ef..b6c190792cbadf7c601bfe254a8f510fe36d6754 100644 --- a/src/partition.c +++ b/src/partition.c @@ -1267,7 +1267,7 @@ int partition_space_to_space(double *oldh, double *oldcdim, int *oldnodeIDs, */ void partition_store_celllist(struct space *s, struct repartition *reparttype) { if (reparttype->celllist != NULL) free(reparttype->celllist); - reparttype->celllist = malloc(sizeof(int) * s->nr_cells); + reparttype->celllist = (int *)malloc(sizeof(int) * s->nr_cells); reparttype->ncelllist = s->nr_cells; if (reparttype->celllist == NULL) error("Failed to allocate celllist"); @@ -1333,7 +1333,7 @@ void partition_struct_restore(struct repartition *reparttype, FILE *stream) { /* Also restore the celllist, if we have one. */ if (reparttype->ncelllist > 0) { - reparttype->celllist = malloc(sizeof(int) * reparttype->ncelllist); + reparttype->celllist = (int *)malloc(sizeof(int) * reparttype->ncelllist); if (reparttype->celllist == NULL) error("Failed to allocate celllist"); restart_read_blocks(reparttype->celllist, sizeof(int) * reparttype->ncelllist, 1, stream, NULL, diff --git a/src/proxy.c b/src/proxy.c index 4c110d1a23cbe337978147567b2e6ad8a6d6ba65..d035a206578c9becf8634ea4a4c9011ba1e144dd 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -145,14 +145,14 @@ void proxy_addcell_in(struct proxy *p, struct cell *c, int type) { p->size_cells_in *= proxy_buffgrow; struct cell **temp_cell; - if ((temp_cell = malloc(sizeof(struct cell *) * p->size_cells_in)) == NULL) + if ((temp_cell = (struct cell **)malloc(sizeof(struct cell *) * p->size_cells_in)) == NULL) error("Failed to allocate incoming cell list."); memcpy(temp_cell, p->cells_in, sizeof(struct cell *) * p->nr_cells_in); free(p->cells_in); p->cells_in = temp_cell; int *temp_type; - if ((temp_type = malloc(sizeof(int) * p->size_cells_in)) == NULL) + if ((temp_type = (int *)malloc(sizeof(int) * p->size_cells_in)) == NULL) error("Failed to allocate incoming cell type list."); memcpy(temp_type, p->cells_in_type, sizeof(int) * p->nr_cells_in); free(p->cells_in_type); @@ -190,14 +190,14 @@ void proxy_addcell_out(struct proxy *p, struct cell *c, int type) { p->size_cells_out *= proxy_buffgrow; struct cell **temp_cell; - if ((temp_cell = malloc(sizeof(struct cell *) * p->size_cells_out)) == NULL) + if ((temp_cell = (struct cell **)malloc(sizeof(struct cell *) * p->size_cells_out)) == NULL) error("Failed to allocate outgoing cell list."); memcpy(temp_cell, p->cells_out, sizeof(struct cell *) * p->nr_cells_out); free(p->cells_out); p->cells_out = temp_cell; int *temp_type; - if ((temp_type = malloc(sizeof(int) * p->size_cells_out)) == NULL) + if ((temp_type = (int *)malloc(sizeof(int) * p->size_cells_out)) == NULL) error("Failed to allocate outgoing cell type list."); memcpy(temp_type, p->cells_out_type, sizeof(int) * p->nr_cells_out); free(p->cells_out_type); diff --git a/src/restart.c b/src/restart.c index 4f4d2b9fba2b40c21f767894cc20d79c8c748aea..26cbf7e8f4d4793b9e0d786449864645cf4c3b6c 100644 --- a/src/restart.c +++ b/src/restart.c @@ -93,7 +93,7 @@ char **restart_locate(const char *dir, const char *basename, int *nfiles) { char **files = NULL; if (glob(pattern, 0, NULL, &globbuf) == 0) { *nfiles = globbuf.gl_pathc; - files = malloc(sizeof(char *) * *nfiles); + files = (char **)malloc(sizeof(char *) * *nfiles); for (int i = 0; i < *nfiles; i++) { files[i] = strdup(globbuf.gl_pathv[i]); } @@ -133,7 +133,7 @@ void restart_write(struct engine *e, const char *filename) { error("Failed to open restart file: %s (%s)", filename, strerror(errno)); /* Dump our signature and version. */ - restart_write_blocks(SWIFT_RESTART_SIGNATURE, strlen(SWIFT_RESTART_SIGNATURE), + restart_write_blocks((void *)SWIFT_RESTART_SIGNATURE, strlen(SWIFT_RESTART_SIGNATURE), 1, stream, "signature", "SWIFT signature"); restart_write_blocks((void *)package_version(), strlen(package_version()), 1, stream, "version", "SWIFT version"); @@ -141,7 +141,7 @@ void restart_write(struct engine *e, const char *filename) { engine_struct_dump(e, stream); /* Just an END statement to spot truncated files. */ - restart_write_blocks(SWIFT_RESTART_END_SIGNATURE, + restart_write_blocks((void *)SWIFT_RESTART_END_SIGNATURE, strlen(SWIFT_RESTART_END_SIGNATURE), 1, stream, "endsignature", "SWIFT end signature"); diff --git a/src/runner.c b/src/runner.c index e5d7d005aa05050d9fc9392856e764a80c573e2d..6020533bdc5be845aa6a6c3c7429c07c8bb9eeea 100644 --- a/src/runner.c +++ b/src/runner.c @@ -660,7 +660,7 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { /* Init the list of active particles that have to be updated. */ int *pid = NULL; - if ((pid = malloc(sizeof(int) * c->count)) == NULL) + if ((pid = (int *)malloc(sizeof(int) * c->count)) == NULL) error("Can't allocate memory for pid."); for (int k = 0; k < c->count; k++) if (part_is_active(&parts[k], e)) { diff --git a/src/runner_doiact.h b/src/runner_doiact.h index 07d24c8df984634e19cb1aaf8bc072158e1b4c95..2897aca0012ddab2dff0fc54eb0a2e50f3fcdbd8 100644 --- a/src/runner_doiact.h +++ b/src/runner_doiact.h @@ -1159,7 +1159,7 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, sort_active_i = sort_i; count_active_i = count_i; } else if (cell_is_active_hydro(ci, e)) { - if (posix_memalign((void *)&sort_active_i, SWIFT_CACHE_ALIGNMENT, + if (posix_memalign((void **)&sort_active_i, SWIFT_CACHE_ALIGNMENT, sizeof(struct entry) * count_i) != 0) error("Failed to allocate active sortlists."); @@ -1177,7 +1177,7 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj, const int sid, sort_active_j = sort_j; count_active_j = count_j; } else if (cell_is_active_hydro(cj, e)) { - if (posix_memalign((void *)&sort_active_j, SWIFT_CACHE_ALIGNMENT, + if (posix_memalign((void **)&sort_active_j, SWIFT_CACHE_ALIGNMENT, sizeof(struct entry) * count_j) != 0) error("Failed to allocate active sortlists."); @@ -1601,7 +1601,7 @@ void DOSELF1(struct runner *r, struct cell *restrict c) { /* Set up indt. */ int *indt = NULL; int countdt = 0, firstdt = 0; - if (posix_memalign((void *)&indt, VEC_SIZE * sizeof(int), + if (posix_memalign((void **)&indt, VEC_SIZE * sizeof(int), count * sizeof(int)) != 0) error("Failed to allocate indt."); for (int k = 0; k < count; k++) @@ -1761,7 +1761,7 @@ void DOSELF2(struct runner *r, struct cell *restrict c) { /* Set up indt. */ int *indt = NULL; int countdt = 0, firstdt = 0; - if (posix_memalign((void *)&indt, VEC_SIZE * sizeof(int), + if (posix_memalign((void **)&indt, VEC_SIZE * sizeof(int), count * sizeof(int)) != 0) error("Failed to allocate indt."); for (int k = 0; k < count; k++) diff --git a/src/runner_doiact_fft.c b/src/runner_doiact_fft.c index 9e9841496707cb0d0dc0b7b6f3d8d98399414d91..05896f6205d58d6bb76332d5936b98d480412385 100644 --- a/src/runner_doiact_fft.c +++ b/src/runner_doiact_fft.c @@ -194,12 +194,12 @@ void runner_do_grav_fft(struct runner* r, int timer) { #endif /* Allocates some memory for the density mesh */ - double* restrict rho = fftw_malloc(sizeof(double) * N * N * N); + double* restrict rho = (double *)fftw_malloc(sizeof(double) * N * N * N); if (rho == NULL) error("Error allocating memory for density mesh"); /* Allocates some memory for the mesh in Fourier space */ fftw_complex* restrict frho = - fftw_malloc(sizeof(fftw_complex) * N * N * (N_half + 1)); + (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * N * N * (N_half + 1)); if (frho == NULL) error("Error allocating memory for transform of density mesh"); diff --git a/src/scheduler.c b/src/scheduler.c index 46dd82a513d504ef6834983935f8893fb633dacd..ac36043fc9fabf3e9bd55a75e19ee16bd4414ac7 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -136,7 +136,7 @@ void scheduler_write_dependencies(struct scheduler *s, int verbose) { * ind = (ta * task_subtype_count + sa) * max_nber_dep * 2 * where ta is the value of task_type and sa is the value of * task_subtype */ - int *table = malloc(nber_relation * sizeof(int)); + int *table = (int *)malloc(nber_relation * sizeof(int)); if (table == NULL) error("Error allocating memory for task-dependency graph."); @@ -1144,7 +1144,7 @@ void scheduler_reset(struct scheduler *s, int size) { scheduler_free_tasks(s); /* Allocate the new lists. */ - if (posix_memalign((void *)&s->tasks, task_align, + if (posix_memalign((void **)&s->tasks, task_align, size * sizeof(struct task)) != 0) error("Failed to allocate task array."); @@ -1463,7 +1463,7 @@ void scheduler_enqueue(struct scheduler *s, struct task *t) { case task_type_recv: #ifdef WITH_MPI if (t->subtype == task_subtype_tend) { - t->buff = malloc(sizeof(struct pcell_step) * t->ci->pcell_size); + t->buff = (struct pcell_step *)malloc(sizeof(struct pcell_step) * t->ci->pcell_size); err = MPI_Irecv( t->buff, t->ci->pcell_size * sizeof(struct pcell_step), MPI_BYTE, t->ci->nodeID, t->flags, MPI_COMM_WORLD, &t->req); @@ -1482,7 +1482,7 @@ void scheduler_enqueue(struct scheduler *s, struct task *t) { err = MPI_Irecv(t->ci->sparts, t->ci->scount, spart_mpi_type, t->ci->nodeID, t->flags, MPI_COMM_WORLD, &t->req); } else if (t->subtype == task_subtype_multipole) { - t->buff = malloc(sizeof(struct gravity_tensors) * t->ci->pcell_size); + t->buff = (struct gravity_tensors *)malloc(sizeof(struct gravity_tensors) * t->ci->pcell_size); err = MPI_Irecv( t->buff, sizeof(struct gravity_tensors) * t->ci->pcell_size, MPI_BYTE, t->ci->nodeID, t->flags, MPI_COMM_WORLD, &t->req); @@ -1500,7 +1500,7 @@ void scheduler_enqueue(struct scheduler *s, struct task *t) { case task_type_send: #ifdef WITH_MPI if (t->subtype == task_subtype_tend) { - t->buff = malloc(sizeof(struct pcell_step) * t->ci->pcell_size); + t->buff = (struct pcell_step *)malloc(sizeof(struct pcell_step) * t->ci->pcell_size); cell_pack_end_step(t->ci, t->buff); if ((t->ci->pcell_size * sizeof(struct pcell_step)) > s->mpi_message_limit) @@ -1538,7 +1538,7 @@ void scheduler_enqueue(struct scheduler *s, struct task *t) { err = MPI_Issend(t->ci->sparts, t->ci->scount, spart_mpi_type, t->cj->nodeID, t->flags, MPI_COMM_WORLD, &t->req); } else if (t->subtype == task_subtype_multipole) { - t->buff = malloc(sizeof(struct gravity_tensors) * t->ci->pcell_size); + t->buff = (struct gravity_tensors *)malloc(sizeof(struct gravity_tensors) * t->ci->pcell_size); cell_pack_multipoles(t->ci, t->buff); err = MPI_Isend( t->buff, t->ci->pcell_size * sizeof(struct gravity_tensors), diff --git a/src/single_io.c b/src/single_io.c index 79dc6d43d645862edb3e0f8a9a6480f368265a50..d0928512721e77f3672160847c148127bcb84ce5 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -131,16 +131,16 @@ void readArray(hid_t h_grp, const struct io_props prop, size_t N, /* message("Converting ! factor=%e", factor); */ if (io_is_double_precision(prop.type)) { - double* temp_d = temp; + double* temp_d = (double *)temp; for (size_t i = 0; i < num_elements; ++i) temp_d[i] *= factor; } else { - float* temp_f = temp; + float* temp_f = (float *)temp; for (size_t i = 0; i < num_elements; ++i) temp_f[i] *= factor; } } /* Copy temporary buffer to particle data */ - char* temp_c = temp; + char* temp_c = (char *)temp; for (size_t i = 0; i < N; ++i) memcpy(prop.field + i * prop.partSize, &temp_c[i * copySize], copySize); @@ -387,7 +387,7 @@ void read_ic_single(char* fileName, const struct unit_system* internal_units, H5Gclose(h_grp); /* Read the unit system used in the ICs */ - struct unit_system* ic_units = malloc(sizeof(struct unit_system)); + struct unit_system* ic_units = (struct unit_system *)malloc(sizeof(struct unit_system)); if (ic_units == NULL) error("Unable to allocate memory for IC unit system"); io_read_unit_system(h_file, ic_units, 0); @@ -428,7 +428,7 @@ void read_ic_single(char* fileName, const struct unit_system* internal_units, /* Allocate memory to store SPH particles */ if (with_hydro) { *Ngas = N[swift_type_gas]; - if (posix_memalign((void*)parts, part_align, *Ngas * sizeof(struct part)) != + if (posix_memalign((void **)parts, part_align, *Ngas * sizeof(struct part)) != 0) error("Error while allocating memory for SPH particles"); bzero(*parts, *Ngas * sizeof(struct part)); @@ -437,7 +437,7 @@ void read_ic_single(char* fileName, const struct unit_system* internal_units, /* Allocate memory to store star particles */ if (with_stars) { *Nstars = N[swift_type_star]; - if (posix_memalign((void*)sparts, spart_align, + if (posix_memalign((void **)sparts, spart_align, *Nstars * sizeof(struct spart)) != 0) error("Error while allocating memory for star particles"); bzero(*sparts, *Nstars * sizeof(struct spart)); @@ -449,7 +449,7 @@ void read_ic_single(char* fileName, const struct unit_system* internal_units, *Ngparts = (with_hydro ? N[swift_type_gas] : 0) + N[swift_type_dark_matter] + (with_stars ? N[swift_type_star] : 0); - if (posix_memalign((void*)gparts, gpart_align, + if (posix_memalign((void **)gparts, gpart_align, *Ngparts * sizeof(struct gpart)) != 0) error("Error while allocating memory for gravity particles"); bzero(*gparts, *Ngparts * sizeof(struct gpart)); @@ -765,7 +765,7 @@ void write_output_single(struct engine* e, const char* baseName, case swift_type_dark_matter: /* Allocate temporary array */ - if (posix_memalign((void*)&dmparts, gpart_align, + if (posix_memalign((void **)&dmparts, gpart_align, Ndm * sizeof(struct gpart)) != 0) error("Error while allocating temporart memory for DM particles"); bzero(dmparts, Ndm * sizeof(struct gpart)); diff --git a/src/space.c b/src/space.c index c0381b619f1aa8b1847fda84e3b15255cdfc9f85..2c05cdfcb20443d281a079089c451ec1c295c1cb 100644 --- a/src/space.c +++ b/src/space.c @@ -423,21 +423,21 @@ void space_regrid(struct space *s, int verbose) { /* Allocate the highest level of cells. */ s->tot_cells = s->nr_cells = cdim[0] * cdim[1] * cdim[2]; - if (posix_memalign((void *)&s->cells_top, cell_align, + if (posix_memalign((void **)&s->cells_top, cell_align, s->nr_cells * sizeof(struct cell)) != 0) error("Failed to allocate top-level cells."); bzero(s->cells_top, s->nr_cells * sizeof(struct cell)); /* Allocate the multipoles for the top-level cells. */ if (s->gravity) { - if (posix_memalign((void *)&s->multipoles_top, multipole_align, + if (posix_memalign((void **)&s->multipoles_top, multipole_align, s->nr_cells * sizeof(struct gravity_tensors)) != 0) error("Failed to allocate top-level multipoles."); bzero(s->multipoles_top, s->nr_cells * sizeof(struct gravity_tensors)); } /* Allocate the indices of local cells */ - if (posix_memalign((void *)&s->local_cells_top, SWIFT_STRUCT_ALIGNMENT, + if (posix_memalign((void **)&s->local_cells_top, SWIFT_STRUCT_ALIGNMENT, s->nr_cells * sizeof(int)) != 0) error("Failed to allocate indices of local top-level cells."); bzero(s->local_cells_top, s->nr_cells * sizeof(int)); @@ -1346,7 +1346,7 @@ void space_parts_sort(struct space *s, int *ind, size_t N, int min, int max, sort_struct.xparts = s->xparts; sort_struct.ind = ind; sort_struct.stack_size = 2 * (max - min + 1) + 10 + s->e->nr_threads; - if ((sort_struct.stack = + if ((sort_struct.stack = (struct qstack *) malloc(sizeof(struct qstack) * sort_struct.stack_size)) == NULL) error("Failed to allocate sorting stack."); for (unsigned int i = 0; i < sort_struct.stack_size; i++) @@ -1530,7 +1530,7 @@ void space_sparts_sort(struct space *s, int *ind, size_t N, int min, int max, sort_struct.sparts = s->sparts; sort_struct.ind = ind; sort_struct.stack_size = 2 * (max - min + 1) + 10 + s->e->nr_threads; - if ((sort_struct.stack = + if ((sort_struct.stack = (struct qstack *) malloc(sizeof(struct qstack) * sort_struct.stack_size)) == NULL) error("Failed to allocate sorting stack."); for (unsigned int i = 0; i < sort_struct.stack_size; i++) @@ -1713,7 +1713,7 @@ void space_gparts_sort(struct space *s, int *ind, size_t N, int min, int max, sort_struct.gparts = s->gparts; sort_struct.ind = ind; sort_struct.stack_size = 2 * (max - min + 1) + 10 + s->e->nr_threads; - if ((sort_struct.stack = + if ((sort_struct.stack = (struct qstack *) malloc(sizeof(struct qstack) * sort_struct.stack_size)) == NULL) error("Failed to allocate sorting stack."); for (unsigned int i = 0; i < sort_struct.stack_size; i++) @@ -2062,7 +2062,7 @@ void space_split_recursive(struct space *s, struct cell *c, const int allocate_buffer = (buff == NULL && gbuff == NULL && sbuff == NULL); if (allocate_buffer) { if (count > 0) { - if (posix_memalign((void *)&buff, SWIFT_STRUCT_ALIGNMENT, + if (posix_memalign((void **)&buff, SWIFT_STRUCT_ALIGNMENT, sizeof(struct cell_buff) * count) != 0) error("Failed to allocate temporary indices."); for (int k = 0; k < count; k++) { @@ -2072,7 +2072,7 @@ void space_split_recursive(struct space *s, struct cell *c, } } if (gcount > 0) { - if (posix_memalign((void *)&gbuff, SWIFT_STRUCT_ALIGNMENT, + if (posix_memalign((void **)&gbuff, SWIFT_STRUCT_ALIGNMENT, sizeof(struct cell_buff) * gcount) != 0) error("Failed to allocate temporary indices."); for (int k = 0; k < gcount; k++) { @@ -2082,7 +2082,7 @@ void space_split_recursive(struct space *s, struct cell *c, } } if (scount > 0) { - if (posix_memalign((void *)&sbuff, SWIFT_STRUCT_ALIGNMENT, + if (posix_memalign((void **)&sbuff, SWIFT_STRUCT_ALIGNMENT, sizeof(struct cell_buff) * scount) != 0) error("Failed to allocate temporary indices."); for (int k = 0; k < scount; k++) { @@ -2510,7 +2510,7 @@ void space_getcells(struct space *s, int nr_cells, struct cell **cells) { /* Is the cell buffer empty? */ if (s->cells_sub == NULL) { - if (posix_memalign((void *)&s->cells_sub, cell_align, + if (posix_memalign((void **)&s->cells_sub, cell_align, space_cellallocchunk * sizeof(struct cell)) != 0) error("Failed to allocate more cells."); @@ -2523,7 +2523,7 @@ void space_getcells(struct space *s, int nr_cells, struct cell **cells) { /* Is the multipole buffer empty? */ if (s->gravity && s->multipoles_sub == NULL) { if (posix_memalign( - (void *)&s->multipoles_sub, multipole_align, + (void **)&s->multipoles_sub, multipole_align, space_cellallocchunk * sizeof(struct gravity_tensors)) != 0) error("Failed to allocate more multipoles."); @@ -2740,8 +2740,8 @@ void space_first_init_sparts(struct space *s) { void space_init_parts_mapper(void *restrict map_data, int count, void *restrict extra_data) { - struct part *restrict parts = map_data; - const struct hydro_space *restrict hs = extra_data; + struct part *restrict parts = (struct part *)map_data; + const struct hydro_space *restrict hs = (struct hydro_space *)extra_data; for (int k = 0; k < count; k++) hydro_init_part(&parts[k], hs); } @@ -2766,7 +2766,7 @@ void space_init_parts(struct space *s, int verbose) { void space_init_gparts_mapper(void *restrict map_data, int count, void *restrict extra_data) { - struct gpart *gparts = map_data; + struct gpart *gparts = (struct gpart *)map_data; for (int k = 0; k < count; k++) gravity_init_gpart(&gparts[k]); } @@ -2791,8 +2791,8 @@ void space_init_gparts(struct space *s, int verbose) { void space_convert_quantities_mapper(void *restrict map_data, int count, void *restrict extra_data) { - struct space *s = extra_data; - struct part *restrict parts = map_data; + struct space *s = (struct space *)extra_data; + struct part *restrict parts = (struct part *)map_data; const ptrdiff_t index = parts - s->parts; struct xpart *restrict xparts = s->xparts + index; for (int k = 0; k < count; k++) @@ -3007,7 +3007,7 @@ void space_init(struct space *s, const struct swift_params *params, /* Allocate the extra parts array for the gas particles. */ if (Npart > 0) { - if (posix_memalign((void *)&s->xparts, xpart_align, + if (posix_memalign((void **)&s->xparts, xpart_align, Npart * sizeof(struct xpart)) != 0) error("Failed to allocate xparts."); bzero(s->xparts, Npart * sizeof(struct xpart)); @@ -3055,15 +3055,15 @@ void space_replicate(struct space *s, int replicate, int verbose) { struct gpart *gparts = NULL; struct spart *sparts = NULL; - if (posix_memalign((void *)&parts, part_align, + if (posix_memalign((void **)&parts, part_align, s->nr_parts * sizeof(struct part)) != 0) error("Failed to allocate new part array."); - if (posix_memalign((void *)&gparts, gpart_align, + if (posix_memalign((void **)&gparts, gpart_align, s->nr_gparts * sizeof(struct gpart)) != 0) error("Failed to allocate new gpart array."); - if (posix_memalign((void *)&sparts, spart_align, + if (posix_memalign((void **)&sparts, spart_align, s->nr_sparts * sizeof(struct spart)) != 0) error("Failed to allocate new spart array."); @@ -3300,10 +3300,10 @@ void space_struct_restore(struct space *s, FILE *stream) { if (s->nr_parts > 0) { /* Need the memory for these. */ - if (posix_memalign((void *)&s->parts, part_align, + if (posix_memalign((void **)&s->parts, part_align, s->size_parts * sizeof(struct part)) != 0) error("Failed to allocate restore part array."); - if (posix_memalign((void *)&s->xparts, xpart_align, + if (posix_memalign((void **)&s->xparts, xpart_align, s->size_parts * sizeof(struct xpart)) != 0) error("Failed to allocate restore xpart array."); @@ -3314,7 +3314,7 @@ void space_struct_restore(struct space *s, FILE *stream) { } s->gparts = NULL; if (s->nr_gparts > 0) { - if (posix_memalign((void *)&s->gparts, gpart_align, + if (posix_memalign((void **)&s->gparts, gpart_align, s->size_gparts * sizeof(struct gpart)) != 0) error("Failed to allocate restore gpart array."); @@ -3324,7 +3324,7 @@ void space_struct_restore(struct space *s, FILE *stream) { s->sparts = NULL; if (s->nr_sparts > 0) { - if (posix_memalign((void *)&s->sparts, spart_align, + if (posix_memalign((void **)&s->sparts, spart_align, s->size_sparts * sizeof(struct spart)) != 0) error("Failed to allocate restore spart array.");