1 | #------------------------------------------------------------------------------ |
---|
2 | # Import necessary modules |
---|
3 | #------------------------------------------------------------------------------ |
---|
4 | import anuga |
---|
5 | import subprocess |
---|
6 | import csv |
---|
7 | import os |
---|
8 | import time |
---|
9 | import liststore |
---|
10 | from anuga.abstract_2d_finite_volumes.util import add_directories |
---|
11 | from anuga.utilities.log_analyser import analyse_log |
---|
12 | |
---|
13 | #------------------------------------------------------------------------------ |
---|
14 | # Set up variables for the correct directories to store the output |
---|
15 | #------------------------------------------------------------------------------ |
---|
16 | home = os.getenv('INUNDATIONHOME') |
---|
17 | host = os.getenv('HOST') |
---|
18 | scenariodir = add_directories(home, ["data","mem_time_test", "triangles","area"]) |
---|
19 | file1 = 'ex1.csv' |
---|
20 | meta = 'metalog.csv' |
---|
21 | meta_path = os.path.join(scenariodir, meta) |
---|
22 | final = 'final.csv' |
---|
23 | final_path = os.path.join(scenariodir, final) |
---|
24 | storen ='storen.txt' |
---|
25 | file_path_storen = os.path.join(scenariodir, storen) |
---|
26 | |
---|
27 | #set up needed files |
---|
28 | firstex1 = open(file_path, 'wb') |
---|
29 | spamWriter = csv.writer(firstex1) |
---|
30 | spamWriter.writerow(['Number of Triangles','Max Area(m^2)','Extent(m^2)' , 'Time Taken(s)','Space Used']) |
---|
31 | e = open(file_path_storen,'a') |
---|
32 | e.close() |
---|
33 | |
---|
34 | # this is the main loops that assigns the maximum triangle area (m) and the map side length(l) |
---|
35 | |
---|
36 | n = 4 #number of processors to use |
---|
37 | for m in range(90,100,10): |
---|
38 | for l in range(100,2000,100): |
---|
39 | |
---|
40 | z = time.time()# time it |
---|
41 | |
---|
42 | #the different ways each host calls MPI properly |
---|
43 | if (host == 'cyclone.agso.gov.au'): |
---|
44 | subprocess.call(['mpirun', '-np', str(n), '-hostfile' ,'~/machinefiles/test.machines_cyclone', '-x','PYTHONPATH','-x','INUNDATIONHOME','python', 'runcairns.py',str(m),str(l)]) |
---|
45 | if (host == 'tornado.agso.gov.au'): |
---|
46 | subprocess.call(['mpirun', '-np', str(n), '-hostfile' ,'~/machinefiles/test.machines_tornado', '-x','PYTHONPATH','-x','INUNDATIONHOME','python', 'runcairns.py',str(m),str(l)]) |
---|
47 | if (host == 'vayu1'): |
---|
48 | subprocess.call(['mpirun', '-np', str(n), '-x','PYTHONPATH','-x','INUNDATIONHOME','python', 'runcairns.py',str(m),str(l)]) |
---|
49 | if (host == 'rhe-compute1.ga.gov.au'): |
---|
50 | subprocess.call(['mpirun', '-np', str(n), '-x','PYTHONPATH','-x','INUNDATIONHOME','python2.6', 'runcairns.py',str(m),str(l)]) |
---|
51 | if (host == 'xe'): |
---|
52 | subprocess.call(['mpirun', '-np', str(n), '-x','PYTHONPATH','-x','INUNDATIONHOME','python', 'runcairns.py',str(m),str(l)]) |
---|
53 | |
---|
54 | y = time.time()# time it |
---|
55 | |
---|
56 | # read the number of triangles from this file |
---|
57 | f = open(file_path_storen,'r+') |
---|
58 | i = float(f.readline()) |
---|
59 | f.close() |
---|
60 | |
---|
61 | spamWriter.writerow([i,m,(l*l),'x' ,(y-z)])# record it |
---|
62 | |
---|
63 | print 'Done' |
---|
64 | |
---|
65 | analyse_log(scenariodir, os.path.join(scenariodir,'metalog.csv')) #get the memory usage from the log files |
---|
66 | |
---|
67 | #close ex1.csv so we can read from it for a different csv reader object |
---|
68 | firstex1.close() |
---|
69 | |
---|
70 | #merge the metalog useful memory info and the ex1 recorded info into one csv file named final |
---|
71 | ex1 = csv.reader(open(file_path,'rb')) |
---|
72 | metalog = csv.reader(open(meta_path,'rb')) |
---|
73 | final = csv.writer(open(final_path,'wb')) |
---|
74 | |
---|
75 | |
---|
76 | for row in ex1: |
---|
77 | d = metalog.next() |
---|
78 | final.writerow([row[0],row[1],d[0],d[3],d[6],d[9],d[12]])#,d[15],d[18]]) |
---|
79 | |
---|