Skip to content

Commit eed1e67

Browse files
authored
Merge pull request #1678 from lcheng9/develop
Fix #1667 Potential crash for the OpenMP multi-thread running.
2 parents 27efebd + baa3436 commit eed1e67

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Common/src/linear_algebra/CSysMatrix.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ void CSysMatrix<ScalarType>::Initialize(unsigned long npoint, unsigned long npoi
190190

191191
/*--- This is akin to the row_ptr. ---*/
192192
omp_partitions = new unsigned long [omp_num_parts+1];
193+
for (unsigned long i = 0; i <= omp_num_parts; ++i) omp_partitions[i] = nPointDomain;
193194

194195
/*--- Work estimate based on non-zeros to produce balanced partitions. ---*/
195196

@@ -202,7 +203,15 @@ void CSysMatrix<ScalarType>::Initialize(unsigned long npoint, unsigned long npoi
202203
if (row_ptr_prec[iPoint] >= part*nnz_per_part)
203204
omp_partitions[part++] = iPoint;
204205
}
205-
omp_partitions[omp_num_parts] = nPointDomain;
206+
207+
for (unsigned long thread = 0; thread < omp_num_parts; ++thread) {
208+
const auto begin = omp_partitions[thread];
209+
const auto end = omp_partitions[thread + 1];
210+
if (begin == end) {
211+
cout << "WARNING: Redundant thread has been detected. Performance could be impacted due to low number of nodes per thread." << endl;
212+
break;
213+
}
214+
}
206215

207216
/*--- Generate MKL Kernels ---*/
208217

@@ -700,6 +709,7 @@ void CSysMatrix<ScalarType>::BuildILUPreconditioner() {
700709
{
701710
const auto begin = omp_partitions[thread];
702711
const auto end = omp_partitions[thread+1];
712+
if (begin == end) continue;
703713

704714
/*--- Each thread will work on the submatrix defined from row/col "begin"
705715
* to row/col "end-1" (i.e. the range [begin,end[). Which is exactly
@@ -777,6 +787,7 @@ void CSysMatrix<ScalarType>::ComputeILUPreconditioner(const CSysVector<ScalarTyp
777787
{
778788
const auto begin = omp_partitions[thread];
779789
const auto end = omp_partitions[thread+1];
790+
if (begin == end) continue;
780791

781792
ScalarType aux_vec[MAXNVAR];
782793

@@ -839,6 +850,7 @@ void CSysMatrix<ScalarType>::ComputeLU_SGSPreconditioner(const CSysVector<Scalar
839850
{
840851
const auto begin = omp_partitions[thread];
841852
const auto end = omp_partitions[thread+1];
853+
if (begin == end) continue;
842854

843855
/*--- Each thread will work on the submatrix defined from row/col "begin"
844856
* to row/col "end-1", except the last thread that also considers halos.
@@ -869,6 +881,8 @@ void CSysMatrix<ScalarType>::ComputeLU_SGSPreconditioner(const CSysVector<Scalar
869881
{
870882
const auto begin = omp_partitions[thread];
871883
const auto row_end = omp_partitions[thread+1];
884+
if (begin == row_end) continue;
885+
872886
/*--- On the last thread partition the upper
873887
* product should consider halo columns. ---*/
874888
const auto col_end = (row_end==nPointDomain)? nPoint : row_end;

0 commit comments

Comments
 (0)