Skip to content

Commit 5989709

Browse files
authored
[OpenMP] Miscellaneous small code improvements (#95603)
Removes a few uninitialized variables, possible resource leaks, and redundant code.
1 parent 57abd4e commit 5989709

File tree

9 files changed

+32
-20
lines changed

9 files changed

+32
-20
lines changed

openmp/runtime/src/kmp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4731,6 +4731,8 @@ class kmp_safe_raii_file_t {
47314731
: f(nullptr) {
47324732
open(filename, mode, env_var);
47334733
}
4734+
kmp_safe_raii_file_t(const kmp_safe_raii_file_t &other) = delete;
4735+
kmp_safe_raii_file_t &operator=(const kmp_safe_raii_file_t &other) = delete;
47344736
~kmp_safe_raii_file_t() { close(); }
47354737

47364738
/// Open filename using mode. This is automatically closed in the destructor.

openmp/runtime/src/kmp_affinity.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,7 +1970,6 @@ static bool __kmp_affinity_create_hwloc_map(kmp_i18n_id_t *const msg_id) {
19701970
hw_thread.ids[index + 1] = sub_id;
19711971
index--;
19721972
}
1973-
prev = memory;
19741973
}
19751974
prev = obj;
19761975
}
@@ -4989,7 +4988,7 @@ static void __kmp_aux_affinity_initialize(kmp_affinity_t &affinity) {
49894988
int depth = __kmp_topology->get_depth();
49904989

49914990
// Create the table of masks, indexed by thread Id.
4992-
unsigned numUnique;
4991+
unsigned numUnique = 0;
49934992
int numAddrs = __kmp_topology->get_num_hw_threads();
49944993
// If OMP_PLACES=cores:<attribute> specified, then attempt
49954994
// to make OS Id mask table using those attributes

openmp/runtime/src/kmp_affinity.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class KMPHwlocAffinity : public KMPAffinity {
2929
mask = hwloc_bitmap_alloc();
3030
this->zero();
3131
}
32+
Mask(const Mask &other) = delete;
33+
Mask &operator=(const Mask &other) = delete;
3234
~Mask() { hwloc_bitmap_free(mask); }
3335
void set(int i) override { hwloc_bitmap_set(mask, i); }
3436
bool is_set(int i) const override { return hwloc_bitmap_isset(mask, i); }
@@ -1271,7 +1273,7 @@ class hierarchy_info {
12711273
leaf. It corresponds to the number of entries in numPerLevel if we exclude
12721274
all but one trailing 1. */
12731275
kmp_uint32 depth;
1274-
kmp_uint32 base_num_threads;
1276+
kmp_uint32 base_num_threads = 0;
12751277
enum init_status { initialized = 0, not_initialized = 1, initializing = 2 };
12761278
volatile kmp_int8 uninitialized; // 0=initialized, 1=not initialized,
12771279
// 2=initialization in progress
@@ -1281,8 +1283,8 @@ class hierarchy_info {
12811283
the parent of a node at level i has. For example, if we have a machine
12821284
with 4 packages, 4 cores/package and 2 HT per core, then numPerLevel =
12831285
{2, 4, 4, 1, 1}. All empty levels are set to 1. */
1284-
kmp_uint32 *numPerLevel;
1285-
kmp_uint32 *skipPerLevel;
1286+
kmp_uint32 *numPerLevel = nullptr;
1287+
kmp_uint32 *skipPerLevel = nullptr;
12861288

12871289
void deriveLevels() {
12881290
int hier_depth = __kmp_topology->get_depth();

openmp/runtime/src/kmp_barrier.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,8 @@ static void __kmp_dist_barrier_release(
444444
next_go = my_current_iter + distributedBarrier::MAX_ITERS;
445445
my_go_index = tid / b->threads_per_go;
446446
if (this_thr->th.th_used_in_team.load() == 3) {
447-
KMP_COMPARE_AND_STORE_ACQ32(&(this_thr->th.th_used_in_team), 3, 1);
447+
(void)KMP_COMPARE_AND_STORE_ACQ32(&(this_thr->th.th_used_in_team), 3,
448+
1);
448449
}
449450
// Check if go flag is set
450451
if (b->go[my_go_index].go.load() != next_go) {

openmp/runtime/src/kmp_csupport.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ void __kmpc_critical_with_hint(ident_t *loc, kmp_int32 global_tid,
15891589
kmp_dyna_lockseq_t lockseq = __kmp_map_hint_to_lock(hint);
15901590
if (*lk == 0) {
15911591
if (KMP_IS_D_LOCK(lockseq)) {
1592-
KMP_COMPARE_AND_STORE_ACQ32(
1592+
(void)KMP_COMPARE_AND_STORE_ACQ32(
15931593
(volatile kmp_int32 *)&((kmp_base_tas_lock_t *)crit)->poll, 0,
15941594
KMP_GET_D_TAG(lockseq));
15951595
} else {
@@ -3486,8 +3486,8 @@ __kmp_enter_critical_section_reduce_block(ident_t *loc, kmp_int32 global_tid,
34863486
// Check if it is initialized.
34873487
if (*lk == 0) {
34883488
if (KMP_IS_D_LOCK(__kmp_user_lock_seq)) {
3489-
KMP_COMPARE_AND_STORE_ACQ32((volatile kmp_int32 *)crit, 0,
3490-
KMP_GET_D_TAG(__kmp_user_lock_seq));
3489+
(void)KMP_COMPARE_AND_STORE_ACQ32((volatile kmp_int32 *)crit, 0,
3490+
KMP_GET_D_TAG(__kmp_user_lock_seq));
34913491
} else {
34923492
__kmp_init_indirect_csptr(crit, loc, global_tid,
34933493
KMP_GET_I_TAG(__kmp_user_lock_seq));

openmp/runtime/src/kmp_runtime.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,8 +1983,8 @@ int __kmp_fork_call(ident_t *loc, int gtid,
19831983

19841984
#if OMPT_SUPPORT
19851985
ompt_data_t ompt_parallel_data = ompt_data_none;
1986-
ompt_data_t *parent_task_data;
1987-
ompt_frame_t *ompt_frame;
1986+
ompt_data_t *parent_task_data = NULL;
1987+
ompt_frame_t *ompt_frame = NULL;
19881988
void *return_address = NULL;
19891989

19901990
if (ompt_enabled.enabled) {
@@ -5765,8 +5765,8 @@ void __kmp_free_team(kmp_root_t *root,
57655765
for (f = 1; f < team->t.t_nproc; ++f) {
57665766
KMP_DEBUG_ASSERT(team->t.t_threads[f]);
57675767
if (__kmp_barrier_gather_pattern[bs_forkjoin_barrier] == bp_dist_bar) {
5768-
KMP_COMPARE_AND_STORE_ACQ32(&(team->t.t_threads[f]->th.th_used_in_team),
5769-
1, 2);
5768+
(void)KMP_COMPARE_AND_STORE_ACQ32(
5769+
&(team->t.t_threads[f]->th.th_used_in_team), 1, 2);
57705770
}
57715771
__kmp_free_thread(team->t.t_threads[f]);
57725772
}
@@ -9220,8 +9220,8 @@ void __kmp_add_threads_to_team(kmp_team_t *team, int new_nthreads) {
92209220
// to wake it up.
92219221
for (int f = 1; f < new_nthreads; ++f) {
92229222
KMP_DEBUG_ASSERT(team->t.t_threads[f]);
9223-
KMP_COMPARE_AND_STORE_ACQ32(&(team->t.t_threads[f]->th.th_used_in_team), 0,
9224-
3);
9223+
(void)KMP_COMPARE_AND_STORE_ACQ32(
9224+
&(team->t.t_threads[f]->th.th_used_in_team), 0, 3);
92259225
if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) { // Wake up sleeping threads
92269226
__kmp_resume_32(team->t.t_threads[f]->th.th_info.ds.ds_gtid,
92279227
(kmp_flag_32<false, false> *)NULL);

openmp/runtime/src/kmp_tasking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5276,7 +5276,7 @@ static void __kmp_taskloop(ident_t *loc, int gtid, kmp_task_t *task, int if_val,
52765276
switch (sched) {
52775277
case 0: // no schedule clause specified, we can choose the default
52785278
// let's try to schedule (team_size*10) tasks
5279-
grainsize = thread->th.th_team_nproc * 10;
5279+
grainsize = thread->th.th_team_nproc * static_cast<kmp_uint64>(10);
52805280
KMP_FALLTHROUGH();
52815281
case 2: // num_tasks provided
52825282
if (grainsize > tc) {

openmp/runtime/src/kmp_wait_release.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ template <> struct flag_traits<flag_oncore> {
104104
template <flag_type FlagType> class kmp_flag {
105105
protected:
106106
flag_properties t; /**< "Type" of the flag in loc */
107-
kmp_info_t *waiting_threads[1]; /**< Threads sleeping on this thread. */
107+
/**< Threads sleeping on this thread. */
108+
kmp_info_t *waiting_threads[1] = {nullptr};
108109
kmp_uint32 num_waiting_threads; /**< Num threads sleeping on this thread. */
109110
std::atomic<bool> *sleepLoc;
110111

@@ -140,7 +141,7 @@ template <typename PtrType, flag_type FlagType, bool Sleepable>
140141
class kmp_flag_native : public kmp_flag<FlagType> {
141142
protected:
142143
volatile PtrType *loc;
143-
PtrType checker; /**< When flag==checker, it has been released. */
144+
PtrType checker = (PtrType)0; /**< When flag==checker, it has been released */
144145
typedef flag_traits<FlagType> traits_type;
145146

146147
public:
@@ -234,7 +235,7 @@ template <typename PtrType, flag_type FlagType, bool Sleepable>
234235
class kmp_flag_atomic : public kmp_flag<FlagType> {
235236
protected:
236237
std::atomic<PtrType> *loc; /**< Pointer to flag location to wait on */
237-
PtrType checker; /**< Flag == checker means it has been released. */
238+
PtrType checker = (PtrType)0; /**< Flag==checker means it has been released */
238239
public:
239240
typedef flag_traits<FlagType> traits_type;
240241
typedef PtrType flag_t;
@@ -935,7 +936,8 @@ class kmp_flag_oncore : public kmp_flag_native<kmp_uint64, flag_oncore, false> {
935936
kmp_uint32 offset; /**< Portion of flag of interest for an operation. */
936937
bool flag_switch; /**< Indicates a switch in flag location. */
937938
enum barrier_type bt; /**< Barrier type. */
938-
kmp_info_t *this_thr; /**< Thread to redirect to different flag location. */
939+
/**< Thread to redirect to different flag location. */
940+
kmp_info_t *this_thr = nullptr;
939941
#if USE_ITT_BUILD
940942
void *itt_sync_obj; /**< ITT object to pass to new flag location. */
941943
#endif

openmp/runtime/src/ompt-general.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ static ompt_start_tool_result_t *ompt_start_tool_result = NULL;
104104

105105
#if KMP_OS_WINDOWS
106106
static HMODULE ompt_tool_module = NULL;
107+
static HMODULE ompt_archer_module = NULL;
107108
#define OMPT_DLCLOSE(Lib) FreeLibrary(Lib)
108109
#else
109110
static void *ompt_tool_module = NULL;
111+
static void *ompt_archer_module = NULL;
110112
#define OMPT_DLCLOSE(Lib) dlclose(Lib)
111113
#endif
112114

@@ -374,13 +376,15 @@ ompt_try_start_tool(unsigned int omp_version, const char *runtime_version) {
374376
"Tool was started and is using the OMPT interface.\n");
375377
OMPT_VERBOSE_INIT_PRINT(
376378
"----- END LOGGING OF TOOL REGISTRATION -----\n");
379+
ompt_archer_module = h;
377380
return ret;
378381
}
379382
OMPT_VERBOSE_INIT_CONTINUED_PRINT(
380383
"Found but not using the OMPT interface.\n");
381384
} else {
382385
OMPT_VERBOSE_INIT_CONTINUED_PRINT("Failed: %s\n", dlerror());
383386
}
387+
OMPT_DLCLOSE(h);
384388
}
385389
}
386390
#endif
@@ -521,6 +525,8 @@ void ompt_fini() {
521525
}
522526
}
523527

528+
if (ompt_archer_module)
529+
OMPT_DLCLOSE(ompt_archer_module);
524530
if (ompt_tool_module)
525531
OMPT_DLCLOSE(ompt_tool_module);
526532
memset(&ompt_enabled, 0, sizeof(ompt_enabled));

0 commit comments

Comments
 (0)