From b49e41e215f4c724b1dc9da42f9b0ad868175211 Mon Sep 17 00:00:00 2001 From: Thomas Oberbichler Date: Mon, 21 Sep 2020 08:48:07 +0200 Subject: [PATCH 01/12] Use simple colors --- include/eqlib/Log.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/eqlib/Log.h b/include/eqlib/Log.h index bf190a69..0c26ad0d 100644 --- a/include/eqlib/Log.h +++ b/include/eqlib/Log.h @@ -63,14 +63,14 @@ class Log { template static void task_info(std::string text, TArgs&&... args) { - std::string message = "\033[38;5;33m" + text + "\033[0m"; + std::string message = "\033[37m" + text + "\033[0m"; info(2, message.c_str(), std::forward(args)...); } template static void task_step(std::string text, TArgs&&... args) { - std::string message = "\033[38;5;8m" + text + "\033[0m"; + std::string message = "\033[33m" + text + "\033[0m"; info(3, message.c_str(), std::forward(args)...); } @@ -109,7 +109,7 @@ class Log { template static void warn(std::string text, TArgs&&... args) { - std::string message = "\033[38;5;208m" + text + "\033[0m"; + std::string message = "\033[35m" + text + "\033[0m"; s_console->warn(message.c_str(), std::forward(args)...); } From 6fa546f21a6880b634e7db96bcaaae4f6e969602 Mon Sep 17 00:00:00 2001 From: Thomas Oberbichler Date: Mon, 21 Sep 2020 08:48:25 +0200 Subject: [PATCH 02/12] Store lo and hi --- include/eqlib/Problem.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/eqlib/Problem.h b/include/eqlib/Problem.h index 9dd07507..168dafbb 100644 --- a/include/eqlib/Problem.h +++ b/include/eqlib/Problem.h @@ -78,6 +78,9 @@ class Problem { std::vector> m_element_g_equation_indices; std::vector> m_element_g_variable_indices; + std::vector> m_element_f_variable_indices_lo; + std::vector> m_element_f_variable_indices_hi; + SparseStructure m_structure_dg; SparseStructure m_structure_hm; @@ -413,6 +416,24 @@ class Problem { m_linear_solver = new_(); #endif + m_element_f_variable_indices_lo.resize(nb_elements_f); + m_element_f_variable_indices_hi.resize(nb_elements_f); + + for (index i = 0; i < nb_elements_f; i++) + { + const auto& element_indices = m_element_f_variable_indices[i]; + + std::vector element_lo(length(element_indices)); + std::vector element_hi(length(element_indices)); + + for (index row_i = 0; row_i < length(element_indices); row_i++) { + const auto row = element_indices[row_i]; + + element_lo[row_i] = m_structure_hm.get_index(row.global, element_indices.front().global); + element_hi[row_i] = m_structure_hm.get_index(row.global, element_indices.back().global); + } + } + Log::task_end("Problem initialized in {:.3f} sec", timer.ellapsed()); } From 215433a48a3c5f91dd91f4e102c1409641ee358e Mon Sep 17 00:00:00 2001 From: Thomas Oberbichler Date: Mon, 21 Sep 2020 09:45:03 +0200 Subject: [PATCH 03/12] Log init solver --- include/eqlib/Problem.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/eqlib/Problem.h b/include/eqlib/Problem.h index 168dafbb..c8f592ed 100644 --- a/include/eqlib/Problem.h +++ b/include/eqlib/Problem.h @@ -410,6 +410,8 @@ class Problem { Log::task_info("The problem occupies {} MB", m_data.values().size() * 8.0 / 1'024 / 1'024); + Log::task_step("Initialize linear solver..."); + #ifdef EQLIB_USE_MKL m_linear_solver = new_(); #else From 71c32d006174203675eb71f44b6590124a25f4c1 Mon Sep 17 00:00:00 2001 From: Thomas Oberbichler Date: Mon, 21 Sep 2020 09:45:26 +0200 Subject: [PATCH 04/12] Use std::next --- include/eqlib/SparseStructure.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/eqlib/SparseStructure.h b/include/eqlib/SparseStructure.h index acfd84f8..b2ecb8e2 100644 --- a/include/eqlib/SparseStructure.h +++ b/include/eqlib/SparseStructure.h @@ -122,8 +122,10 @@ class SparseStructure { return it->second; } else { - const auto lower = m_ja.begin() + m_ia[i]; - const auto upper = m_ja.begin() + m_ia[i + 1]; + const auto ja_begin = m_ja.begin(); + + const auto lower = std::next(ja_begin, m_ia[i]); + const auto upper = std::next(ja_begin, m_ia[i + 1]); const auto it = std::lower_bound(lower, upper, j); @@ -131,7 +133,7 @@ class SparseStructure { return -1; } - const index value_index = std::distance(m_ja.begin(), it); + const index value_index = std::distance(ja_begin, it); assert(value_index < nb_nonzeros()); From 7963219a1ac3eb88601ab04a5ab5aaf769cc1bfa Mon Sep 17 00:00:00 2001 From: Thomas Oberbichler Date: Mon, 21 Sep 2020 09:45:43 +0200 Subject: [PATCH 05/12] Add get_index_bounded --- include/eqlib/SparseStructure.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/eqlib/SparseStructure.h b/include/eqlib/SparseStructure.h index b2ecb8e2..85dfa41a 100644 --- a/include/eqlib/SparseStructure.h +++ b/include/eqlib/SparseStructure.h @@ -105,6 +105,26 @@ class SparseStructure { return m_ja.at(index); } + index get_index_bounded(const index j, const index lo, const index hi) const + { + const auto ja_begin = m_ja.begin(); + + const auto lower = std::next(ja_begin, lo); + const auto upper = std::next(ja_begin, hi); + + const auto it = std::lower_bound(lower, upper, j); + + if (*it != j || it == upper) { + return -1; + } + + const index value_index = std::distance(ja_begin, it); + + assert(value_index < nb_nonzeros()); + + return value_index; + } + index get_index(const index row, const index col) const { assert(0 <= row && row < rows()); From 1405dbe746f9117df871cb3a06dfa92eb956e00e Mon Sep 17 00:00:00 2001 From: Thomas Oberbichler Date: Mon, 21 Sep 2020 09:46:37 +0200 Subject: [PATCH 06/12] Use get_index_bounded --- include/eqlib/Problem.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/include/eqlib/Problem.h b/include/eqlib/Problem.h index c8f592ed..2f47f5b1 100644 --- a/include/eqlib/Problem.h +++ b/include/eqlib/Problem.h @@ -78,8 +78,8 @@ class Problem { std::vector> m_element_g_equation_indices; std::vector> m_element_g_variable_indices; - std::vector> m_element_f_variable_indices_lo; - std::vector> m_element_f_variable_indices_hi; + std::vector> m_element_f_variable_indices_lo; + std::vector> m_element_f_variable_indices_hi; SparseStructure m_structure_dg; SparseStructure m_structure_hm; @@ -418,6 +418,8 @@ class Problem { m_linear_solver = new_(); #endif + Log::task_step("Initialize element boundaries..."); + m_element_f_variable_indices_lo.resize(nb_elements_f); m_element_f_variable_indices_hi.resize(nb_elements_f); @@ -431,9 +433,12 @@ class Problem { for (index row_i = 0; row_i < length(element_indices); row_i++) { const auto row = element_indices[row_i]; - element_lo[row_i] = m_structure_hm.get_index(row.global, element_indices.front().global); - element_hi[row_i] = m_structure_hm.get_index(row.global, element_indices.back().global); + element_lo[row_i] = m_structure_hm.get_index(row.global, row.global); + element_hi[row_i] = m_structure_hm.get_index(row.global, element_indices.back().global) + 1; } + + m_element_f_variable_indices_lo[i] = std::move(element_lo); + m_element_f_variable_indices_hi[i] = std::move(element_hi); } Log::task_end("Problem initialized in {:.3f} sec", timer.ellapsed()); @@ -480,16 +485,21 @@ class Problem { data.df(row.global) += g(row.local); + auto lo = m_element_f_variable_indices_lo[i][row_i]; + const auto hi = m_element_f_variable_indices_hi[i][row_i]; + for (index col_i = row_i; col_i < length(variable_indices) && TOrder > 1; col_i++) { const auto col = variable_indices[col_i]; - index index = m_structure_hm.get_index(row.global, col.global); + index index = m_structure_hm.get_index_bounded(col.global, lo, hi); if (row.local < col.local) { data.hm_value(index) += h(row.local, col.local); } else { data.hm_value(index) += h(col.local, row.local); } + + lo = index; } } From 4af9fd28294addcc52babd74b138a474693cfcc8 Mon Sep 17 00:00:00 2001 From: Thomas Oberbichler Date: Mon, 21 Sep 2020 09:47:14 +0200 Subject: [PATCH 07/12] Add get_first_index --- include/eqlib/SparseStructure.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/eqlib/SparseStructure.h b/include/eqlib/SparseStructure.h index 85dfa41a..03a07777 100644 --- a/include/eqlib/SparseStructure.h +++ b/include/eqlib/SparseStructure.h @@ -105,6 +105,11 @@ class SparseStructure { return m_ja.at(index); } + index get_first_index(const index i) const + { + return m_ia(i); + } + index get_index_bounded(const index j, const index lo, const index hi) const { const auto ja_begin = m_ja.begin(); From b569ec6dd51be4c3a06dab2718d0101029239ad4 Mon Sep 17 00:00:00 2001 From: Thomas Oberbichler Date: Mon, 21 Sep 2020 10:27:47 +0200 Subject: [PATCH 08/12] Fix indexer --- include/eqlib/SparseStructure.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/eqlib/SparseStructure.h b/include/eqlib/SparseStructure.h index 03a07777..30b9ee07 100644 --- a/include/eqlib/SparseStructure.h +++ b/include/eqlib/SparseStructure.h @@ -107,7 +107,7 @@ class SparseStructure { index get_first_index(const index i) const { - return m_ia(i); + return m_ia[i]; } index get_index_bounded(const index j, const index lo, const index hi) const From e4c7a7ea2980609dd01691060c7e1608b64b650e Mon Sep 17 00:00:00 2001 From: Thomas Oberbichler Date: Mon, 21 Sep 2020 10:28:32 +0200 Subject: [PATCH 09/12] Use get_first_index --- include/eqlib/Problem.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/include/eqlib/Problem.h b/include/eqlib/Problem.h index 2f47f5b1..0763b256 100644 --- a/include/eqlib/Problem.h +++ b/include/eqlib/Problem.h @@ -78,7 +78,6 @@ class Problem { std::vector> m_element_g_equation_indices; std::vector> m_element_g_variable_indices; - std::vector> m_element_f_variable_indices_lo; std::vector> m_element_f_variable_indices_hi; SparseStructure m_structure_dg; @@ -420,24 +419,21 @@ class Problem { Log::task_step("Initialize element boundaries..."); - m_element_f_variable_indices_lo.resize(nb_elements_f); m_element_f_variable_indices_hi.resize(nb_elements_f); for (index i = 0; i < nb_elements_f; i++) { const auto& element_indices = m_element_f_variable_indices[i]; - std::vector element_lo(length(element_indices)); std::vector element_hi(length(element_indices)); for (index row_i = 0; row_i < length(element_indices); row_i++) { const auto row = element_indices[row_i]; + const auto col = element_indices.back(); - element_lo[row_i] = m_structure_hm.get_index(row.global, row.global); - element_hi[row_i] = m_structure_hm.get_index(row.global, element_indices.back().global) + 1; + element_hi[row_i] = m_structure_hm.get_index(row.global, col.global) + 1; } - m_element_f_variable_indices_lo[i] = std::move(element_lo); m_element_f_variable_indices_hi[i] = std::move(element_hi); } @@ -485,7 +481,7 @@ class Problem { data.df(row.global) += g(row.local); - auto lo = m_element_f_variable_indices_lo[i][row_i]; + auto lo = m_structure_hm.get_first_index(row.global); const auto hi = m_element_f_variable_indices_hi[i][row_i]; for (index col_i = row_i; col_i < length(variable_indices) && TOrder > 1; col_i++) { From a8b86055251d767cf9f7649271093f27ad1341cf Mon Sep 17 00:00:00 2001 From: Thomas Oberbichler Date: Mon, 21 Sep 2020 10:31:52 +0200 Subject: [PATCH 10/12] Drop active reduction --- include/eqlib/Problem.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/include/eqlib/Problem.h b/include/eqlib/Problem.h index 0763b256..834b83cc 100644 --- a/include/eqlib/Problem.h +++ b/include/eqlib/Problem.h @@ -626,9 +626,8 @@ class Problem { #pragma omp parallel if (m_nb_threads != 1) num_threads(m_nb_threads) firstprivate(l_data) { #pragma omp for schedule(dynamic, m_grainsize) nowait - for (index i = 0; i < length(m_active_elements_f); i++) { - // Log::info("Element {}", i); - compute_element_f(l_data, m_active_elements_f[i]); + for (index i = 0; i < nb_elements_f(); i++) { + compute_element_f(l_data, i); } if (sigma() != 1.0) { @@ -644,8 +643,8 @@ class Problem { } #pragma omp for schedule(dynamic, m_grainsize) nowait - for (index i = 0; i < length(m_active_elements_g); i++) { - compute_element_g(l_data, m_active_elements_g[i]); + for (index i = 0; i < nb_elements_g(); i++) { + compute_element_g(l_data, i); } #pragma omp critical From 57f80b29716c96335c4d424f0eda661de4c7e19b Mon Sep 17 00:00:00 2001 From: Thomas Oberbichler Date: Mon, 21 Sep 2020 10:41:31 +0200 Subject: [PATCH 11/12] Add const --- include/eqlib/Problem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/eqlib/Problem.h b/include/eqlib/Problem.h index 834b83cc..cb854890 100644 --- a/include/eqlib/Problem.h +++ b/include/eqlib/Problem.h @@ -487,7 +487,7 @@ class Problem { for (index col_i = row_i; col_i < length(variable_indices) && TOrder > 1; col_i++) { const auto col = variable_indices[col_i]; - index index = m_structure_hm.get_index_bounded(col.global, lo, hi); + const index index = m_structure_hm.get_index_bounded(col.global, lo, hi); if (row.local < col.local) { data.hm_value(index) += h(row.local, col.local); From 037b8acf45fff136ecfc09eaa0284266385fde79 Mon Sep 17 00:00:00 2001 From: Thomas Oberbichler Date: Mon, 21 Sep 2020 10:48:14 +0200 Subject: [PATCH 12/12] Add inline --- include/eqlib/SparseStructure.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/eqlib/SparseStructure.h b/include/eqlib/SparseStructure.h index 30b9ee07..b42786ac 100644 --- a/include/eqlib/SparseStructure.h +++ b/include/eqlib/SparseStructure.h @@ -105,7 +105,7 @@ class SparseStructure { return m_ja.at(index); } - index get_first_index(const index i) const + EQLIB_INLINE index get_first_index(const index i) const { return m_ia[i]; }