From 63c3067f3351b84dd02faae3c9daee7a7d6cda62 Mon Sep 17 00:00:00 2001
From: Giovanni La Mura <giovanni.lamura@inaf.it>
Date: Wed, 17 Apr 2024 17:07:11 +0200
Subject: [PATCH] Make c1ao->am0m matrix contiguous

---
 src/include/Commons.h   |  2 ++
 src/libnptm/Commons.cpp | 12 ++++++------
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/include/Commons.h b/src/include/Commons.h
index f24de7d3..1022fb3b 100644
--- a/src/include/Commons.h
+++ b/src/include/Commons.h
@@ -266,6 +266,8 @@ public:
   //! \brief QUESTION: definition?
   dcomplex **am0m;
   //! \brief QUESTION: definition?
+  dcomplex *am0v;
+  //! \brief QUESTION: definition?
   dcomplex *vintm;
   //! \brief QUESTION: definition?
   dcomplex *vintt;
diff --git a/src/libnptm/Commons.cpp b/src/libnptm/Commons.cpp
index 65af7359..d5a9cb4e 100644
--- a/src/libnptm/Commons.cpp
+++ b/src/libnptm/Commons.cpp
@@ -225,9 +225,10 @@ C1_AddOns::C1_AddOns(C4 *c4) {
   vj = new dcomplex[1]();
   vyhj = new dcomplex[(nsph * nsph - 1) * litpos]();
   vyj0 = new dcomplex[nsph * lmtpos]();
+  am0v = new dcomplex[nlemt * nlemt]();
   am0m = new dcomplex*[nlemt];
   for (int ai = 0; ai < nlemt; ai++) {
-    am0m[ai] = new dcomplex[nlemt]();
+    am0m[ai] = (am0v + nlemt * ai);
   }
   vintm = new dcomplex[16]();
   vintt = new dcomplex[16]();
@@ -279,10 +280,11 @@ C1_AddOns::C1_AddOns(const C1_AddOns& rhs) {
   int vyj0size = nsph * lmtpos;
   vyj0 = new dcomplex[vyj0size]();
   for (int hi=0; hi<vyj0size; hi++) vyj0[hi] = rhs.vyj0[hi];
+  am0v = new dcomplex[nlemt * nlemt]();
   am0m = new dcomplex*[nlemt];
   for (int ai = 0; ai < nlemt; ai++) {
-    am0m[ai] = new dcomplex[nlemt]();
-    for (int aj = 0; aj < nlemt; aj++) am0m[ai][aj] = rhs.am0m[ai][aj];
+    for (int aj = 0; aj < nlemt; aj++) am0v[nlemt * ai + aj] = rhs.am0v[nlemt * ai + aj];
+    am0m[ai] = (am0v + nlemt * ai);
   }
   vintm = new dcomplex[16]();
   vintt = new dcomplex[16]();
@@ -342,10 +344,8 @@ C1_AddOns::~C1_AddOns() {
   delete[] vh;
   delete[] vj0;
   delete[] vj;
-  for (int ai = nlemt - 1; ai > -1; ai--) {
-    delete[] am0m[ai];
-  }
   delete[] am0m;
+  delete[] am0v;
   delete[] vintm;
   delete[] vintt;
   for (int fi = 1; fi > -1; fi--) {
-- 
GitLab