[Openmp-commits] [openmp] 5989709 - [OpenMP] Miscellaneous small code improvements (#95603)
via Openmp-commits
openmp-commits at lists.llvm.org
Thu Aug 15 08:42:26 PDT 2024
Author: Hansang Bae
Date: 2024-08-15T10:42:22-05:00
New Revision: 598970904736f3535939f6a5525022219e4ae517
URL: https://github.com/llvm/llvm-project/commit/598970904736f3535939f6a5525022219e4ae517
DIFF: https://github.com/llvm/llvm-project/commit/598970904736f3535939f6a5525022219e4ae517.diff
LOG: [OpenMP] Miscellaneous small code improvements (#95603)
Removes a few uninitialized variables, possible resource leaks, and
redundant code.
Added:
Modified:
openmp/runtime/src/kmp.h
openmp/runtime/src/kmp_affinity.cpp
openmp/runtime/src/kmp_affinity.h
openmp/runtime/src/kmp_barrier.cpp
openmp/runtime/src/kmp_csupport.cpp
openmp/runtime/src/kmp_runtime.cpp
openmp/runtime/src/kmp_tasking.cpp
openmp/runtime/src/kmp_wait_release.h
openmp/runtime/src/ompt-general.cpp
Removed:
################################################################################
diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h
index 916c1dc2570087..4f4fb3292d63ee 100644
--- a/openmp/runtime/src/kmp.h
+++ b/openmp/runtime/src/kmp.h
@@ -4731,6 +4731,8 @@ class kmp_safe_raii_file_t {
: f(nullptr) {
open(filename, mode, env_var);
}
+ kmp_safe_raii_file_t(const kmp_safe_raii_file_t &other) = delete;
+ kmp_safe_raii_file_t &operator=(const kmp_safe_raii_file_t &other) = delete;
~kmp_safe_raii_file_t() { close(); }
/// Open filename using mode. This is automatically closed in the destructor.
diff --git a/openmp/runtime/src/kmp_affinity.cpp b/openmp/runtime/src/kmp_affinity.cpp
index dd48b1ea5c13f9..cf5cad04eb57d5 100644
--- a/openmp/runtime/src/kmp_affinity.cpp
+++ b/openmp/runtime/src/kmp_affinity.cpp
@@ -1970,7 +1970,6 @@ static bool __kmp_affinity_create_hwloc_map(kmp_i18n_id_t *const msg_id) {
hw_thread.ids[index + 1] = sub_id;
index--;
}
- prev = memory;
}
prev = obj;
}
@@ -4989,7 +4988,7 @@ static void __kmp_aux_affinity_initialize(kmp_affinity_t &affinity) {
int depth = __kmp_topology->get_depth();
// Create the table of masks, indexed by thread Id.
- unsigned numUnique;
+ unsigned numUnique = 0;
int numAddrs = __kmp_topology->get_num_hw_threads();
// If OMP_PLACES=cores:<attribute> specified, then attempt
// to make OS Id mask table using those attributes
diff --git a/openmp/runtime/src/kmp_affinity.h b/openmp/runtime/src/kmp_affinity.h
index ed24b6faf2f7e8..9ab2c0cc70d8c6 100644
--- a/openmp/runtime/src/kmp_affinity.h
+++ b/openmp/runtime/src/kmp_affinity.h
@@ -29,6 +29,8 @@ class KMPHwlocAffinity : public KMPAffinity {
mask = hwloc_bitmap_alloc();
this->zero();
}
+ Mask(const Mask &other) = delete;
+ Mask &operator=(const Mask &other) = delete;
~Mask() { hwloc_bitmap_free(mask); }
void set(int i) override { hwloc_bitmap_set(mask, i); }
bool is_set(int i) const override { return hwloc_bitmap_isset(mask, i); }
@@ -1271,7 +1273,7 @@ class hierarchy_info {
leaf. It corresponds to the number of entries in numPerLevel if we exclude
all but one trailing 1. */
kmp_uint32 depth;
- kmp_uint32 base_num_threads;
+ kmp_uint32 base_num_threads = 0;
enum init_status { initialized = 0, not_initialized = 1, initializing = 2 };
volatile kmp_int8 uninitialized; // 0=initialized, 1=not initialized,
// 2=initialization in progress
@@ -1281,8 +1283,8 @@ class hierarchy_info {
the parent of a node at level i has. For example, if we have a machine
with 4 packages, 4 cores/package and 2 HT per core, then numPerLevel =
{2, 4, 4, 1, 1}. All empty levels are set to 1. */
- kmp_uint32 *numPerLevel;
- kmp_uint32 *skipPerLevel;
+ kmp_uint32 *numPerLevel = nullptr;
+ kmp_uint32 *skipPerLevel = nullptr;
void deriveLevels() {
int hier_depth = __kmp_topology->get_depth();
diff --git a/openmp/runtime/src/kmp_barrier.cpp b/openmp/runtime/src/kmp_barrier.cpp
index 658cee594e48d5..d7ef57c608149e 100644
--- a/openmp/runtime/src/kmp_barrier.cpp
+++ b/openmp/runtime/src/kmp_barrier.cpp
@@ -444,7 +444,8 @@ static void __kmp_dist_barrier_release(
next_go = my_current_iter + distributedBarrier::MAX_ITERS;
my_go_index = tid / b->threads_per_go;
if (this_thr->th.th_used_in_team.load() == 3) {
- KMP_COMPARE_AND_STORE_ACQ32(&(this_thr->th.th_used_in_team), 3, 1);
+ (void)KMP_COMPARE_AND_STORE_ACQ32(&(this_thr->th.th_used_in_team), 3,
+ 1);
}
// Check if go flag is set
if (b->go[my_go_index].go.load() != next_go) {
diff --git a/openmp/runtime/src/kmp_csupport.cpp b/openmp/runtime/src/kmp_csupport.cpp
index b33c16fa79a658..fdbf9ff45e3549 100644
--- a/openmp/runtime/src/kmp_csupport.cpp
+++ b/openmp/runtime/src/kmp_csupport.cpp
@@ -1589,7 +1589,7 @@ void __kmpc_critical_with_hint(ident_t *loc, kmp_int32 global_tid,
kmp_dyna_lockseq_t lockseq = __kmp_map_hint_to_lock(hint);
if (*lk == 0) {
if (KMP_IS_D_LOCK(lockseq)) {
- KMP_COMPARE_AND_STORE_ACQ32(
+ (void)KMP_COMPARE_AND_STORE_ACQ32(
(volatile kmp_int32 *)&((kmp_base_tas_lock_t *)crit)->poll, 0,
KMP_GET_D_TAG(lockseq));
} else {
@@ -3486,8 +3486,8 @@ __kmp_enter_critical_section_reduce_block(ident_t *loc, kmp_int32 global_tid,
// Check if it is initialized.
if (*lk == 0) {
if (KMP_IS_D_LOCK(__kmp_user_lock_seq)) {
- KMP_COMPARE_AND_STORE_ACQ32((volatile kmp_int32 *)crit, 0,
- KMP_GET_D_TAG(__kmp_user_lock_seq));
+ (void)KMP_COMPARE_AND_STORE_ACQ32((volatile kmp_int32 *)crit, 0,
+ KMP_GET_D_TAG(__kmp_user_lock_seq));
} else {
__kmp_init_indirect_csptr(crit, loc, global_tid,
KMP_GET_I_TAG(__kmp_user_lock_seq));
diff --git a/openmp/runtime/src/kmp_runtime.cpp b/openmp/runtime/src/kmp_runtime.cpp
index 5b4391aa125d41..06bc4939359e26 100644
--- a/openmp/runtime/src/kmp_runtime.cpp
+++ b/openmp/runtime/src/kmp_runtime.cpp
@@ -1983,8 +1983,8 @@ int __kmp_fork_call(ident_t *loc, int gtid,
#if OMPT_SUPPORT
ompt_data_t ompt_parallel_data = ompt_data_none;
- ompt_data_t *parent_task_data;
- ompt_frame_t *ompt_frame;
+ ompt_data_t *parent_task_data = NULL;
+ ompt_frame_t *ompt_frame = NULL;
void *return_address = NULL;
if (ompt_enabled.enabled) {
@@ -5765,8 +5765,8 @@ void __kmp_free_team(kmp_root_t *root,
for (f = 1; f < team->t.t_nproc; ++f) {
KMP_DEBUG_ASSERT(team->t.t_threads[f]);
if (__kmp_barrier_gather_pattern[bs_forkjoin_barrier] == bp_dist_bar) {
- KMP_COMPARE_AND_STORE_ACQ32(&(team->t.t_threads[f]->th.th_used_in_team),
- 1, 2);
+ (void)KMP_COMPARE_AND_STORE_ACQ32(
+ &(team->t.t_threads[f]->th.th_used_in_team), 1, 2);
}
__kmp_free_thread(team->t.t_threads[f]);
}
@@ -9220,8 +9220,8 @@ void __kmp_add_threads_to_team(kmp_team_t *team, int new_nthreads) {
// to wake it up.
for (int f = 1; f < new_nthreads; ++f) {
KMP_DEBUG_ASSERT(team->t.t_threads[f]);
- KMP_COMPARE_AND_STORE_ACQ32(&(team->t.t_threads[f]->th.th_used_in_team), 0,
- 3);
+ (void)KMP_COMPARE_AND_STORE_ACQ32(
+ &(team->t.t_threads[f]->th.th_used_in_team), 0, 3);
if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) { // Wake up sleeping threads
__kmp_resume_32(team->t.t_threads[f]->th.th_info.ds.ds_gtid,
(kmp_flag_32<false, false> *)NULL);
diff --git a/openmp/runtime/src/kmp_tasking.cpp b/openmp/runtime/src/kmp_tasking.cpp
index 03ce0dd752af15..7edaa8e127e52c 100644
--- a/openmp/runtime/src/kmp_tasking.cpp
+++ b/openmp/runtime/src/kmp_tasking.cpp
@@ -5276,7 +5276,7 @@ static void __kmp_taskloop(ident_t *loc, int gtid, kmp_task_t *task, int if_val,
switch (sched) {
case 0: // no schedule clause specified, we can choose the default
// let's try to schedule (team_size*10) tasks
- grainsize = thread->th.th_team_nproc * 10;
+ grainsize = thread->th.th_team_nproc * static_cast<kmp_uint64>(10);
KMP_FALLTHROUGH();
case 2: // num_tasks provided
if (grainsize > tc) {
diff --git a/openmp/runtime/src/kmp_wait_release.h b/openmp/runtime/src/kmp_wait_release.h
index 97db68943da702..9baf280228ee52 100644
--- a/openmp/runtime/src/kmp_wait_release.h
+++ b/openmp/runtime/src/kmp_wait_release.h
@@ -104,7 +104,8 @@ template <> struct flag_traits<flag_oncore> {
template <flag_type FlagType> class kmp_flag {
protected:
flag_properties t; /**< "Type" of the flag in loc */
- kmp_info_t *waiting_threads[1]; /**< Threads sleeping on this thread. */
+ /**< Threads sleeping on this thread. */
+ kmp_info_t *waiting_threads[1] = {nullptr};
kmp_uint32 num_waiting_threads; /**< Num threads sleeping on this thread. */
std::atomic<bool> *sleepLoc;
@@ -140,7 +141,7 @@ template <typename PtrType, flag_type FlagType, bool Sleepable>
class kmp_flag_native : public kmp_flag<FlagType> {
protected:
volatile PtrType *loc;
- PtrType checker; /**< When flag==checker, it has been released. */
+ PtrType checker = (PtrType)0; /**< When flag==checker, it has been released */
typedef flag_traits<FlagType> traits_type;
public:
@@ -234,7 +235,7 @@ template <typename PtrType, flag_type FlagType, bool Sleepable>
class kmp_flag_atomic : public kmp_flag<FlagType> {
protected:
std::atomic<PtrType> *loc; /**< Pointer to flag location to wait on */
- PtrType checker; /**< Flag == checker means it has been released. */
+ PtrType checker = (PtrType)0; /**< Flag==checker means it has been released */
public:
typedef flag_traits<FlagType> traits_type;
typedef PtrType flag_t;
@@ -935,7 +936,8 @@ class kmp_flag_oncore : public kmp_flag_native<kmp_uint64, flag_oncore, false> {
kmp_uint32 offset; /**< Portion of flag of interest for an operation. */
bool flag_switch; /**< Indicates a switch in flag location. */
enum barrier_type bt; /**< Barrier type. */
- kmp_info_t *this_thr; /**< Thread to redirect to
diff erent flag location. */
+ /**< Thread to redirect to
diff erent flag location. */
+ kmp_info_t *this_thr = nullptr;
#if USE_ITT_BUILD
void *itt_sync_obj; /**< ITT object to pass to new flag location. */
#endif
diff --git a/openmp/runtime/src/ompt-general.cpp b/openmp/runtime/src/ompt-general.cpp
index e07c5ff4fcc47d..923eea2a563a91 100644
--- a/openmp/runtime/src/ompt-general.cpp
+++ b/openmp/runtime/src/ompt-general.cpp
@@ -104,9 +104,11 @@ static ompt_start_tool_result_t *ompt_start_tool_result = NULL;
#if KMP_OS_WINDOWS
static HMODULE ompt_tool_module = NULL;
+static HMODULE ompt_archer_module = NULL;
#define OMPT_DLCLOSE(Lib) FreeLibrary(Lib)
#else
static void *ompt_tool_module = NULL;
+static void *ompt_archer_module = NULL;
#define OMPT_DLCLOSE(Lib) dlclose(Lib)
#endif
@@ -374,6 +376,7 @@ ompt_try_start_tool(unsigned int omp_version, const char *runtime_version) {
"Tool was started and is using the OMPT interface.\n");
OMPT_VERBOSE_INIT_PRINT(
"----- END LOGGING OF TOOL REGISTRATION -----\n");
+ ompt_archer_module = h;
return ret;
}
OMPT_VERBOSE_INIT_CONTINUED_PRINT(
@@ -381,6 +384,7 @@ ompt_try_start_tool(unsigned int omp_version, const char *runtime_version) {
} else {
OMPT_VERBOSE_INIT_CONTINUED_PRINT("Failed: %s\n", dlerror());
}
+ OMPT_DLCLOSE(h);
}
}
#endif
@@ -521,6 +525,8 @@ void ompt_fini() {
}
}
+ if (ompt_archer_module)
+ OMPT_DLCLOSE(ompt_archer_module);
if (ompt_tool_module)
OMPT_DLCLOSE(ompt_tool_module);
memset(&ompt_enabled, 0, sizeof(ompt_enabled));
More information about the Openmp-commits
mailing list