Skip to content

Commit

Permalink
Fix use of calloc.
Browse files Browse the repository at this point in the history
The count is first, then the sizeof.

Signed-off-by: George Bosilca <gbosilca@nvidia.com>
  • Loading branch information
bosilca committed Sep 10, 2024
1 parent dcba0c0 commit 2904dac
Show file tree
Hide file tree
Showing 26 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions parsec/class/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void parsec_info_object_array_init(parsec_info_object_array_t *oa, parsec_info_t
if(oa->known_infos == 0)
oa->info_objects = NULL;
else
oa->info_objects = calloc(sizeof(void*), oa->known_infos);
oa->info_objects = calloc(oa->known_infos, sizeof(void*));
oa->infos = nfo;
oa->cons_obj = cons_obj;
}
Expand Down Expand Up @@ -265,7 +265,7 @@ static void parsec_ioa_resize_and_rdlock(parsec_info_object_array_t *oa, parsec_
oa->info_objects = realloc(oa->info_objects, sizeof(void *) * ns);
memset(&oa->info_objects[oa->known_infos - 1], 0, ns - oa->known_infos);
} else {
oa->info_objects = calloc(sizeof(void*), ns);
oa->info_objects = calloc(ns, sizeof(void*));
}
oa->known_infos = ns;
}
Expand Down
6 changes: 3 additions & 3 deletions parsec/data_dist/matrix/map_operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static const parsec_symbol_t symb_column = {
.flags = PARSEC_SYMBOL_IS_STANDALONE
};

