Debian Codegraph @

packages/muelu/research/tawiesn/crada/genFiles.py

raw
1 #!/usr/bin/env python
2
3 #import os.path
4 import os
5 import sys
6 import math
7
8 def getstatusoutput(cmd):
9 """Return (status, output) of executing cmd in a shell."""
10 pipe = os.popen(cmd + ' 2>&1', 'r')
11 text = pipe.read()
12 sts = pipe.close()
13 if sts is None: sts = 0
14 if text[-1:] == '\n': text = text[:-1]
15 return sts, text
16
17
18 def deleteDir(path):
19 """deletes the path entirely"""
20 cmd = "rm -rf "+path
21 result = getstatusoutput(cmd)
22 if(result[0]!=0):
23 raise RuntimeError(result[1])
24
25 def createDir(path):
26 """deletes the path entirely"""
27 cmd = "mkdir "+path
28 result = getstatusoutput(cmd)
29 if(result[0]!=0):
30 raise RuntimeError(result[1])
31
32 def runCommand(cmd):
33 """deletes the path entirely"""
34 result = getstatusoutput(cmd)
35 #if(result[0]!=0):
36 # raise RuntimeError(result[1])
37 return result[1]
38
39 ###########
40 # MAIN routine
41 def main(argv=None):
42
43
44
45 jobfilename = "runJobs.sh"
46
47 # open jobfile
48 if os.path.isfile(jobfilename):
49 os.remove(jobfilename)
50 jobfile = open(jobfilename,"a")
51
52 jobfile.write("#!/bin/bash\n")
53
54 genFile("crada50x50x30-","muelu","driver_fullAMG.xml", 4, 1000, 1, 1.0 , "true", 1, 1.25, "false", "SGS", 3, 0.8, "ILU", 2, 8, jobfile)
55 genFile("crada50x50x30-","muelu","driver_fullAMG.xml", 4, 1000, 1, 1.1 , "true", 1, 1.25, "false", "SGS", 3, 0.8, "ILU", 2, 8, jobfile)
56 genFile("crada50x50x30-","muelu","driver_fullAMG.xml", 4, 1000, 1, 1.15, "true", 1, 1.25, "false", "SGS", 3, 0.8, "ILU", 2, 8, jobfile)
57 genFile("crada50x50x30-","muelu","driver_fullAMG.xml", 4, 1000, 1, 1.2 , "true", 1, 1.25, "false", "SGS", 3, 0.8, "ILU", 2, 8, jobfile)
58 genFile("crada50x50x30-","muelu","driver_fullAMG.xml", 4, 1000, 1, 1.25, "true", 1, 1.25, "false", "SGS", 3, 0.8, "ILU", 2, 8, jobfile)
59 genFile("crada50x50x30-","muelu","driver_fullAMG.xml", 4, 1000, 1, 1.3 , "true", 1, 1.25, "false", "SGS", 3, 0.8, "ILU", 2, 8, jobfile)
60
61
62 genFile("crada50x50x30-","muelu","driver_fullAMG.xml", 4, 1000, 1, 1.25, "true", 2, 1.25, "false", "SGS", 3, 0.8, "ILU", 2, 8, jobfile)
63 genFile("crada50x50x30-","muelu","driver_fullAMG.xml", 4, 1000, 2, 1.25, "true", 2, 1.25, "false", "SGS", 3, 0.8, "ILU", 2, 8, jobfile)
64
65
66 genFile("crada50x50x30-","muelu","driver_fullAMG.xml", 4, 1000, 1, 1.2 , "true", 1, 1.25, "false", "SGS", 1, 0.8, "ILU", 2, 8, jobfile)
67 genFile("crada50x50x30-","muelu","driver_fullAMG.xml", 4, 1000, 1, 1.25, "true", 1, 1.25, "false", "SGS", 2, 0.8, "ILU", 2, 8, jobfile)
68 genFile("crada50x50x30-","muelu","driver_fullAMG.xml", 4, 1000, 1, 1.3 , "true", 1, 1.25, "false", "SGS", 3, 0.8, "ILU", 2, 8, jobfile)
69
70 genFile("crada50x50x30-","muelu","driver_fullAMG.xml", 4, 1000, 1, 1.0 , "true", 1, 1.25, "false", "SGS", 3, 0.8, "ILU", 1, 8, jobfile)
71 genFile("crada50x50x30-","muelu","driver_fullAMG.xml", 4, 1000, 1, 1.1 , "true", 1, 1.25, "false", "SGS", 3, 0.8, "ILU", 1, 8, jobfile)
72 genFile("crada50x50x30-","muelu","driver_fullAMG.xml", 4, 1000, 1, 1.15, "true", 1, 1.25, "false", "SGS", 3, 0.8, "ILU", 1, 8, jobfile)
73 genFile("crada50x50x30-","muelu","driver_fullAMG.xml", 4, 1000, 1, 1.2 , "true", 1, 1.25, "false", "SGS", 3, 0.8, "ILU", 1, 8, jobfile)
74 genFile("crada50x50x30-","muelu","driver_fullAMG.xml", 4, 1000, 1, 1.25, "true", 1, 1.25, "false", "SGS", 3, 0.8, "ILU", 1, 8, jobfile)
75 genFile("crada50x50x30-","muelu","driver_fullAMG.xml", 4, 1000, 1, 1.3 , "true", 1, 1.25, "false", "SGS", 3, 0.8, "ILU", 1, 8, jobfile)
76
77
78 # close the jobfile
79 jobfile.close()
80
81
82 def genFile(seriesname,simname,tmplfile,maxLevel,maxCoarseSize, simplesweeps, simplerelax, usesimplec, coarsesimplesweeps, coarsesimplerelax, coarseusesimplec, relsmootype, relsmooiter, relsmoodamp, schursmootype, schursmoofill, procs, jobfile):
83
84 # generate filenames
85 filename_out = seriesname + simname + "_" + str(simplesweeps) + "Simple" + str(simplerelax) + "_" + str(coarsesimplesweeps) + str(usesimplec) + "Simple" + str(coarsesimplerelax) + str(coarseusesimplec) + "_" + str(relsmootype) + str(relsmooiter) + str(relsmoodamp) + "_" + str(schursmootype) + str(schursmoofill) + "_maxL" + str(maxLevel) + "_maxCoarseSize" + str(maxCoarseSize) + "_" + str(procs) + "proc"
86
87
88 if (relsmootype == "SGS"):
89 relsmootype = "Symmetric Gauss-Seidel"
90 elif (relsmootype == "GS"):
91 relsmootype = "Gauss-Seidel"
92 elif (relsmootype == "JAC"):
93 relsmootype = "Jacobi"
94
95
96 # generate filenames
97 filename_log = filename_out + ".log"
98 filename_xml = filename_out + ".xml"
99
100
101 # generate XML file for pre_exodus
102 if os.path.isfile(filename_xml):
103 os.remove(filename_xml)
104 o = open(filename_xml,"a")
105 for line in open(tmplfile):
106
107 line = line.replace("$MAXLEVEL", str(maxLevel))
108 line = line.replace("$MAXCOARSESIZE", str(maxCoarseSize))
109
110 line = line.replace("$RELSMOOTYPE", str(relsmootype))
111 line = line.replace("$RELSMOOITER", str(relsmooiter))
112 line = line.replace("$RELSMOODAMP", str(relsmoodamp))
113
114 line = line.replace("$SCHURSMOOTYPE", str(schursmootype))
115 line = line.replace("$SCHURSMOOFILL", str(schursmoofill))
116
117
118 line = line.replace("$COARSESIMPLESWEEPS", str(coarsesimplesweeps))
119 line = line.replace("$COARSESIMPLERELAX", str(coarsesimplerelax))
120 line = line.replace("$COARSEUSESIMPLEC", str(coarseusesimplec))
121
122 line = line.replace("$SIMPLESWEEPS", str(simplesweeps))
123 line = line.replace("$SIMPLERELAX", str(simplesweeps))
124 line = line.replace("$USESIMPLEC", str(usesimplec))
125 o.write(line)
126 o.close()
127
128 jobfile.write("mpirun -np " + str(procs) + " ./MueLu_CradaDriver.exe --xml=" + filename_xml + " --split=1 --thyra=0 --matrixfile=grid_50_50_30/A0.m --rhsfile=grid_50_50_30/b0.m --coordinatesfile=grid_50_50_30/coordinates.m --specialfile=grid_50_50_30/special.m --nspfile= --linAlgebra=Epetra --tol=1e-10 --maxits=150 --output=" + filename_out + " | tee " + filename_out + ".txt\n\n\n")
129
130
131 if __name__ == "__main__":
132 sys.exit(main())