Skip to content

Unify environment variables usage across the project #423

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

Merged
merged 1 commit into from
May 26, 2025
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
202 changes: 101 additions & 101 deletions .github/workflows/main.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Below is the table of contents for the Parallel Programming Course documentation
user_guide/submit_work
user_guide/ci
user_guide/api
user_guide/environment_variables

.. toctree::
:maxdepth: 2
Expand Down
51 changes: 51 additions & 0 deletions docs/locale/en/LC_MESSAGES/user_guide/environment_variables.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2025, Learning Process
# This file is distributed under the same license as the Parallel
# Programming Course package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2025.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Parallel Programming Course \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-05-26 10:22+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en\n"
"Language-Team: en <[email protected]>\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.16.0\n"

#: ../../../../docs/user_guide/environment_variables.rst:2
msgid "Environment Variables"
msgstr ""

#: ../../../../docs/user_guide/environment_variables.rst:4
msgid ""
"The following environment variables can be used to configure the "
"project's runtime behavior:"
msgstr ""

#: ../../../../docs/user_guide/environment_variables.rst:6
msgid ""
"``PPC_NUM_PROC``: Specifies the number of processes to launch. "
"Default: ``1``"
msgstr ""

#: ../../../../docs/user_guide/environment_variables.rst:9
msgid ""
"``PPC_NUM_THREADS``: Specifies the number of threads to use. Default:"
" ``1``"
msgstr ""

#: ../../../../docs/user_guide/environment_variables.rst:12
msgid ""
"``PPC_ASAN_RUN``: Specifies that application is compiler with "
"sanitizers. Used by ``scripts/run_tests.py`` to skip ``valgrind`` runs. "
"Default: ``0``"
msgstr ""

52 changes: 52 additions & 0 deletions docs/locale/ru/LC_MESSAGES/user_guide/environment_variables.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2025, Learning Process
# This file is distributed under the same license as the Parallel
# Programming Course package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2025.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Parallel Programming Course \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-05-26 10:22+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: ru\n"
"Language-Team: ru <[email protected]>\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.16.0\n"

#: ../../../../docs/user_guide/environment_variables.rst:2
msgid "Environment Variables"
msgstr "Переменные окружения"

#: ../../../../docs/user_guide/environment_variables.rst:4
msgid ""
"The following environment variables can be used to configure the "
"project's runtime behavior:"
msgstr "Следующие переменные окружения могут использоваться для настройки поведения программы во время выполнения:"

#: ../../../../docs/user_guide/environment_variables.rst:6
msgid ""
"``PPC_NUM_PROC``: Specifies the number of processes to launch. "
"Default: ``1``"
msgstr "``PPC_NUM_PROC``: задаёт количество запускаемых процессов. По умолчанию: ``1``"

#: ../../../../docs/user_guide/environment_variables.rst:9
msgid ""
"``PPC_NUM_THREADS``: Specifies the number of threads to use. Default:"
" ``1``"
msgstr "``PPC_NUM_THREADS``: задаёт количество используемых потоков. По умолчанию: ``1``"

#: ../../../../docs/user_guide/environment_variables.rst:12
msgid ""
"``PPC_ASAN_RUN``: Specifies that application is compiler with "
"sanitizers. Used by ``scripts/run_tests.py`` to skip ``valgrind`` runs. "
"Default: ``0``"
msgstr "``PPC_ASAN_RUN``: указывает, что приложение собрано с санитайзерами. Используется в ``scripts/run_tests.py`` для пропуска запусков под ``valgrind``. По умолчанию: ``0``"

13 changes: 13 additions & 0 deletions docs/user_guide/environment_variables.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Environment Variables
=====================

The following environment variables can be used to configure the project's runtime behavior:

- ``PPC_NUM_PROC``: Specifies the number of processes to launch.
Default: ``1``

- ``PPC_NUM_THREADS``: Specifies the number of threads to use.
Default: ``1``

