Skip to content

Commit cf7f331

Browse files
committed
[bugfix] fix all parallel error.
1 parent 92f7c4e commit cf7f331

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242

4343
# Initializes the CodeQL tools for scanning.
4444
- name: Initialize CodeQL
45-
uses: github/codeql-action/init@v2
45+
uses: github/codeql-action/init@v3
4646
with:
4747
languages: ${{ matrix.language }}
4848
# If you wish to specify custom queries, you can do so here or in a config file.

src/GraphCtrl/GraphElement/_GEngine/GDynamicEngine/GDynamicEngine.cpp

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,23 @@ CStatus GDynamicEngine::setup(const GSortedGElementPtrSet& elements) {
2828

2929

3030
CStatus GDynamicEngine::run() {
31-
CGRAPH_FUNCTION_BEGIN
3231
cur_status_.reset();
3332

34-
if (internal::GEngineDagType::COMMON == dag_type_) {
35-
commonRunAll();
36-
} else if (internal::GEngineDagType::ALL_SERIAL == dag_type_) {
37-
serialRunAll();
38-
} else if (internal::GEngineDagType::ALL_PARALLEL == dag_type_) {
39-
parallelRunAll();
40-
} else {
41-
CGRAPH_RETURN_ERROR_STATUS("unknown engine dag type")
33+
switch (dag_type_) {
34+
case internal::GEngineDagType::COMMON:
35+
commonRunAll();
36+
break;
37+
case internal::GEngineDagType::ALL_SERIAL:
38+
serialRunAll();
39+
break;
40+
case internal::GEngineDagType::ALL_PARALLEL:
41+
parallelRunAll();
42+
break;
43+
default:
44+
CGRAPH_RETURN_ERROR_STATUS("unknown engine dag type");
4245
}
4346

44-
status = cur_status_;
45-
CGRAPH_FUNCTION_END
47+
return cur_status_;
4648
}
4749

4850

@@ -103,22 +105,16 @@ CVoid GDynamicEngine::analysisParallelMatrix() {
103105
CSize thdSize = config.default_thread_size_ + config.secondary_thread_size_;
104106
CGRAPH_THROW_EXCEPTION_BY_CONDITION(thdSize <= 0,
105107
"default thread size cannot smaller than 1");
106-
107108
CSize taskNumPerThd = total_end_size_ / thdSize + (CSize)(0 != total_end_size_ % thdSize);
108109
CGRAPH_THROW_EXCEPTION_BY_CONDITION(taskNumPerThd == 0,
109110
"task number per thread is 0");
110-
CGRAPH_THROW_EXCEPTION_BY_CONDITION(total_end_size_ <= 1,
111-
"total end size <= 1, should not enter all parallel path");
112-
if (1 == taskNumPerThd) {
113-
// 如果线程数比 task数量都多,则直接放到一个 arr里就好了
114-
parallel_element_matrix_.push_back(total_element_arr_);
115-
return;
116-
}
117111

118112
CSize curIndex = 0;
119113
while (curIndex < total_end_size_) {
120114
CSize curEnd = curIndex + taskNumPerThd < total_end_size_ ? curIndex + taskNumPerThd : total_end_size_ ;
121115
GElementPtrArr curArr(total_element_arr_.data() + curIndex, total_element_arr_.data() + curEnd);
116+
CGRAPH_THROW_EXCEPTION_BY_CONDITION(curArr.empty(),
117+
"current elements array cannot be empty");
122118
parallel_element_matrix_.push_back(curArr);
123119
curIndex += taskNumPerThd;
124120
}
@@ -170,7 +166,7 @@ CVoid GDynamicEngine::afterElementRun(GElementPtr element) {
170166
}
171167
}
172168
}
173-
reserved ? process(reserved, true) : void();
169+
if (reserved) { process(reserved, true); }
174170
}
175171
} else {
176172
CGRAPH_LOCK_GUARD lock(locker_.mtx_);
@@ -224,11 +220,18 @@ CVoid GDynamicEngine::parallelRunAll() {
224220
CVoid GDynamicEngine::parallelRunAll() {
225221
parallel_run_num_ = 0;
226222
for (CIndex i = 0; i < (CIndex)parallel_element_matrix_.size(); i++) {
227-
const auto& curArr = parallel_element_matrix_[i];
228-
for (auto element : curArr) {
229-
thread_pool_->executeWithTid([this, element] { parallelRunOne(element); }, i,
230-
element == curArr.front() || element == curArr.back(),
231-
element == curArr.front());
223+
auto& curArr = parallel_element_matrix_[i];
224+
if (curArr.size() > 1) {
225+
for (const auto& element : curArr) {
226+
thread_pool_->executeWithTid([this, element] { parallelRunOne(element); }, i,
227+
element == curArr.front() || element == curArr.back(),
228+
element == curArr.front());
229+
}
230+
} else {
231+
// 仅有一个任务的情况,无法使用 executeWithTid 函数,故走这边的逻辑
232+
const auto& element = curArr.front();
233+
thread_pool_->execute([this, element] {
234+
parallelRunOne(element); }, element->binding_index_);
232235
}
233236
}
234237

src/GraphCtrl/GraphElement/_GEngine/GDynamicEngine/GDynamicEngine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ class GDynamicEngine : public GEngine {
9191
CVoid serialRunAll();
9292

9393
private:
94-
GElementPtrArr total_element_arr_; // pipeline中所有的元素信息集合
95-
GElementPtrArr front_element_arr_; // 没有依赖的元素信息
94+
GElementPtrArr total_element_arr_ {}; // pipeline中所有的元素信息集合
95+
GElementPtrArr front_element_arr_ {}; // 没有依赖的元素信息
9696
CSize total_end_size_ = 0; // 图结束节点数量
9797
CSize finished_end_size_ = 0; // 执行结束节点数量
9898
CStatus cur_status_; // 当前全局的状态信息

0 commit comments

Comments
 (0)