1 | """Simple water flow example using ANUGA |
---|
2 | Water flowing down a channel |
---|
3 | """ |
---|
4 | #------------------------------------------------------------------------------ |
---|
5 | # Import necessary modules |
---|
6 | #------------------------------------------------------------------------------ |
---|
7 | import anuga |
---|
8 | import subprocess |
---|
9 | import csv |
---|
10 | import os |
---|
11 | import time |
---|
12 | from anuga.abstract_2d_finite_volumes.util import add_directories |
---|
13 | from anuga.utilities.log_analyser import analyse_log |
---|
14 | |
---|
15 | #-------------------------------------------------------------------------------------- |
---|
16 | # Set up variables for the correct directories to store the output |
---|
17 | #-------------------------------------------------------------------------------------- |
---|
18 | host = os.getenv('HOST') |
---|
19 | home = os.getenv('INUNDATIONHOME') |
---|
20 | scenariodir = add_directories(home, ["data","mem_time_test", "parallel","cairns"]) |
---|
21 | file1 = 'ex1.csv' |
---|
22 | file_path = os.path.join(scenariodir, file1) |
---|
23 | |
---|
24 | firstex1 = open(file_path, 'wb') |
---|
25 | spamWriter = csv.writer(firstex1) |
---|
26 | spamWriter.writerow(['Number Of Processors' , 'Space Used MB' , 'Time Taken (s)']) |
---|
27 | |
---|
28 | |
---|
29 | # main loop that runs macpus - 1 times |
---|
30 | maxcpus = 18 |
---|
31 | |
---|
32 | for n in range(1,maxcpus,1): |
---|
33 | z = time.time() # time it |
---|
34 | |
---|
35 | #the necessary ways to run this script in parallel on the different hosts we use |
---|
36 | if (host == 'cyclone.agso.gov.au'): |
---|
37 | subprocess.call(['mpirun', '-np', str(n), '-hostfile' ,'~/machinefiles/test.machines_cyclone', '-x','PYTHONPATH','-x','INUNDATIONHOME','python', 'runcairns.py']) |
---|
38 | if (host == 'tornado.agso.gov.au'): |
---|
39 | subprocess.call(['mpirun', '-np', str(n), '-hostfile' ,'~/machinefiles/test.machines_tornado', '-x','PYTHONPATH','-x','INUNDATIONHOME','python', 'runcairns.py']) |
---|
40 | if (host == 'vayu1'): |
---|
41 | subprocess.call(['mpirun', '-np', str(n), '-x','PYTHONPATH','-x','INUNDATIONHOME','python', 'runcairns.py']) |
---|
42 | if (host == 'rhe-compute1.ga.gov.au'): |
---|
43 | subprocess.call(['mpirun', '-np', str(n), '-x','PYTHONPATH','-x','INUNDATIONHOME','python2.6', 'runcairns.py']) |
---|
44 | if (host == 'xe'): |
---|
45 | subprocess.call(['mpirun', '-np', str(n), '-x','PYTHONPATH','-x','INUNDATIONHOME','python', 'runcairns.py']) |
---|
46 | |
---|
47 | y = time.time()# time it |
---|
48 | spamWriter.writerow([n,'x' ,(y-z)]) # write recorded results |
---|
49 | print 'DONE' |
---|
50 | |
---|
51 | analyse_log(scenariodir, os.path.join(scenariodir,'metalog.csv')) #get the memory usage from the log files |
---|
52 | |
---|
53 | #close ex1.csv so we can read from it for a different csv reader object |
---|
54 | firstex1.close() |
---|
55 | |
---|
56 | #merge the metalog useful memory info and the ex1 recorded info into one csv file named final |
---|
57 | ex1 = csv.reader(open(file_path,'rb')) |
---|
58 | metalog = csv.reader(open(meta_path,'rb')) |
---|
59 | final = csv.writer(open(final_path,'wb')) |
---|
60 | |
---|
61 | |
---|
62 | for row in ex1: |
---|
63 | d = metalog.next() |
---|
64 | final.writerow([row[0],row[1],d[0],d[3],d[6],d[9],d[12]])#,d[15],d[18]]) |
---|