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","template"]) |
---|
21 | meta_path = os.path.join(scenariodir, 'metalog.csv') |
---|
22 | final_path = os.path.join(scenariodir, 'final.csv') |
---|
23 | |
---|
24 | |
---|
25 | #main loop that runs maxcpus - 1 times |
---|
26 | maxcpus = 40 |
---|
27 | |
---|
28 | for n in range(1,maxcpus,1): |
---|
29 | |
---|
30 | #the different ways each HOST requires the parallel script to be run |
---|
31 | if (host == 'cyclone.agso.gov.au'): |
---|
32 | subprocess.call(['mpirun', '-np', str(n), '-hostfile' ,'~/machinefiles/test.machines_cyclone', '-x','PYTHONPATH','-x','INUNDATIONHOME','python', 'runcairns.py']) |
---|
33 | elif (host == 'tornado.agso.gov.au'): |
---|
34 | subprocess.call(['mpirun', '-np', str(n), '-hostfile' ,'~/machinefiles/test.machines_tornado', '-x','PYTHONPATH','-x','INUNDATIONHOME','python', 'runcairns.py']) |
---|
35 | elif (host == 'rhe-compute1.ga.gov.au'): |
---|
36 | subprocess.call(['mpirun', '-np', str(n), '-x','PYTHONPATH','-x','INUNDATIONHOME','python2.6', 'runcairns.py']) |
---|
37 | else: |
---|
38 | subprocess.call(['mpirun', '-np', str(n), '-x','PYTHONPATH','-x','INUNDATIONHOME','python', 'runcairns.py']) |
---|
39 | |
---|
40 | |
---|
41 | print 'Done' |
---|
42 | |
---|
43 | #get the important data for the experiments from the anuga experiments |
---|
44 | analyse_log(scenariodir, os.path.join(scenariodir,'metalog.csv')) |
---|
45 | |
---|
46 | #open files to read from and write to |
---|
47 | metalog = csv.reader(open(meta_path,'rb')) |
---|
48 | final = csv.writer(open(final_path,'wb')) |
---|
49 | |
---|
50 | #list stores the index of the values required |
---|
51 | indexlist = [] |
---|
52 | |
---|
53 | #read in the first row |
---|
54 | firstrow = metalog.next() |
---|
55 | |
---|
56 | #get the indices of the values we want, so that the data can be condensed |
---|
57 | indexlist.append(firstrow.index("beforetime")) |
---|
58 | indexlist.append(firstrow.index("aftertime")) |
---|
59 | indexlist.append(firstrow.index("aftermeshtime")) |
---|
60 | indexlist.append(firstrow.index("beforesimulationmemory")) |
---|
61 | indexlist.append(firstrow.index("aftermeshmemory")) |
---|
62 | indexlist.append(firstrow.index("afterinitialconditionsmemory")) |
---|
63 | indexlist.append(firstrow.index("afterboundarymemory")) |
---|
64 | indexlist.append(firstrow.index("aftersimulationmemory")) |
---|
65 | indexlist.append(firstrow.index("numberofcpus")) |
---|
66 | indexlist.append(firstrow.index("myid")) |
---|
67 | |
---|
68 | #write the header for the final csv |
---|
69 | final.writerow(["TimeTaken(s)","MeshTime(s)", |
---|
70 | firstrow[(indexlist[3])],firstrow[(indexlist[4])], |
---|
71 | firstrow[(indexlist[5])],firstrow[(indexlist[6])], |
---|
72 | firstrow[(indexlist[7])],firstrow[(indexlist[8])], |
---|
73 | firstrow[(indexlist[9])]]) |
---|
74 | |
---|
75 | #write the data for each column in the final csv |
---|
76 | for row in metalog: |
---|
77 | |
---|
78 | #manipulate the beginning and end time to get the time taken |
---|
79 | begin = time.strptime(row[(indexlist[0])],'%Y%m%d_%H%M%S') |
---|
80 | end = time.strptime(row[(indexlist[1])],'%Y%m%d_%H%M%S') |
---|
81 | mesh = time.strptime(row[(indexlist[2])],'%Y%m%d_%H%M%S') |
---|
82 | taken = time.mktime(end) - time.mktime(begin) |
---|
83 | meshtime =time.mktime(mesh) - time.mktime(begin) |
---|
84 | |
---|
85 | #write to file |
---|
86 | final.writerow([str(taken),str(meshtime), |
---|
87 | row[(indexlist[3])],row[(indexlist[4])], |
---|
88 | row[(indexlist[5])],row[(indexlist[6])], |
---|
89 | row[(indexlist[7])],row[(indexlist[8])], |
---|
90 | row[(indexlist[9])]]) |
---|