From 1352f6b31cb93b4b55f7f7d3bbdbd207bb740698 Mon Sep 17 00:00:00 2001
From: Georges Da Costa <dacosta@irit.fr>
Date: Fri, 26 May 2023 16:02:31 +0200
Subject: [PATCH] Changes for MacOS

---
 expetator/benchmarks/mpi_generic.c         | 12 ++++++------
 expetator/experiment.py                    | 10 ++++++----
 expetator/monitors/laptop_power_monitor.py |  4 ++--
 expetator/monitors/lperf.py                | 10 +++++-----
 expetator/monitors/mojitos.py              |  5 +----
 expetator/monitors/power.py                |  4 ++--
 6 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/expetator/benchmarks/mpi_generic.c b/expetator/benchmarks/mpi_generic.c
index f9f2558..3d1a319 100644
--- a/expetator/benchmarks/mpi_generic.c
+++ b/expetator/benchmarks/mpi_generic.c
@@ -184,8 +184,8 @@ int main(int argc, char** argv) {
 // -c 1200
 // -m 35000
 
-/* time mpirun --machinefile /dev/shm/m ./a.out -m 35000 -n 1 -c 1200
-/dev/shm/m : 32 == cores
+/* time mpirun --machinefile m ./a.out -m 35000 -n 1 -c 1200
+m : 32 == cores
 real	2m26.163s
 user	32m6.416s
 sys	5m27.728s
@@ -196,8 +196,8 @@ sys	5m27.728s
 
 /*
 
-/* time mpirun  --machinefile /dev/shm/m2 ./a.out -m 35000 -n 1 -c 1200
-/dev/shm/m2 : 64 == hyperthread
+/* time mpirun  --machinefile m2 ./a.out -m 35000 -n 1 -c 1200
+m2 : 64 == hyperthread
 real	3m38.990s
 user	101m59.836s
 sys	12m21.300s
@@ -209,12 +209,12 @@ sys	12m21.300s
 
 /* RQ: avec mpirun --mca btl ^openib
 
-time mpirun  --mca btl ^openib --machinefile /dev/shm/m ./a.out -n 1
+time mpirun  --mca btl ^openib --machinefile m ./a.out -n 1
 real	0m53.827s
 user	6m38.412s
 sys	6m46.088s
 
-time mpirun  --machinefile /dev/shm/m ./a.out -n 1
+time mpirun  --machinefile m ./a.out -n 1
 real	0m53.990s
 user	6m43.392s
 sys	6m53.344s
diff --git a/expetator/experiment.py b/expetator/experiment.py
index 694c8e2..8553d86 100755
--- a/expetator/experiment.py
+++ b/expetator/experiment.py
@@ -8,6 +8,7 @@ import random
 import time
 import itertools
 from pathlib import Path
+import tempfile
 
 from functools import reduce
 from execo import Process
@@ -15,12 +16,13 @@ from execo import Process
 class Executor:
     'Allow access to the platform'
     def __init__(self):
+        self.tmp_dir
         if os.path.isdir('/dev/shm'):
-            self.mpi_host_file = '/dev/shm/mpi_host_file'
-            self.mpi_core_file = '/dev/shm/mpi_core_file'
+            self.tmp_dir = tempfile.mkdtemp(prefix="/dev/shm")
         else:
-            self.mpi_host_file = '/tmp/expetator_mpi_host_file'
-            self.mpi_core_file = '/tmp/expetator_mpi_core_file'
+            self.tmp_dir = tempfile.mkdtemp(prefix="/tmp/executor")
+        self.mpi_host_file = '%s/mpi_host_file' % self.tmp_dir
+        self.mpi_core_file = '%s/mpi_core_file' % self.tmp_dir
         self.mpi_options = ''
         self.hostnames = ['localhost']
         self.nbhosts = 1
diff --git a/expetator/monitors/laptop_power_monitor.py b/expetator/monitors/laptop_power_monitor.py
index 474c5b1..74abf00 100755
--- a/expetator/monitors/laptop_power_monitor.py
+++ b/expetator/monitors/laptop_power_monitor.py
@@ -18,7 +18,7 @@ if __name__ == '__main__':
     
     stay=True
 
-    with open('/dev/shm/power_measures','w') as power_file:
+    with open('/tmp/expetator_power_measures','w') as power_file:
         power_file.write('#timestamp power\n')
 
     try:
@@ -30,7 +30,7 @@ if __name__ == '__main__':
             current_time=time.time()
             int_current_time=int(current_time)
     
-            with open('/dev/shm/power_measures','a') as power_file:
+            with open('/tmp/expetator_power_measures','a') as power_file:
                 power_file.write(str(int_current_time)+' '+str(watt)+'\n')
             time.sleep(1-(current_time-int_current_time))
     except:
diff --git a/expetator/monitors/lperf.py b/expetator/monitors/lperf.py
index 3470f49..7881837 100644
--- a/expetator/monitors/lperf.py
+++ b/expetator/monitors/lperf.py
@@ -31,7 +31,7 @@ class Lperf:
         self.executor = executor
 
         self.cmdline = '/tmp/bin/lperf stat -x "!" -I %s -a -A -e %s' % (self.interval, ','.join(self.names))
-        self.cmdline += ' -o /dev/shm/lperf_monitoring &'
+        self.cmdline += ' -o %s/lperf_monitoring &' % executor.tmp_dir
 
     def start(self):
         'Starts the monitoring right before the benchmark'
@@ -47,8 +47,8 @@ class Lperf:
         os.makedirs(filename_moj, exist_ok=True)
         if len(self.executor.hostnames) > 1:
             for hostname in self.executor.hostnames:
-                self.executor.local('oarcp %s:/dev/shm/lperf_monitoring %s/%s_%s_%s' %
-                                    (hostname, filename_moj, hostname, benchname, beg_time))
+                self.executor.local('oarcp %s:%s/lperf_monitoring %s/%s_%s_%s' %
+                                    (hostname, self.executor.tmp_dir, filename_moj, hostname, benchname, beg_time))
         else:
-            self.executor.local('cp /dev/shm/lperf_monitoring %s/%s_%s_%s' %
-                                    (filename_moj, 'localhost', benchname, beg_time))
+            self.executor.local('cp %s/lperf_monitoring %s/%s_%s_%s' %
+                                    (self.executor.tmp_dir, filename_moj, 'localhost', benchname, beg_time))
diff --git a/expetator/monitors/mojitos.py b/expetator/monitors/mojitos.py
index a2ae125..2e90ace 100644
--- a/expetator/monitors/mojitos.py
+++ b/expetator/monitors/mojitos.py
@@ -93,10 +93,7 @@ class Mojitos:
             self.cmdline += ' -r'
         if self.load:
             self.cmdline += ' -u'
-        if os.path.isdir('/dev/shm'):
-            self.monitoring_file = '/dev/shm/monitoring_moj'
-        else:
-            self.monitoring_file = '/tmp/expetator_monitoring_moj'
+        self.monitoring_file = '%s/monitoring_moj' executor.tmp_dir
         self.cmdline += ' -o %s &' % self.monitoring_file
 
 
diff --git a/expetator/monitors/power.py b/expetator/monitors/power.py
index 3fb2d45..4bbcbe0 100644
--- a/expetator/monitors/power.py
+++ b/expetator/monitors/power.py
@@ -57,8 +57,8 @@ class Power:
 
                 result = [(raw['uid'], raw['timestamps'],raw['values']) for raw in raws]
         else:
-            self.executor.local('cp /dev/shm/power_measures %s' % target)
-            with open('/dev/shm/power_measures') as file_id:
+            self.executor.local('cp /tmp/expetator_power_measures %s' % target)
+            with open('/tmp/expetator_power_measures') as file_id:
                 content = [line.split() for line in file_id.readlines()[1:]]
             content = [(int(t), float(p)) for t,p in content]
             result = [('localhost',)+tuple(zip(*content))]
-- 
GitLab