From abf258e2e8a337870bdb7404975307861867fe69 Mon Sep 17 00:00:00 2001 From: StefanoPetrilli Date: Wed, 20 Jul 2022 15:45:29 -0500 Subject: [PATCH] isAlreadyMatched is now atomic --- amgprec/impl/aggregator/clean.cpp | 2 -- amgprec/impl/aggregator/isAlreadyMatched.cpp | 29 ++++++++++++++------ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/amgprec/impl/aggregator/clean.cpp b/amgprec/impl/aggregator/clean.cpp index 29fa351d..62f366b2 100644 --- a/amgprec/impl/aggregator/clean.cpp +++ b/amgprec/impl/aggregator/clean.cpp @@ -1,8 +1,6 @@ #include "MatchBoxPC.h" // TODO comment -// TODO use task -// TODO destroy the locks void clean(MilanLongInt NLVer, MilanInt myRank, diff --git a/amgprec/impl/aggregator/isAlreadyMatched.cpp b/amgprec/impl/aggregator/isAlreadyMatched.cpp index d4efd416..a7d65c15 100644 --- a/amgprec/impl/aggregator/isAlreadyMatched.cpp +++ b/amgprec/impl/aggregator/isAlreadyMatched.cpp @@ -1,6 +1,5 @@ #include "MatchBoxPC.h" -//TODO can be optimized!! /** * //TODO documentation * @param k @@ -13,14 +12,14 @@ * @return */ bool isAlreadyMatched(MilanLongInt node, - MilanLongInt StartIndex, - MilanLongInt EndIndex, - vector &GMate, - MilanLongInt* Mate, - map &Ghost2LocalMap -) { + MilanLongInt StartIndex, + MilanLongInt EndIndex, + vector &GMate, + MilanLongInt *Mate, + map &Ghost2LocalMap) +{ - bool result = false; + /* #pragma omp critical(Mate) { if ((node < StartIndex) || (node > EndIndex)) { //Is it a ghost vertex? @@ -30,6 +29,18 @@ bool isAlreadyMatched(MilanLongInt node, } } + */ + MilanLongInt val; + if ((node < StartIndex) || (node > EndIndex)) // if ghost vertex + { +#pragma omp atomic read + val = GMate[Ghost2LocalMap[node]]; + return val >= 0; // Already matched + } + + // If not ghost vertex +#pragma omp atomic read + val = Mate[node - StartIndex]; - return result; + return val >= 0; // Already matched } \ No newline at end of file