- ``PPC_ASAN_RUN``: Specifies that application is compiler with sanitizers. Used by ``scripts/run_tests.py`` to skip ``valgrind`` runs.
Default: ``0``
8 changes: 4 additions & 4 deletions modules/core/util/func_tests/util_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ TEST(util_tests, check_unset_env) {
#ifndef _WIN32
int save_var = ppc::util::GetPPCNumThreads();

unsetenv("OMP_NUM_THREADS"); // NOLINT(concurrency-mt-unsafe,misc-include-cleaner)
unsetenv("PPC_NUM_THREADS"); // NOLINT(concurrency-mt-unsafe,misc-include-cleaner)

EXPECT_EQ(ppc::util::GetPPCNumThreads(), 1);

setenv("OMP_NUM_THREADS", std::to_string(save_var).c_str(), 1); // NOLINT(concurrency-mt-unsafe,misc-include-cleaner)
setenv("PPC_NUM_THREADS", std::to_string(save_var).c_str(), 1); // NOLINT(concurrency-mt-unsafe,misc-include-cleaner)
#else
GTEST_SKIP();
#endif
Expand All @@ -26,11 +26,11 @@ TEST(util_tests, check_set_env) {

const int num_threads = static_cast<int>(std::thread::hardware_concurrency());
// NOLINTNEXTLINE(concurrency-mt-unsafe,misc-include-cleaner)
setenv("OMP_NUM_THREADS", std::to_string(num_threads).c_str(), 1);
setenv("PPC_NUM_THREADS", std::to_string(num_threads).c_str(), 1);

EXPECT_EQ(ppc::util::GetPPCNumThreads(), num_threads);

setenv("OMP_NUM_THREADS", std::to_string(save_var).c_str(), 1); // NOLINT(concurrency-mt-unsafe,misc-include-cleaner)
setenv("PPC_NUM_THREADS", std::to_string(save_var).c_str(), 1); // NOLINT(concurrency-mt-unsafe,misc-include-cleaner)
#else
GTEST_SKIP();
#endif
Expand Down
4 changes: 2 additions & 2 deletions modules/core/util/src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ int ppc::util::GetPPCNumThreads() {
#ifdef _WIN32
size_t len;
char omp_env[100];
errno_t err = getenv_s(&len, omp_env, sizeof(omp_env), "OMP_NUM_THREADS");
errno_t err = getenv_s(&len, omp_env, sizeof(omp_env), "PPC_NUM_THREADS");
if (err != 0 || len == 0) {
omp_env[0] = '\0';
}
int num_threads = std::atoi(omp_env);
#else
const char *omp_env = std::getenv("OMP_NUM_THREADS"); // NOLINT(concurrency-mt-unsafe)
const char *omp_env = std::getenv("PPC_NUM_THREADS"); // NOLINT(concurrency-mt-unsafe)
int num_threads = (omp_env != nullptr) ? std::atoi(omp_env) : 1;
#endif
return num_threads;
Expand Down
4 changes: 2 additions & 2 deletions scripts/create_perf_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
worksheet.set_column('A:Z', 23)
right_bold_border = workbook.add_format({'bold': True, 'right': 2, 'bottom': 2})
bottom_bold_border = workbook.add_format({'bold': True, 'bottom': 2})
cpu_num = os.environ.get("PROC_COUNT")
cpu_num = os.environ.get("PPC_NUM_PROC")
if cpu_num is None:
raise EnvironmentError("Required environment variable 'PROC_COUNT' is not set.")
raise EnvironmentError("Required environment variable 'PPC_NUM_PROC' is not set.")
cpu_num = int(cpu_num)
worksheet.write(0, 0, "cpu_num = " + str(cpu_num), right_bold_border)

Expand Down
24 changes: 12 additions & 12 deletions scripts/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __get_gtest_settings(repeats_count):
return command

def run_threads(self):
if platform.system() == "Linux" and not os.environ.get("ASAN_RUN"):
if platform.system() == "Linux" and not os.environ.get("PPC_ASAN_RUN"):
self.__run_exec(f"{self.valgrind_cmd} {self.work_dir / 'seq_func_tests'} {self.__get_gtest_settings(1)}")
self.__run_exec(f"{self.valgrind_cmd} {self.work_dir / 'stl_func_tests'} {self.__get_gtest_settings(1)}")

Expand All @@ -70,27 +70,27 @@ def run_threads(self):
self.__run_exec(f"{self.work_dir / 'omp_func_tests'} {self.__get_gtest_settings(3)}")

def run_core(self):
if platform.system() == "Linux" and not os.environ.get("ASAN_RUN"):
if platform.system() == "Linux" and not os.environ.get("PPC_ASAN_RUN"):
self.__run_exec(f"{self.valgrind_cmd} {self.work_dir / 'core_func_tests'} {self.__get_gtest_settings(1)}")

self.__run_exec(f"{self.work_dir / 'core_func_tests'} {self.__get_gtest_settings(1)}")

def run_processes(self, additional_mpi_args):
proc_count = os.environ.get("PROC_COUNT")
if proc_count is None:
raise EnvironmentError("Required environment variable 'PROC_COUNT' is not set.")
PPC_NUM_PROC = os.environ.get("PPC_NUM_PROC")
if PPC_NUM_PROC is None:
raise EnvironmentError("Required environment variable 'PPC_NUM_PROC' is not set.")

mpi_running = f"{self.mpi_exec} {additional_mpi_args} -np {proc_count}"
if not os.environ.get("ASAN_RUN"):
mpi_running = f"{self.mpi_exec} {additional_mpi_args} -np {PPC_NUM_PROC}"
if not os.environ.get("PPC_ASAN_RUN"):
self.__run_exec(f"{mpi_running} {self.work_dir / 'all_func_tests'} {self.__get_gtest_settings(10)}")
self.__run_exec(f"{mpi_running} {self.work_dir / 'mpi_func_tests'} {self.__get_gtest_settings(10)}")

def run_performance(self):
if not os.environ.get("ASAN_RUN"):
proc_count = os.environ.get("PROC_COUNT")
if proc_count is None:
raise EnvironmentError("Required environment variable 'PROC_COUNT' is not set.")
mpi_running = f"{self.mpi_exec} -np {proc_count}"
if not os.environ.get("PPC_ASAN_RUN"):
PPC_NUM_PROC = os.environ.get("PPC_NUM_PROC")
if PPC_NUM_PROC is None:
raise EnvironmentError("Required environment variable 'PPC_NUM_PROC' is not set.")
mpi_running = f"{self.mpi_exec} -np {PPC_NUM_PROC}"
self.__run_exec(f"{mpi_running} {self.work_dir / 'all_perf_tests'} {self.__get_gtest_settings(1)}")
self.__run_exec(f"{mpi_running} {self.work_dir / 'mpi_perf_tests'} {self.__get_gtest_settings(1)}")

Expand Down
Loading