From af3a83aee578b5f442670b08a392df5121d62f1f Mon Sep 17 00:00:00 2001
From: Simon Schwitanski <simon.schwitanski@rwth-aachen.de>
Date: Mon, 7 Apr 2025 09:36:12 +0200
Subject: [PATCH] Fix RMA LocalConcurrency tests

A few generated local concurrency tests for RMA were invalid RMA programs (e.g., P0 locks window of P1 but then tries to put to itself) and some other tests were falsely classified. This commit fixes those errors.
---
 scripts/Infrastructure/TemplateFactory.py |  1 +
 scripts/errors/rma/LocalConcurrency.py    | 18 ++++++++++++------
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/scripts/Infrastructure/TemplateFactory.py b/scripts/Infrastructure/TemplateFactory.py
index 32f4e294..3772f8f7 100644
--- a/scripts/Infrastructure/TemplateFactory.py
+++ b/scripts/Infrastructure/TemplateFactory.py
@@ -756,6 +756,7 @@ def get_rma_call(tm: TemplateManager, rma_func, rank, identifier="RMACall") -> T
     rma_call = getattr(cfmpi, rma_func)()
     rma_call.set_identifier(identifier)
     rma_call.set_rank_executing(rank)
+    rma_call.set_arg("target_rank", "1")
 
     # request-based RMA call, add request
     if rma_call.has_arg("request"):
diff --git a/scripts/errors/rma/LocalConcurrency.py b/scripts/errors/rma/LocalConcurrency.py
index 9bc87c75..b068aa73 100644
--- a/scripts/errors/rma/LocalConcurrency.py
+++ b/scripts/errors/rma/LocalConcurrency.py
@@ -22,8 +22,8 @@ class LocalConcurrencyErrorRMA(ErrorGenerator):
         self.cfmpi = CorrectMPICallFactory()
         # generate standard buffer access instructions
         self.buf_instructions = {
-            "bufread": Instruction(f'printf("buf is %d\\n", {CorrectParameterFactory().buf_var_name}[1]);', 0, "bufread"),
-            "bufwrite": Instruction(f'{CorrectParameterFactory().buf_var_name}[1] = 42;', 0, "bufwrite")
+            "bufread": Instruction(f'printf("buf is %d\\n", {CorrectParameterFactory().buf_var_name}[0]);', 0, "bufread"),
+            "bufwrite": Instruction(f'{CorrectParameterFactory().buf_var_name}[0] = 42;', 0, "bufwrite")
         }
 
     def get_feature(self):
@@ -318,7 +318,7 @@ class LocalConcurrencyErrorRMA(ErrorGenerator):
                 for (op1, op2) in itertools.product(ops1, ops2):
                     self.tm = TemplateManager()
                     (win_declare, win_alloc, win_free) = get_allocated_window(
-                        "mpi_win_create", cf.get("win"), cf.winbuf_var_name, "int", "10")
+                        "mpi_win_create", cf.get("win"), cf.winbuf_var_name, "int", "20")
                     # window allocation boilerplate
                     self.tm.register_instruction(win_declare)
                     self.tm.register_instruction(win_alloc)
@@ -332,9 +332,15 @@ class LocalConcurrencyErrorRMA(ErrorGenerator):
                     alloc1, inst1, inst1_free = self.get_mem_op(op1, 0)
                     alloc2, inst2, inst2_free = self.get_mem_op(op2, 0)
 
-                    # avoid race at the target rank by setting the target rank to 1 for the second operation
-                    if isinstance(inst2, MPICall):
-                        inst2.set_arg("target_rank", "0")
+                    if sync_mode not in [self.lockflush, self.lockflushlocal, self.lockunlock]:
+                        # avoid race at the target rank by setting the target rank to 0 for the second operation
+                        if isinstance(inst2, MPICall):
+                            inst2.set_arg("target_rank", "0")
+                    else:
+                        # cannot set target rank to 0, because this would be not allowed with exclusive locks here
+                        # avoid race at the target rank by setting the target disp to 10 for the second operation
+                        if isinstance(inst2, MPICall):
+                            inst2.set_arg("target_disp", "10")
 
                     # if the operations are not conflicting and we should sync, we do not have to generate this test case
                     if not hasconflict and shouldsync:
-- 
GitLab