Changeset 8331 for trunk/anuga_work/development/mem_time_tests/parameters/timelen-over-timestep/main.py
- Timestamp:
- Feb 10, 2012, 10:34:08 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_work/development/mem_time_tests/parameters/timelen-over-timestep/main.py
r8328 r8331 5 5 import anuga 6 6 import time 7 import random8 7 import subprocess 9 8 import csv … … 19 18 scenariodir = add_directories(home, ["data","mem_time_test", "parameters", 20 19 "timelen-over-timestep"]) 21 file = 'ex1.csv'22 file_path = os.path.join(scenariodir, file)23 20 meta = 'metalog.csv' 24 21 meta_path = os.path.join(scenariodir, meta) … … 26 23 final_path = os.path.join(scenariodir, final) 27 24 28 #create each file 29 firstex1 = open(file_path, 'wb') 30 spamWriter = csv.writer(firstex1) 31 spamWriter.writerow(['Time Length(s)','Time Step (s)' , 'Time Taken','Space Used']) 25 # main loops that give the time length (m) and the time step (n) 26 for m in range(10,1000,200): 32 27 33 # main loops that give the time length (m) and the time step (n) 34 for m in range(1,1000,50): 35 36 for n in range(1,1000,5): 28 for n in range(10,1000,100): 37 29 n = n/100.0 #adjust it so its small enough to see the nature of the relationship 38 39 x = time.time()#time it40 30 subprocess.call(['python2.5', 'ex1.py',str(m),str(n)])#run it 41 y = time.time()#time it42 spamWriter.writerow([m,n ,(y-x),'b'])#write the results43 44 31 print 'Done' 45 32 46 analyse_log(scenariodir, os.path.join(scenariodir,'metalog.csv')) #get the memory usage from the log files 33 #get the important data for the experiments from the anuga experiments 34 analyse_log(scenariodir, os.path.join(scenariodir,'metalog.csv')) 47 35 48 #close ex1.csv so we can read from it for a different csv reader object 49 firstex1.close() 50 51 #merge the metalog useful memory info and the ex1 recorded info into one csv file named final 52 ex1 = csv.reader(open(file_path,'rb')) 36 #open files to read from and write to 53 37 metalog = csv.reader(open(meta_path,'rb')) 54 38 final = csv.writer(open(final_path,'wb')) 55 39 40 #list stores the index of the values requird 41 indexlist = [] 56 42 57 for row in ex1: 58 d = metalog.next() 59 final.writerow([row[0],row[1],d[0],d[3],d[6],d[9],d[12]])#,d[15],d[18]]) 43 #read in the first row 44 firstrow = metalog.next() 45 46 #get the indices of the values we want, so that the data can be condensed 47 indexlist.append(firstrow.index("beforetime")) 48 indexlist.append(firstrow.index("aftertime")) 49 indexlist.append(firstrow.index("beforesimulationmemory")) 50 indexlist.append(firstrow.index("aftermeshmemory")) 51 indexlist.append(firstrow.index("afterinitialconditionsmemory")) 52 indexlist.append(firstrow.index("afterboundarymemory")) 53 indexlist.append(firstrow.index("aftersimulationmemory")) 54 indexlist.append(firstrow.index("variable1")) 55 56 #not all experiments have 3 variables, but some do 57 try: 58 indexlist.append(firstrow.index("variable2")) 59 except ValueError: 60 indexlist.append(firstrow.index("beforetime")) 61 try: 62 indexlist.append(firstrow.index("variable3")) 63 except ValueError: 64 indexlist.append(firstrow.index("aftertime")) 65 66 #write the header for the final csv 67 final.writerow(["TimeTaken(s)",firstrow[(indexlist[2])], 68 firstrow[(indexlist[3])],firstrow[(indexlist[4])], 69 firstrow[(indexlist[5])],firstrow[(indexlist[6])], 70 firstrow[(indexlist[7])],firstrow[(indexlist[8])], 71 firstrow[(indexlist[9])]]) 72 73 #write the data for each column in the final csv 74 for row in metalog: 75 76 #manipulate the beginning and end time to get the time taken 77 begin = time.strptime(row[(indexlist[0])],'%Y%m%d_%H%M%S') 78 end = time.strptime(row[(indexlist[1])],'%Y%m%d_%H%M%S') 79 taken = time.mktime(end) - time.mktime(begin) 80 81 #write to file 82 final.writerow([str(taken),row[(indexlist[2])], 83 row[(indexlist[3])],row[(indexlist[4])], 84 row[(indexlist[5])],row[(indexlist[6])], 85 row[(indexlist[7])],row[(indexlist[8])], 86 row[(indexlist[9])]]) 87 88
Note: See TracChangeset
for help on using the changeset viewer.