- 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/scenarios/vel2/main.py
r8328 r8331 16 16 scenariodir = add_directories(home, ["data","mem_time_test", "scenarios", 17 17 "velocity"]) 18 file = 'ex1.csv'19 file_path = os.path.join(scenariodir, file)20 18 meta = 'metalog.csv' 21 19 meta_path = os.path.join(scenariodir, meta) 22 20 final = 'final.csv' 23 21 final_path = os.path.join(scenariodir, final) 24 store = 'store.txt'25 store_path = os.path.join(scenariodir, store)26 27 #set up needed files28 firstex1 = open(file_path, 'wb')29 spamWriter = csv.writer(firstex1)30 spamWriter.writerow(['Velocity(m/s)','Number Of Triangles','Extent(m^2)' , 'Time Taken(s)','Space Used'])31 storeopen = open(store_path,'a')32 storeopen.close33 22 34 23 # these are the main loops that give the velocity of inflow (m) and the map side length(n) 35 24 for m in range(0,250,10): 36 25 for n in range(1,2000,300): 37 38 z = time.time() #time it 39 subprocess.call(['python2.5', 'ex1.py', str(m), str(n)])#run simulation script 40 y = time.time() #time it 41 42 # read the number of triangles from this text file 43 f = open(store_path,'r+') 44 h = float(f.readline()) 45 f.close() 46 47 spamWriter.writerow([m,h,(n*n),(y-z), 'b'])# record it 26 subprocess.call(['python2.5', 'ex1.py', str(m), str(n)])#run simulation script 48 27 print 'DONE' 49 28 50 analyse_log(scenariodir, os.path.join(scenariodir,'metalog.csv')) #get the memory usage from the log files 29 #get the important data for the experiments from the anuga experiments 30 analyse_log(scenariodir, os.path.join(scenariodir,'metalog.csv')) 51 31 52 #close ex1.csv so we can read from it for a different csv reader object 53 firstex1.close() 54 55 #merge the metalog useful memory info and the ex1 recorded info into one csv file named final 56 ex1 = csv.reader(open(file_path,'rb')) 32 #open files to read from and write to 57 33 metalog = csv.reader(open(meta_path,'rb')) 58 34 final = csv.writer(open(final_path,'wb')) 59 35 36 #list stores the index of the values requird 37 indexlist = [] 60 38 61 for row in ex1: 62 d = metalog.next() 63 final.writerow([row[0],row[1],d[0],d[3],d[6],d[9],d[12]])#,d[15],d[18]]) 39 #read in the first row 40 firstrow = metalog.next() 41 42 #get the indices of the values we want, so that the data can be condensed 43 indexlist.append(firstrow.index("beforetime")) 44 indexlist.append(firstrow.index("aftertime")) 45 indexlist.append(firstrow.index("beforesimulationmemory")) 46 indexlist.append(firstrow.index("aftermeshmemory")) 47 indexlist.append(firstrow.index("afterinitialconditionsmemory")) 48 indexlist.append(firstrow.index("afterboundarymemory")) 49 indexlist.append(firstrow.index("aftersimulationmemory")) 50 indexlist.append(firstrow.index("variable1")) 51 52 #not all experiments have 3 variables, but some do 53 try: 54 indexlist.append(firstrow.index("variable2")) 55 except ValueError: 56 indexlist.append(firstrow.index("beforetime")) 57 try: 58 indexlist.append(firstrow.index("variable3")) 59 except ValueError: 60 indexlist.append(firstrow.index("aftertime")) 61 62 #write the header for the final csv 63 final.writerow(["TimeTaken(s)",firstrow[(indexlist[2])], 64 firstrow[(indexlist[3])],firstrow[(indexlist[4])], 65 firstrow[(indexlist[5])],firstrow[(indexlist[6])], 66 firstrow[(indexlist[7])],firstrow[(indexlist[8])], 67 firstrow[(indexlist[9])]]) 68 69 #write the data for each column in the final csv 70 for row in metalog: 71 72 #manipulate the beginning and end time to get the time taken 73 begin = time.strptime(row[(indexlist[0])],'%Y%m%d_%H%M%S') 74 end = time.strptime(row[(indexlist[1])],'%Y%m%d_%H%M%S') 75 taken = time.mktime(end) - time.mktime(begin) 76 77 #write to file 78 final.writerow([str(taken),row[(indexlist[2])], 79 row[(indexlist[3])],row[(indexlist[4])], 80 row[(indexlist[5])],row[(indexlist[6])], 81 row[(indexlist[7])],row[(indexlist[8])], 82 row[(indexlist[9])]]) 83 84
Note: See TracChangeset
for help on using the changeset viewer.