Skip to content

Commit e606241

Browse files
authored
Unify environment variables usage across the project (#423)
- Use `PPC_` prefix for all used environment variables - Add environment variables documentation page
1 parent 29103af commit e606241

File tree

9 files changed

+238
-121
lines changed

9 files changed

+238
-121
lines changed

.github/workflows/main.yml

Lines changed: 101 additions & 101 deletions
Large diffs are not rendered by default.

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Below is the table of contents for the Parallel Programming Course documentation
1313
user_guide/submit_work
1414
user_guide/ci
1515
user_guide/api
16+
user_guide/environment_variables
1617

1718
.. toctree::
1819
:maxdepth: 2
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# SOME DESCRIPTIVE TITLE.
2+
# Copyright (C) 2025, Learning Process
3+
# This file is distributed under the same license as the Parallel
4+
# Programming Course package.
5+
# FIRST AUTHOR <EMAIL@ADDRESS>, 2025.
6+
#
7+
#, fuzzy
8+
msgid ""
9+
msgstr ""
10+
"Project-Id-Version: Parallel Programming Course \n"
11+
"Report-Msgid-Bugs-To: \n"
12+
"POT-Creation-Date: 2025-05-26 10:22+0200\n"
13+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
14+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
15+
"Language: en\n"
16+
"Language-Team: en <[email protected]>\n"
17+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
18+
"MIME-Version: 1.0\n"
19+
"Content-Type: text/plain; charset=utf-8\n"
20+
"Content-Transfer-Encoding: 8bit\n"
21+
"Generated-By: Babel 2.16.0\n"
22+
23+
#: ../../../../docs/user_guide/environment_variables.rst:2
24+
msgid "Environment Variables"
25+
msgstr ""
26+
27+
#: ../../../../docs/user_guide/environment_variables.rst:4
28+
msgid ""
29+
"The following environment variables can be used to configure the "
30+
"project's runtime behavior:"
31+
msgstr ""
32+
33+
#: ../../../../docs/user_guide/environment_variables.rst:6
34+
msgid ""
35+
"``PPC_NUM_PROC``: Specifies the number of processes to launch. "
36+
"Default: ``1``"
37+
msgstr ""
38+
39+
#: ../../../../docs/user_guide/environment_variables.rst:9
40+
msgid ""
41+
"``PPC_NUM_THREADS``: Specifies the number of threads to use. Default:"
42+
" ``1``"
43+
msgstr ""
44+
45+
#: ../../../../docs/user_guide/environment_variables.rst:12
46+
msgid ""
47+
"``PPC_ASAN_RUN``: Specifies that application is compiler with "
48+
"sanitizers. Used by ``scripts/run_tests.py`` to skip ``valgrind`` runs. "
49+
"Default: ``0``"
50+
msgstr ""
51+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# SOME DESCRIPTIVE TITLE.
2+
# Copyright (C) 2025, Learning Process
3+
# This file is distributed under the same license as the Parallel
4+
# Programming Course package.
5+
# FIRST AUTHOR <EMAIL@ADDRESS>, 2025.
6+
#
7+
#, fuzzy
8+
msgid ""
9+
msgstr ""
10+
"Project-Id-Version: Parallel Programming Course \n"
11+
"Report-Msgid-Bugs-To: \n"
12+
"POT-Creation-Date: 2025-05-26 10:22+0200\n"
13+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
14+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
15+
"Language: ru\n"
16+
"Language-Team: ru <[email protected]>\n"
17+
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
18+
"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
19+
"MIME-Version: 1.0\n"
20+
"Content-Type: text/plain; charset=utf-8\n"
21+
"Content-Transfer-Encoding: 8bit\n"
22+
"Generated-By: Babel 2.16.0\n"
23+
24+
#: ../../../../docs/user_guide/environment_variables.rst:2
25+
msgid "Environment Variables"
26+
msgstr "Переменные окружения"
27+
28+
#: ../../../../docs/user_guide/environment_variables.rst:4
29+
msgid ""
30+
"The following environment variables can be used to configure the "
31+
"project's runtime behavior:"
32+
msgstr "Следующие переменные окружения могут использоваться для настройки поведения программы во время выполнения:"
33+
34+
#: ../../../../docs/user_guide/environment_variables.rst:6
35+
msgid ""
36+
"``PPC_NUM_PROC``: Specifies the number of processes to launch. "
37+
"Default: ``1``"
38+
msgstr "``PPC_NUM_PROC``: задаёт количество запускаемых процессов. По умолчанию: ``1``"
39+
40+
#: ../../../../docs/user_guide/environment_variables.rst:9
41+
msgid ""
42+
"``PPC_NUM_THREADS``: Specifies the number of threads to use. Default:"
43+
" ``1``"
44+
msgstr "``PPC_NUM_THREADS``: задаёт количество используемых потоков. По умолчанию: ``1``"
45+
46+
#: ../../../../docs/user_guide/environment_variables.rst:12
47+
msgid ""
48+
"``PPC_ASAN_RUN``: Specifies that application is compiler with "
49+
"sanitizers. Used by ``scripts/run_tests.py`` to skip ``valgrind`` runs. "
50+
"Default: ``0``"
51+
msgstr "``PPC_ASAN_RUN``: указывает, что приложение собрано с санитайзерами. Используется в ``scripts/run_tests.py`` для пропуска запусков под ``valgrind``. По умолчанию: ``0``"
52+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Environment Variables
2+
=====================
3+
4+
The following environment variables can be used to configure the project's runtime behavior:
5+
6+
- ``PPC_NUM_PROC``: Specifies the number of processes to launch.
7+
Default: ``1``
8+
9+
- ``PPC_NUM_THREADS``: Specifies the number of threads to use.
10+
Default: ``1``
11+
12+
- ``PPC_ASAN_RUN``: Specifies that application is compiler with sanitizers. Used by ``scripts/run_tests.py`` to skip ``valgrind`` runs.
13+
Default: ``0``

modules/core/util/func_tests/util_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ TEST(util_tests, check_unset_env) {
1010
#ifndef _WIN32
1111
int save_var = ppc::util::GetPPCNumThreads();
1212

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

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

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

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

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

33-
setenv("OMP_NUM_THREADS", std::to_string(save_var).c_str(), 1); // NOLINT(concurrency-mt-unsafe,misc-include-cleaner)
33+
setenv("PPC_NUM_THREADS", std::to_string(save_var).c_str(), 1); // NOLINT(concurrency-mt-unsafe,misc-include-cleaner)
3434
#else
3535
GTEST_SKIP();
3636
#endif

modules/core/util/src/util.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ int ppc::util::GetPPCNumThreads() {
2020
#ifdef _WIN32
2121
size_t len;
2222
char omp_env[100];
23-
errno_t err = getenv_s(&len, omp_env, sizeof(omp_env), "OMP_NUM_THREADS");
23+
errno_t err = getenv_s(&len, omp_env, sizeof(omp_env), "PPC_NUM_THREADS");
2424
if (err != 0 || len == 0) {
2525
omp_env[0] = '\0';
2626
}
2727
int num_threads = std::atoi(omp_env);
2828
#else
29-
const char *omp_env = std::getenv("OMP_NUM_THREADS"); // NOLINT(concurrency-mt-unsafe)
29+
const char *omp_env = std::getenv("PPC_NUM_THREADS"); // NOLINT(concurrency-mt-unsafe)
3030
int num_threads = (omp_env != nullptr) ? std::atoi(omp_env) : 1;
3131
#endif
3232
return num_threads;

scripts/create_perf_table.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
worksheet.set_column('A:Z', 23)
5050
right_bold_border = workbook.add_format({'bold': True, 'right': 2, 'bottom': 2})
5151
bottom_bold_border = workbook.add_format({'bold': True, 'bottom': 2})
52-
cpu_num = os.environ.get("PROC_COUNT")
52+
cpu_num = os.environ.get("PPC_NUM_PROC")
5353
if cpu_num is None:
54-
raise EnvironmentError("Required environment variable 'PROC_COUNT' is not set.")
54+
raise EnvironmentError("Required environment variable 'PPC_NUM_PROC' is not set.")
5555
cpu_num = int(cpu_num)
5656
worksheet.write(0, 0, "cpu_num = " + str(cpu_num), right_bold_border)
5757

scripts/run_tests.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __get_gtest_settings(repeats_count):
6060
return command
6161

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)