From 2a007b007efb8fcfe376c49243246494a720b0a9 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Wed, 7 Sep 2022 14:16:43 +0100
Subject: [PATCH] BUG: PPCR: check outstanding request. Fixes #2577

If the exit is through maxIter it should still wait
for outstanding requests
---
 src/OpenFOAM/matrices/lduMatrix/solvers/PPCG/PPCG.C | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/PPCG/PPCG.C b/src/OpenFOAM/matrices/lduMatrix/solvers/PPCG/PPCG.C
index 6ad660f76f1..dc637b97ce0 100644
--- a/src/OpenFOAM/matrices/lduMatrix/solvers/PPCG/PPCG.C
+++ b/src/OpenFOAM/matrices/lduMatrix/solvers/PPCG/PPCG.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2019-2020 Mattijs Janssens
-    Copyright (C) 2020-2021 OpenCFD Ltd.
+    Copyright (C) 2020-2022 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -170,7 +170,7 @@ Foam::solverPerformance Foam::PPCG::scalarSolveCG
     )
     {
         // Make sure gamma,delta are available
-        if (Pstream::parRun())
+        if (Pstream::parRun() && outstandingRequest != -1)
         {
             Pstream::waitRequest(outstandingRequest);
             outstandingRequest = -1;
@@ -248,6 +248,12 @@ Foam::solverPerformance Foam::PPCG::scalarSolveCG
         matrix_.Amul(n, m, interfaceBouCoeffs_, interfaces_, cmpt);
     }
 
+    // Cleanup any outstanding requests
+    if (Pstream::parRun() && outstandingRequest != -1)
+    {
+        Pstream::waitRequest(outstandingRequest);
+    }
+
     return solverPerf;
 }
 
-- 
GitLab