Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
main.py
Go to the documentation of this file.
1 # Andrew Gloster
2 # Summer 2016
3 # Python Version of Communication Model Implementation
4 # Main Program
5 
6 #------------------------------------
7 # Import relevant modules
8 #------------------------------------
9 
10 import os
11 from subprocess import Popen, PIPE
12 
13 #------------------------------------
14 # Import relevant main functions
15 #------------------------------------
16 
17 from functions_main import PBS_Job_Parse
18 from functions_main import PBS_Benchmark_Parse
19 from functions_main import Parse_Benchmark
20 from functions_main import Parse_Nektar_Output
21 from functions_main import Parse_Nektar_CG_Benchmark_Output
22 from functions_main import Find_Nektar_Elements
23 from functions_main import Find_Nektar_Files
24 from functions_main import Find_Hardware
25 from functions_main import Find_Conditions
26 from functions_main import Filename_Generate
27 
28 #------------------------------------
29 # Import function for serial computation
30 #------------------------------------
31 
32 from serial import Run_Serial_Fit
33 
34 #------------------------------------
35 # Import function for parallel model
36 #------------------------------------
37 
38 from parallel import Run_Parallel_Model
39 from parallel import Run_Parallel_Comparison
40 
41 #------------------------------------
42 # Import relevant error checking functions
43 #------------------------------------
44 
45 from error_main import Primary_Error_Out
46 from error_main import Error_Check_Proc_Input
47 from error_main import Error_Check_Comm_Input
48 
49 #------------------------------------
50 # Main Program Begin
51 #------------------------------------
52 
53 #------------------------------------
54 # User Model Choices
55 #------------------------------------
56 
57 # Input the mesh file name, stored in Input/Mesh/
58 Mesh = 'cyl-small.xml'
59 
60 # Maximum value of N_Z
61 Max_N_Z = 'output_72.txt'
62 
63 # Input the conditions file name stored in Input/Conditions/
64 Conditions_File = 'conditions_80.xml'
65 
66 # Choose the numerical scheme you're using, IterativeFull or IterativeStaticCond
67 Scheme = 'IterativeStaticCond'
68 
69 # Select the values of N_Z you wish to calibrate the model with
70 Consider_Modes = [80]
71 
72 # Choose number of constant to fit to the serial model model, 1 or 2
73 Num_Constants = 2
74 
75 # Do you wish to run the clearcomparison between the calibrated serial model prediction and the collected data.
76 # Set to false if your serial data was collected to a different core than the one you are calibrating for.
77 Compare_Serial = False
78 
79 # Do you wish to run the parallel portion of the model
80 Parallel = True
81 
82 # Choose the Parallelisation method for the model to adopt, Modal, Elemental, Hybrid_Socket or Hybrid_Node
83 Parallelisation = 'Hybrid_Socket'
84 
85 # Do you wish to run the comparison between the full model prediction and the collected data
86 Compare_Parallel = True
87 
88 # Input number of nodes you are using (Can replace this with PBS_Job_Parse)
89 Num_Node = 1
90 
91 #------------------------------------
92 # Generate Input Filename Locations
93 #------------------------------------
94 
95 (Mesh_File, Input_Nektar_Max, Conditions, Loc_Serial_Timing_Files, Loc_Parallel_Timing_Files, Benchmark_PBS, MPI_Benchmark, Node_Map) = Filename_Generate(Mesh, Max_N_Z, Conditions_File)
96 
97 #------------------------------------
98 # Generate Output Locations
99 #------------------------------------
100 
101 output_path = 'Output/Figures/'
102 if os.path.exists(output_path):
103  cmd_string_clear = 'rm -r Output/Figures/ \n'
104  process = Popen([cmd_string_clear],shell=True, stdout=PIPE, stdin=PIPE)
105  process.wait()
106  os.mkdir(output_path)
107 
108 if not os.path.exists(output_path):
109  os.mkdir(output_path)
110 
111 #------------------------------------
112 # Parse Max Modes Nektar Input
113 #------------------------------------
114 
115 (Pressure, Velocity_1, Velocity_2, Velocity_3) = Parse_Nektar_CG_Benchmark_Output(Input_Nektar_Max)
116 
117 #------------------------------------
118 # Pharse Serial Nektar Inputs
119 #------------------------------------
120 
121 Nektar_Serial_Elements = Find_Nektar_Elements(Mesh_File)
122 
123 (Nektar_Modes, Timing_Files) = Find_Nektar_Files(Loc_Serial_Timing_Files)
124 
125 Timings = {}
126 for i in range(0, len(Timing_Files)):
127  Timings[str(Nektar_Modes[i])] = Parse_Nektar_Output(Loc_Serial_Timing_Files + Timing_Files[i])
128 
129 #------------------------------------
130 # Pharse Condition Inputs
131 #------------------------------------
132 
133 (Num_Modes, P, Error, Message) = Find_Conditions(Conditions)
134 
135 # Print error to file if needed
136 if (Error is False):
137  Primary_Error_Out(Message)
138  quit()
139 
140 #------------------------------------
141 # Fit Serial Model
142 #------------------------------------
143 
144 # Fit the model to the supplied data and return the FLOPs
145 Fit = Run_Serial_Fit(Compare_Serial, Consider_Modes, Num_Constants, P, Nektar_Serial_Elements, Nektar_Modes, Timings, Pressure, Velocity_1, Velocity_2, Velocity_3, 'IterativeStaticCond')
146 
147 # Stop here if we do not wish to run the parallel model.
148 if Parallel is False:
149  quit()
150 
151 #------------------------------------
152 # Pharse Hardware Inputs
153 #------------------------------------
154 
155 (Num_Core_Per_Node, Num_Core_Per_Socket, Num_Sock_Per_Node, Error, Message) = Find_Hardware(Node_Map)
156 
157 # Print error to file if needed
158 if (Error is False):
159  Primary_Error_Out(Message)
160  quit()
161 
162 # Calculate PROC_TOT using outputs of the PBS_Pharse and Find_Hardware functions
163 PROC_TOT = Num_Core_Per_Node * Num_Node
164 
165 # #------------------------------------
166 # # Pharse Communication Inputs
167 # #------------------------------------
168 
169 (PROC_BENCHMARK, Error, Message) = PBS_Benchmark_Parse(Benchmark_PBS)
170 
171 # Print error to file if needed
172 if (Error is False):
173  Primary_Error_Out(Message)
174  quit()
175 
176 (BW_Node_To_Node, LAT_Node_To_Node, BW_Socket_To_Socket, LAT_Socket_To_Socket, BW_Core_To_Core, LAT_Core_To_Core) = Parse_Benchmark(MPI_Benchmark, PROC_BENCHMARK, Num_Core_Per_Socket, Num_Sock_Per_Node)
177 
178 print(BW_Node_To_Node, LAT_Node_To_Node, BW_Socket_To_Socket, LAT_Socket_To_Socket, BW_Core_To_Core, LAT_Core_To_Core)
179 
180 #------------------------------------
181 # Error check all inputs
182 #------------------------------------
183 
184 # Error check the inputs
185 (Error, Message) = Error_Check_Proc_Input(PROC_TOT, Num_Core_Per_Socket, Num_Sock_Per_Node, Num_Modes)
186 
187 # Print error to file if needed
188 if (Error is False):
189  Primary_Error_Out(Message)
190  quit()
191 
192 (Error, Message) = Error_Check_Comm_Input(BW_Node_To_Node, LAT_Node_To_Node, BW_Socket_To_Socket, LAT_Socket_To_Socket, BW_Core_To_Core, LAT_Core_To_Core)
193 
194 # Print error to file if needed
195 if (Error is False):
196  Primary_Error_Out(Message)
197  quit()
198 
199 (PROC_Z, PROC_XY, Total) = Run_Parallel_Model(Parallelisation, Scheme, Mesh_File, Num_Modes, P, Num_Constants, Fit, BW_Node_To_Node, LAT_Node_To_Node, BW_Socket_To_Socket,
200  LAT_Socket_To_Socket, BW_Core_To_Core, LAT_Core_To_Core, Num_Core_Per_Socket, Num_Sock_Per_Node, PROC_TOT, Pressure, Velocity_1, Velocity_2, Velocity_3)
201 
202 if Compare_Parallel is False:
203  quit()
204 
205 Run_Parallel_Comparison(Loc_Parallel_Timing_Files, Parallelisation, PROC_Z, PROC_XY, Total)
206 
207 #------------------------------------
208 # Main Program End
209 #------------------------------------
210 
211 
212 
def Parse_Nektar_CG_Benchmark_Output
def Primary_Error_Out
Definition: error_main.py:21
def quit
def del(self): """ Tell our RVP process to quit.
Definition: validator.py:288
def Error_Check_Comm_Input
Definition: error_main.py:122
def Parse_Nektar_Output
def Run_Serial_Fit
Definition: serial.py:156
def Run_Parallel_Comparison
Definition: parallel.py:151
def Run_Parallel_Model
Definition: parallel.py:35
def Error_Check_Proc_Input
Definition: error_main.py:42