Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use of calloc. #669

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions parsec/class/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2020- The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
*/

#include "parsec/parsec_config.h"
Expand Down Expand Up @@ -217,7 +218,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 +266,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
7 changes: 4 additions & 3 deletions parsec/data_dist/matrix/map_operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2011-2021 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
*/

#include "parsec/runtime.h"
Expand Down Expand Up @@ -106,7 +107,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 +118,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 +135,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
3 changes: 2 additions & 1 deletion parsec/data_dist/matrix/vector_two_dim_cyclic.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2009-2021 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
*/

#include "parsec/parsec_config.h"
Expand Down Expand Up @@ -251,7 +252,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
7 changes: 4 additions & 3 deletions parsec/interfaces/ptg/ptg-compiler/jdf2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2009-2023 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
*/

#include "parsec/parsec_config.h"
Expand Down Expand Up @@ -2044,7 +2045,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 +8414,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
5 changes: 3 additions & 2 deletions parsec/maxheap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2009-2018 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
*/

#include "parsec/parsec_config.h"
Expand All @@ -25,7 +26,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 +68,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
4 changes: 2 additions & 2 deletions parsec/mca/device/device.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
*
* Copyright (c) 2013-2023 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
*/

#include "parsec/parsec_config.h"
Expand Down 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
3 changes: 2 additions & 1 deletion parsec/mca/sched/lfq/sched_lfq_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2013-2020 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -64,7 +65,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
3 changes: 2 additions & 1 deletion parsec/mca/sched/lhq/sched_lhq_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2013-2020 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -70,7 +71,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
3 changes: 2 additions & 1 deletion parsec/mca/sched/ltq/sched_ltq_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2013-2019 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -63,7 +64,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
3 changes: 2 additions & 1 deletion parsec/mca/sched/pbq/sched_pbq_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2013-2020 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -61,7 +62,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
4 changes: 2 additions & 2 deletions parsec/parsec_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2012-2023 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
*/

#if !defined(PARSEC_CONFIG_H_HAS_BEEN_INCLUDED)
Expand Down Expand Up @@ -337,8 +338,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
7 changes: 4 additions & 3 deletions tests/class/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2017-2021 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
*/

#include "parsec/runtime.h"
Expand Down Expand Up @@ -597,9 +598,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
5 changes: 3 additions & 2 deletions tests/class/lifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2009-2024 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
*/

#include "parsec/runtime.h"
Expand Down Expand Up @@ -254,8 +255,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
5 changes: 3 additions & 2 deletions tests/class/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2009-2024 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
*/

#include "parsec/runtime.h"
Expand Down Expand Up @@ -299,8 +300,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
3 changes: 2 additions & 1 deletion tests/class/rwlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2017-2018 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
*/

#include "parsec/runtime.h"
Expand Down Expand Up @@ -138,7 +139,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
3 changes: 2 additions & 1 deletion tests/collections/redistribute/redistribute_check2.jdf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extern "C" %{
* Copyright (c) 2017-2021 The Universiy of Tennessee and The Universiy
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
*/
#include "redistribute_test.h"

Expand Down Expand Up @@ -143,7 +144,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
Loading
Loading