source: trunk/anuga_work/development/mem_time_tests/linearregression/area/main.py @ 8427

Last change on this file since 8427 was 8427, checked in by davies, 13 years ago

Adding the trapezoidal channel validation test, and editing the ANUGA manual

File size: 9.9 KB
Line 
1#------------------------------------------------------------------------------
2# Import necessary modules
3#------------------------------------------------------------------------------
4import anuga
5import subprocess
6import csv
7import os
8import numpy
9import time
10import liststore
11from anuga.abstract_2d_finite_volumes.util import add_directories
12from anuga.utilities.log_analyser import analyse_log
13
14#------------------------------------------------------------------------------
15# Set up variables for the correct directories to store the output
16#------------------------------------------------------------------------------
17home = os.getenv('INUNDATIONHOME')
18host = os.getenv('HOST')
19scenariodir = add_directories(home, ["data","mem_time_test", 
20                                     "linearregression","run"])
21meta = 'metalog.csv'
22meta_path = os.path.join(scenariodir, meta)
23final = 'final.csv'
24final_path = os.path.join(scenariodir, final)
25equation = 'equation.csv'
26equation_path = os.path.join(scenariodir, equation)
27
28#------------------------------------------------------------------------------
29# MAIN LOOP
30# this is the main loops that assigns the maximum triangle area (m) 
31# and the map side length(l)
32#------------------------------------------------------------------------------
33n = 1 #number of processors to use
34for seed in range(0,30):
35    stdsidelength = 154.90
36    stdtimelength = 3600.0
37    stdtimestep = stdtimelength / 60.0
38 
39    varsidelength = 5 + seed * (800.0/30.0)
40    vartimelength = 10 + seed * (86400.0/30.0)
41    vartimestep = 0.5 + seed *(1800 / 30)
42    vartimestep2 =vartimelength / 60.0
43
44    # side length experiment
45    if (host == 'cyclone.agso.gov.au'):
46       subprocess.call(['mpirun', '-np', str(n), '-hostfile' ,
47       '~/machinefiles/lnrrun.machines_cyclone', '-x','PYTHONPATH','-x',
48       'INUNDATIONHOME','python', 'runcairns.py',str(stdtimestep),
49       str(stdtimelength),str(varsidelength)]) 
50    elif (host == 'tornado.agso.gov.au'):
51         subprocess.call(['mpirun', '-np', str(n), '-hostfile' ,
52         '~/machinefiles/lnrrun.machines_tornado', '-x','PYTHONPATH','-x',
53         'INUNDATIONHOME','python', 'runcairns.py',str(stdtimestep),
54         str(stdtimelength),str(varsidelength)])
55    elif (host == 'rhe-compute1.ga.gov.au'):
56         subprocess.call(['mpirun', '-np', str(n), '-x','PYTHONPATH','-x',
57         'INUNDATIONHOME','python2.6', 'runcairns.py',str(stdtimestep),
58         str(stdtimelength),str(varsidelength)])   
59    else:
60         subprocess.call(['mpirun', '-np', str(n), '-x','PYTHONPATH','-x',
61         'INUNDATIONHOME','python', 'runcairns.py',str(stdtimestep),
62         str(stdtimelength),str(varsidelength)]) 
63
64    # time length experiment
65    if (host == 'cyclone.agso.gov.au'):
66       subprocess.call(['mpirun', '-np', str(n), 
67       '-hostfile' ,'~/machinefiles/lnrrun.machines_cyclone', '-x',
68       'PYTHONPATH','-x','INUNDATIONHOME','python', 'runcairns.py',
69       str(vartimestep2),str(vartimelength),str(stdsidelength)]) 
70    elif (host == 'tornado.agso.gov.au'):
71         subprocess.call(['mpirun', '-np', str(n), '-hostfile' ,
72         '~/machinefiles/lnrrun.machines_tornado', '-x','PYTHONPATH','-x',
73         'INUNDATIONHOME','python', 'runcairns.py',str(vartimestep2),
74         str(vartimelength),str(stdsidelength)])
75    elif (host == 'rhe-compute1.ga.gov.au'):
76         subprocess.call(['mpirun', '-np', str(n), '-x','PYTHONPATH','-x',
77         'INUNDATIONHOME','python2.6', 'runcairns.py',str(vartimestep2),
78         str(vartimelength),str(stdsidelength)])   
79    else:
80         subprocess.call(['mpirun', '-np', str(n), '-x','PYTHONPATH','-x',
81         'INUNDATIONHOME','python', 'runcairns.py',str(vartimestep2),
82         str(vartimelength),str(stdsidelength)]) 
83
84
85    # time step  experiment
86    if (host == 'cyclone.agso.gov.au'):
87       subprocess.call(['mpirun', '-np', str(n), '-hostfile' ,
88       '~/machinefiles/lnrrun.machines_cyclone', '-x','PYTHONPATH','-x',
89       'INUNDATIONHOME','python', 'runcairns.py',str(vartimestep),
90       str(stdtimelength),str(stdsidelength)]) 
91    elif (host == 'tornado.agso.gov.au'):
92         subprocess.call(['mpirun', '-np', str(n), '-hostfile' ,
93         '~/machinefiles/lnrrun.machines_tornado', '-x','PYTHONPATH','-x',
94         'INUNDATIONHOME','python', 'runcairns.py',str(vartimestep),
95         str(stdtimelength),str(stdsidelength)])
96    elif (host == 'rhe-compute1.ga.gov.au'):
97         subprocess.call(['mpirun', '-np', str(n), '-x','PYTHONPATH','-x',
98         'INUNDATIONHOME','python2.6', 'runcairns.py',str(vartimestep),
99         str(stdtimelength),str(stdsidelength)])   
100    else:
101         subprocess.call(['mpirun', '-np', str(n), '-x','PYTHONPATH','-x',
102         'INUNDATIONHOME','python', 'runcairns.py',str(vartimestep),
103         str(stdtimelength),str(stdsidelength)]) 
104
105print 'Done'
106
107#------------------------------------------------------------------------------
108# LOG ANALYSE
109# and the Linear Regression
110#------------------------------------------------------------------------------
111
112#get the important data for the experiments from the anuga experiments
113analyse_log(scenariodir, os.path.join(scenariodir,'metalog.csv')) 
114
115#open files to read from and write to
116metalog = csv.reader(open(meta_path,'rb'))
117final = csv.writer(open(final_path,'wb'))
118eq = csv.writer(open(equation_path,'wb'))
119
120#lists used to condense the metalog file and the regression equation
121indexlist = []
122triangles = []
123trianglessquared = []
124timelength = []
125filewrites = []
126timelist = []
127space = []
128
129#read in the first row
130firstrow = metalog.next()
131
132#get the indices of the values we want, so that the data can be condensed
133indexlist.append(firstrow.index("beforetime"))
134indexlist.append(firstrow.index("aftertime"))
135indexlist.append(firstrow.index("aftermeshtime"))
136indexlist.append(firstrow.index("beforesimulationmemory"))
137indexlist.append(firstrow.index("aftermeshmemory"))
138indexlist.append(firstrow.index("afterinitialconditionsmemory"))
139indexlist.append(firstrow.index("afterboundarymemory"))
140indexlist.append(firstrow.index("aftersimulationmemory"))
141
142indexlist.append(firstrow.index("numberoftriangles"))
143indexlist.append(firstrow.index("finaltime"))
144indexlist.append(firstrow.index("timestep"))
145indexlist.append(firstrow.index("extent"))
146indexlist.append(firstrow.index("sidelength"))
147indexlist.append(firstrow.index("maxtrianglearea"))
148indexlist.append(firstrow.index("velocity"))
149indexlist.append(firstrow.index("depthofwater"))
150indexlist.append(firstrow.index("percentageofwatercover"))
151indexlist.append(firstrow.index("numberofcpus"))
152indexlist.append(firstrow.index("host"))
153
154#write the header for the final csv
155final.writerow(["TimeTaken(s)","MeshTime(s)",
156                firstrow[(indexlist[3])],firstrow[(indexlist[4])],
157                firstrow[(indexlist[5])],firstrow[(indexlist[6])],
158                firstrow[(indexlist[7])],firstrow[(indexlist[8])],
159                firstrow[(indexlist[9])],firstrow[(indexlist[10])],
160                firstrow[(indexlist[11])],firstrow[(indexlist[12])],
161                firstrow[(indexlist[13])],firstrow[(indexlist[14])],
162                firstrow[(indexlist[15])],firstrow[(indexlist[16])],
163                firstrow[(indexlist[17])],firstrow[(indexlist[18])]])
164
165#write the data for each column in the final csv
166for row in metalog:
167
168    #manipulate the beginning and end time to get the time taken
169    begin = time.strptime(row[(indexlist[0])],'%Y%m%d_%H%M%S')
170    end = time.strptime(row[(indexlist[1])],'%Y%m%d_%H%M%S')
171    aftermesh = time.strptime(row[(indexlist[2])],'%Y%m%d_%H%M%S')
172    taken = time.mktime(end) - time.mktime(begin)
173    mesh = time.mktime(aftermesh) - time.mktime(begin)
174
175    #write to file
176    final.writerow([str(taken),str(mesh),
177                   row[(indexlist[3])],row[(indexlist[4])],
178                   row[(indexlist[5])],row[(indexlist[6])],
179                   row[(indexlist[7])],row[(indexlist[8])],
180                   row[(indexlist[9])],row[(indexlist[10])],
181                   row[(indexlist[11])],row[(indexlist[12])],
182                   row[(indexlist[13])],row[(indexlist[14])],
183                   row[(indexlist[15])],row[(indexlist[16])],
184                   row[(indexlist[17])],row[(indexlist[18])]])
185     
186    #make a list of all the data points, to be used in the regression
187    timelist.append(float(taken))
188    space.append(float(row[(indexlist[7])]))
189    triangles.append(float(row[(indexlist[8])]))
190    trianglessquared.append(float(row[(indexlist[8])])**2)
191    timelength.append(float(row[(indexlist[9])]))
192    filewrites.append(float(row[(indexlist[9])])/float(row[(indexlist[10])]))
193
194#convert these lists to arrays
195spa = numpy.asarray(space)
196tim = numpy.asarray(timelist)     
197tri = numpy.asarray(triangles)
198trisq = numpy.asarray(trianglessquared)
199timlen = numpy.asarray(timelength)
200filwrit = numpy.asarray(filewrites)
201
202# Manipulate the arrays, to stack them into one array that will work the
203# way we want for regression
204multivariatearray = numpy.column_stack([tri.flat,trisq.flat,timlen.flat,
205                                        filwrit.flat, numpy.ones(90,float)])
206multivariatearrayspace = numpy.column_stack([tri.flat, numpy.ones(90,float)])
207
208#get the equations for both time and memory
209timequation = numpy.linalg.lstsq(multivariatearray,tim)[0]
210spaequation = numpy.linalg.lstsq(multivariatearrayspace,spa)[0]
211
212#calculate the R squared values for each equation
213resid1 = numpy.linalg.lstsq(multivariatearray,tim)[1]
214resid2 = numpy.linalg.lstsq(multivariatearrayspace,spa)[1]
215r2 = 1 - resid1 / (tim.size * tim.var())
216r3 = 1 - resid2 / (spa.size * spa.var())
217
218#write these values back to lists
219listtime = timequation.tolist()
220listspace = spaequation.tolist()
221
222#write the equation data to file
223eq.writerow(['Dependent Variable', 'Number of Triangles',
224             'Number of Triangles Squared','Time Length','File Writes',
225             'Constant', 'R Squared'])
226eq.writerow(['Time']+listtime + r2.tolist())
227eq.writerow(['Dependent Variable', 'Number of Triangles','Constant', 
228             'R Squared'])
229eq.writerow(['Space']+listspace + r3.tolist())
230
231
Note: See TracBrowser for help on using the repository browser.