static inline int affinity_of_map_operator(parsec_task_t *this_task,
static inline int affinity_of_map_operator(const parsec_task_t *this_task,
parsec_data_ref_t *ref)
{
const parsec_map_operator_taskpool_t *__tp = (const parsec_map_operator_taskpool_t*)this_task->taskpool;
Expand All @@ -117,7 +117,7 @@ static inline int affinity_of_map_operator(parsec_task_t *this_task,
return 1;
}

static inline int initial_data_of_map_operator(parsec_task_t *this_task,
static inline int initial_data_of_map_operator(const parsec_task_t *this_task,
parsec_data_ref_t *refs)
{
int __flow_nb = 0;
Expand All @@ -134,7 +134,7 @@ static inline int initial_data_of_map_operator(parsec_task_t *this_task,
return __flow_nb;
}

static inline int final_data_of_map_operator(parsec_task_t *this_task,
static inline int final_data_of_map_operator(const parsec_task_t *this_task,
parsec_data_ref_t *data_refs)
{
int __flow_nb = 0;
Expand Down
2 changes: 1 addition & 1 deletion parsec/data_dist/matrix/vector_two_dim_cyclic.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ static parsec_data_t* vector_twoDBC_data_of(parsec_data_collection_t *desc, ...)
#endif

/* Compute the local tile row */
assert( dc->super.bsiz == dc->super.mb );
assert( dc->super.bsiz == (size_t)dc->super.mb );

local_m = m / dc->lcm;

Expand Down
5 changes: 3 additions & 2 deletions parsec/interfaces/dtd/insert_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ parsec_dtd_taskpool_destructor(parsec_dtd_taskpool_t *tp)
free((void *)tp->super.profiling_array);
#endif /* defined(PARSEC_PROF_TRACE) */

if( tp->super.taskpool_name != NULL ) {
if( NULL != tp->super.taskpool_name) {
free(tp->super.taskpool_name);
tp->super.taskpool_name = NULL;
}
Expand Down Expand Up @@ -2303,6 +2303,7 @@ static parsec_hook_return_t parsec_dtd_gpu_task_submit(parsec_execution_stream_t
return device->kernel_scheduler(device, es, gpu_task);
#else
parsec_warning("DTD: Selected best device is a GPU, but no GPU is supported at compile time. Falling back to CPU");
(void)this_task;
return PARSEC_HOOK_RETURN_NEXT;
#endif
}
Expand Down Expand Up @@ -3463,7 +3464,7 @@ parsec_arena_datatype_t *parsec_dtd_create_arena_datatype(parsec_context_t *ctx,
if(NULL != new_adt)
return NULL;
#endif
new_adt = calloc(sizeof(parsec_arena_datatype_t), 1);
new_adt = calloc(1, sizeof(parsec_arena_datatype_t));
if(NULL == new_adt)
return NULL;
new_adt->ht_item.key = my_id;
Expand Down
6 changes: 3 additions & 3 deletions parsec/interfaces/ptg/ptg-compiler/jdf2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -2044,7 +2044,7 @@ static void jdf_generate_affinity( const jdf_t *jdf, const jdf_function_entry_t
assert( NULL == data_affinity->var );
}

coutput("static inline int %s(%s *this_task,\n"
coutput("static inline int %s(const %s *this_task,\n"
" parsec_data_ref_t *ref)\n"
"{\n"
" const __parsec_%s_internal_taskpool_t *__parsec_tp = (const __parsec_%s_internal_taskpool_t*)this_task->taskpool;\n",
Expand Down Expand Up @@ -8413,14 +8413,14 @@ int jdf_force_termdet_dynamic(jdf_t* jdf)
return rc;
}

termdet_expr = (jdf_expr_t *)calloc(sizeof(jdf_expr_t), 1);
termdet_expr = (jdf_expr_t *)calloc(1, sizeof(jdf_expr_t));
termdet_expr->op = JDF_STRING;
termdet_expr->local_variables = NULL;
termdet_expr->scope = -1;
termdet_expr->alias = NULL;
termdet_expr->jdf_var = strdup(JDF_PROP_TERMDET_DYNAMIC);

property = (jdf_def_list_t*)calloc(sizeof(jdf_def_list_t), 1);
property = (jdf_def_list_t*)calloc(1, sizeof(jdf_def_list_t));
property->expr = termdet_expr;
property->name = strdup(JDF_PROP_TERMDET_NAME);
property->next = jdf->global_properties;
Expand Down
4 changes: 2 additions & 2 deletions parsec/maxheap.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static inline int hiBit(unsigned int n)

parsec_heap_t* heap_create(void)
{
parsec_heap_t* heap = calloc(sizeof(parsec_heap_t), 1);
parsec_heap_t* heap = calloc(1, sizeof(parsec_heap_t));
/* Point back to the parent structure */
heap->list_item.list_next = (parsec_list_item_t*)heap;
heap->list_item.list_prev = (parsec_list_item_t*)heap;
Expand Down Expand Up @@ -67,7 +67,7 @@ void heap_insert(parsec_heap_t * heap, parsec_task_t * elem)
}
parents_size = level_counter;

parsec_task_t ** parents = calloc(sizeof(parsec_task_t *), level_counter);
parsec_task_t ** parents = calloc(level_counter, sizeof(parsec_task_t *));
// now the bitmask is two places farther than we want it, so back down
bitmask = bitmask >> 2;

Expand Down
2 changes: 1 addition & 1 deletion parsec/mca/device/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ void parsec_compute_best_unit( uint64_t length, float* updated_value, char** bes

void parsec_devices_save_statistics(uint64_t **pstats) {
if(NULL == *pstats) {
*pstats = (uint64_t*)calloc(sizeof(uint64_t), parsec_nb_devices * 7 /* see below for the number of arrays */);
*pstats = (uint64_t*)calloc(parsec_nb_devices * 7 /* see below for the number of arrays */, sizeof(uint64_t));
}
else {
memset(*pstats, 0, parsec_nb_devices * sizeof(uint64_t) * 7);
Expand Down
2 changes: 1 addition & 1 deletion parsec/mca/sched/lfq/sched_lfq_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static int flow_lfq_init(parsec_execution_stream_t* es, struct parsec_barrier_t*
vp = es->virtual_process;

/* Every flow creates its own local object */
sched_obj = (parsec_mca_sched_local_queues_scheduler_object_t*)calloc(sizeof(parsec_mca_sched_local_queues_scheduler_object_t), 1);
sched_obj = (parsec_mca_sched_local_queues_scheduler_object_t*)calloc(1, sizeof(parsec_mca_sched_local_queues_scheduler_object_t));
es->scheduler_object = sched_obj;
if( 0 == es->th_id ) { /* And flow 0 creates the system_queue */
sched_obj->system_queue = PARSEC_OBJ_NEW(parsec_dequeue_t);
Expand Down
2 changes: 1 addition & 1 deletion parsec/mca/sched/lhq/sched_lhq_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static int flow_lhq_init(parsec_execution_stream_t* ces, struct parsec_barrier_t
/* First of all, we allocate the scheduling object memory for all threads */
es = vp->execution_streams[t];

sched_obj = (parsec_mca_sched_local_queues_scheduler_object_t*)calloc(sizeof(parsec_mca_sched_local_queues_scheduler_object_t), 1);
sched_obj = (parsec_mca_sched_local_queues_scheduler_object_t*)calloc(1, sizeof(parsec_mca_sched_local_queues_scheduler_object_t));
es->scheduler_object = sched_obj;

if( es->th_id == 0 ) {
Expand Down
2 changes: 1 addition & 1 deletion parsec/mca/sched/ltq/sched_ltq_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static int flow_ltq_init(parsec_execution_stream_t* es, struct parsec_barrier_t*
uint32_t queue_size;
parsec_vp_t * vp = es->virtual_process;

sched_obj = (parsec_mca_sched_local_queues_scheduler_object_t*)calloc(sizeof(parsec_mca_sched_local_queues_scheduler_object_t), 1);
sched_obj = (parsec_mca_sched_local_queues_scheduler_object_t*)calloc(1, sizeof(parsec_mca_sched_local_queues_scheduler_object_t));
es->scheduler_object = sched_obj;

if( es->th_id == 0 ) {
Expand Down
2 changes: 1 addition & 1 deletion parsec/mca/sched/pbq/sched_pbq_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static int flow_pbq_init(parsec_execution_stream_t* es, struct parsec_barrier_t*
uint32_t queue_size = 0;

/* Every flow creates its own local object */
sched_obj = (parsec_mca_sched_local_queues_scheduler_object_t*)calloc(sizeof(parsec_mca_sched_local_queues_scheduler_object_t), 1);
sched_obj = (parsec_mca_sched_local_queues_scheduler_object_t*)calloc(1, sizeof(parsec_mca_sched_local_queues_scheduler_object_t));
es->scheduler_object = sched_obj;
if( es->th_id == 0 ) { /* And flow 0 creates the system_queue */
sched_obj->system_queue = PARSEC_OBJ_NEW(parsec_dequeue_t);
Expand Down
3 changes: 1 addition & 2 deletions parsec/parsec_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ typedef struct parsec_data_ref_s {
parsec_data_key_t key;
} parsec_data_ref_t;

typedef int (parsec_data_ref_fn_t)(parsec_task_t *task,
parsec_data_ref_t *ref);
typedef int (parsec_data_ref_fn_t)(const parsec_task_t *task, parsec_data_ref_t *ref);

#define PARSEC_HAS_IN_IN_DEPENDENCIES 0x0001
#define PARSEC_HAS_OUT_OUT_DEPENDENCIES 0x0002
Expand Down
6 changes: 3 additions & 3 deletions tests/class/atomics.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ int main(int argc, char *argv[])
}
}

threads = calloc(sizeof(pthread_t), nb_tests);
params = calloc(sizeof(param_t), nb_tests);
values = calloc(sizeof(values_t), nb_tests+2);
threads = calloc(nb_tests, sizeof(pthread_t));
params = calloc(nb_tests, sizeof(param_t));
values = calloc(nb_tests+2, sizeof(values_t));

gettimeofday(&now, NULL);
srand48(now.tv_usec ^ getpid());
Expand Down
2 changes: 1 addition & 1 deletion tests/class/future.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int main(int argc, char* argv[])
c_fut = PARSEC_OBJ_NEW(parsec_countable_future_t);
parsec_future_init(c_fut, NULL, cores);
printf("running with %d cores and %d copies\n", cores, ncopy);
threads = calloc(sizeof(pthread_t), cores);
threads = calloc(cores, sizeof(pthread_t));

fut_array = malloc(cores*ncopy*sizeof(parsec_base_future_t*));
data = malloc(cores*ncopy*sizeof(int));
Expand Down
2 changes: 1 addition & 1 deletion tests/class/future_datacopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ int main(int argc, char* argv[])
}

printf("running with %d cores and %d copies\n", cores, ncopy);
threads = calloc(sizeof(pthread_t), cores);
threads = calloc(cores, sizeof(pthread_t));

fut_array = malloc(ncopy*sizeof(parsec_datacopy_future_t*));
data = malloc(cores*ncopy*sizeof(int));
Expand Down
6 changes: 3 additions & 3 deletions tests/class/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,9 @@ int main(int argc, char *argv[])
}
}

threads = calloc(sizeof(pthread_t), maxthreads);
params = calloc(sizeof(param_t), maxthreads+1);
keys = calloc(sizeof(uint64_t), nb_tests);
threads = calloc(maxthreads, sizeof(pthread_t));
params = calloc(maxthreads+1, sizeof(param_t));
keys = calloc(nb_tests, sizeof(uint64_t));
init_keys(keys, nb_tests, seed, structured_keys);

for(md_tuning = md_tuning_min; md_tuning < md_tuning_max; md_tuning += md_tuning_inc) {
Expand Down
4 changes: 2 additions & 2 deletions tests/class/lifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ int main(int argc, char *argv[])
}
}

threads = (pthread_t*)calloc(sizeof(pthread_t), nbthreads);
times = (uint64_t*)calloc(sizeof(uint64_t), nbthreads);
threads = (pthread_t*)calloc(nbthreads, sizeof(pthread_t));
times = (uint64_t*)calloc(nbthreads, sizeof(uint64_t));

PARSEC_OBJ_CONSTRUCT(&lifo1, parsec_lifo_t);
PARSEC_OBJ_CONSTRUCT(&lifo2, parsec_lifo_t);
Expand Down
4 changes: 2 additions & 2 deletions tests/class/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ int main(int argc, char *argv[])
}
}

threads = (pthread_t*)calloc(sizeof(pthread_t), nbthreads);
times = (uint64_t*)calloc(sizeof(uint64_t), nbthreads);
threads = (pthread_t*)calloc(nbthreads, sizeof(pthread_t));
times = (uint64_t*)calloc(nbthreads, sizeof(uint64_t));

PARSEC_OBJ_CONSTRUCT( &l1, parsec_list_t );
PARSEC_OBJ_CONSTRUCT( &l2, parsec_list_t );
Expand Down
2 changes: 1 addition & 1 deletion tests/class/rwlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ int main(int argc, char *argv[])

parsec_atomic_rwlock_init(&rwlock);

threads = (pthread_t*)calloc(sizeof(pthread_t), maxthreads);
threads = (pthread_t*)calloc(maxthreads, sizeof(pthread_t));

for( nbthreads = minthreads; nbthreads < maxthreads; nbthreads++) {
parsec_barrier_init(&barrier, NULL, nbthreads+1);
Expand Down
2 changes: 1 addition & 1 deletion tests/collections/redistribute/redistribute_check2.jdf
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ int parsec_redistribute_check2(parsec_context_t *parsec,
int nb_threads = parsec->virtual_processes[0]->nb_cores;

/* Used for error accumulation */
long long int *info = (long long int *)calloc(sizeof(long long int), nb_threads);
long long int *info = (long long int *)calloc(nb_threads, sizeof(long long int));

parsec_redistribute_check2 = parsec_redistribute_check2_New(
(parsec_tiled_matrix_t *)dcY,
Expand Down
2 changes: 1 addition & 1 deletion tests/collections/reshape/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ int reshape_set_matrix_value_position_swap(parsec_execution_stream_t *es,

int check_matrix_equal(parsec_matrix_block_cyclic_t dcA, parsec_matrix_block_cyclic_t dcA_check){
int ret = 0;
for(int i=0; i < dcA_check.super.nb_local_tiles * dcA_check.super.bsiz; i++){
for(size_t i = 0; i < (dcA_check.super.nb_local_tiles * dcA_check.super.bsiz); i++) {
if( ((int*)dcA.mat)[i] != ((int*)dcA_check.mat)[i]){
ret = 1;
break;
Expand Down
2 changes: 1 addition & 1 deletion tests/dsl/dtd/dtd_test_new_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ int main(int argc, char **argv)
parsec_dtd_task_class_add_chore(dtd_tp, fourth_tc, PARSEC_DEV_CPU, cpu_reduce);

parsec_dtd_tile_t **new_tiles;
new_tiles = (parsec_dtd_tile_t**)calloc(sizeof(parsec_dtd_tile_t *), NCASE*world);
new_tiles = (parsec_dtd_tile_t**)calloc(NCASE*world, sizeof(parsec_dtd_tile_t *));

acc = 0;

Expand Down
2 changes: 1 addition & 1 deletion tests/dsl/ptg/branching/branching_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ parsec_data_collection_t *create_and_distribute_data(int rank, int world, int si
#endif
parsec_type_create_contiguous(size, parsec_datatype_int32_t, &d->default_dtt);

m->data = calloc(sizeof(parsec_data_t*), nb);
m->data = calloc(nb, sizeof(parsec_data_t*));
m->nt = nb;
m->size = size;
m->ptr = (int32_t*)malloc(nb * size * sizeof(int32_t));
Expand Down
2 changes: 1 addition & 1 deletion tests/dsl/ptg/choice/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int main(int argc, char *argv[])
dcA = create_and_distribute_data(rank, world, size);
parsec_data_collection_set_key(dcA, "A");

decision = (int*)calloc(sizeof(int), nb+1);
decision = (int*)calloc(nb+1, sizeof(int));

choice = choice_new(dcA, size, decision, nb, world);
rc = parsec_context_add_taskpool(parsec, choice);
Expand Down
2 changes: 1 addition & 1 deletion tests/profiling/async.jdf
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ int main( int argc, char** argv )
profiling_save_iinfo("NB", NB);
#endif

taskqueue = (parsec_task_t**)calloc(sizeof(parsec_task_t*), (NB+1));
taskqueue = (parsec_task_t**)calloc(NB+1, sizeof(parsec_task_t*));
/**
* Build the data and the arena to hold it up.
*/
Expand Down
2 changes: 1 addition & 1 deletion tools/profiling/dbpreader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ static dbp_multifile_reader_t *open_files(int nbfiles, char **filenames)
dbp->last_error = SUCCESS;
dbp->dico_size = 0;
dbp->dico_allocated = 8;
dbp->dico_keys = calloc(sizeof(dbp_dictionary_t), dbp->dico_allocated);
dbp->dico_keys = calloc(dbp->dico_allocated, sizeof(dbp_dictionary_t));

n = 0;
for(i = 0; i < nbfiles; i++) {
Expand Down

0 comments on commit 2904dac

Please sign in to comment.