11from subprocess 
import Popen, PIPE
 
   24    Mesh_File = 
'Input/Mesh/' + Mesh
 
   27    Input_Nektar_Max = 
'Input/Serial_Input/' + Max_N_Z
 
   30    Conditions = 
'Input/Conditions/' + Conditions_File
 
   33    Loc_Serial_Timing_Files = 
'Input/Serial_Input/' 
   36    Loc_Parallel_Timing_Files = 
'Input/Parallel_Input/' 
   39    Benchmark_PBS = 
'Input/Benchmark/Benchmark.pbs' 
   40    MPI_Benchmark = 
'Input/Benchmark/Benchmark.txt' 
   41    Node_Map = 
'Input/Benchmark/node.xml' 
   43    return(Mesh_File, Input_Nektar_Max, Conditions, Loc_Serial_Timing_Files, Loc_Parallel_Timing_Files, Benchmark_PBS, MPI_Benchmark, Node_Map)
 
   53    f = open(
'Input/' + Input_Filename, 
'r')
 
   62        for i 
in range(0, len(a)):
 
   63            b = a[i].split(
':', 2)
 
   64            for j 
in range(0, len(b)):
 
   65                c = b[j].split(
'=', 1)
 
   66                if (c[0] == 
'select'):
 
   72                        Message.append(
'Unable to find number of nodes from ' + Input_Filename)
 
   78    return(Num_Node, Error, Message)
 
   88    output_path = 
'Temporary_Files' 
   89    if os.path.exists(output_path):
 
   90        cmd_string_clear = 
'rm -r Temporary_Files/ \n' 
   91        process = Popen([cmd_string_clear],shell=
True, stdout=PIPE, stdin=PIPE)
 
   95    if not os.path.exists(output_path):
 
   99    cmd_string_uncompress = 
'Nekmesh ' + Input_Filename + 
' Temporary_Files/Nektar_Serial_Mesh.xml:xml:uncompress' + 
" \n" 
  102    process = Popen([cmd_string_uncompress],shell=
True, stdout=PIPE, stdin=PIPE)
 
  106    f = open(
'Temporary_Files/Nektar_Serial_Mesh.xml', 
"r")
 
  116    return(element_count)
 
  126    current_directory = os.getcwd()
 
  128    directory = current_directory + 
'/' + Input_Filename
 
  134    for root, dirs, files 
in os.walk(directory):
 
  136            if file.endswith(
".txt"):
 
  137                Timing_Files.append(os.path.join(file))
 
  142    for i 
in range(0, len(Timing_Files)):
 
  143        a = Timing_Files[i].split(
'_', 1)
 
  144        b = a[1].split(
'.txt', 1)
 
  145        Nektar_Modes.append(int(b[0])) 
 
  148    (Nektar_Modes, Timing_Files) = zip(*sorted(zip(Nektar_Modes, Timing_Files)))
 
  151    return(Nektar_Modes, Timing_Files)
 
  161    f = open(Input_Filename, 
"r")
 
  169        for i 
in range(0, len(a)):
 
  171                b = a[i + 2].split(
's', 1)
 
  172                times.append(float(b[0]))
 
  189    f = open(Input_Filename, 
"r")
 
  194        for i 
in range(0, len(a)):
 
  197            if (a[i] == 
'Pressure'):
 
  205            if (a[i] == 
'Velocity'):
 
  209            if (a[i] == 
'Plane'):
 
  210                plane = int(a[i + 1]) + 1
 
  217                    if plane 
in Pressure.keys():
 
  218                        Pressure[plane].append(int(a[i + 4]))
 
  221                        Pressure[plane] = [int(a[i + 4])]
 
  224                    if plane 
in Velocity_1.keys():
 
  225                        Velocity_1[plane].append(int(a[i + 4]))
 
  229                        Velocity_1[plane] = [int(a[i + 4])]
 
  232                    if plane 
in Velocity_2.keys():
 
  233                        Velocity_2[plane].append(int(a[i + 4]))
 
  237                        Velocity_2[plane] = [int(a[i + 4])]
 
  240                    if plane 
in Velocity_3.keys():
 
  241                        Velocity_3[plane].append(int(a[i + 4]))
 
  244                        Velocity_3[plane] = [int(a[i + 4])]
 
  247    return(Pressure, Velocity_1, Velocity_2, Velocity_3)
 
  257    f = open(Input_Filename, 
'r')
 
  270        for i 
in range(0, len(a)):
 
  271            if (a[i] == 
'type="Core"'):
 
  273            if (a[i] == 
'type="Socket"'):
 
  280    Num_Core_Per_Node = count_cores
 
  283    if(Num_Core_Per_Node == 0):
 
  285        Message.append(
'Unable to find any cores in ' + Input_Filename)
 
  287    if(count_sockets == 0):
 
  289        Message.append(
'Unable to find any sockets in ' + Input_Filename)
 
  292    Num_Core_Per_Socket = Num_Core_Per_Node/count_sockets
 
  293    Num_Sock_Per_Node = count_sockets
 
  296    return(Num_Core_Per_Node, Num_Core_Per_Socket, Num_Sock_Per_Node, Error, Message)
 
  306    f = open(Input_Filename, 
"r")
 
  315        for i 
in range(0, len(a)):
 
  317            if (a[i] == 
'HomModesZ'):
 
  319                    N_Modes = int(a[i + 2])/2
 
  323            b = a[i].split(
'=', 1)
 
  324            for j 
in range(0, len(b)):
 
  325                if(b[j] == 
'NUMMODES'):
 
  326                    c = b[j + 1].split(
'"',2)
 
  336    return(N_Modes, P, Error, Message)
 
  346    f = open(Input_Filename, 
'r')
 
  355        for i 
in range(0, len(a)):
 
  356            b = a[i].split(
':', 2)
 
  357            for j 
in range(0, len(b)):
 
  358                c = b[j].split(
'=', )
 
  359                if (c[0] == 
'select'):
 
  365                        Message.append(
'Unable to find number of nodes from ' + Input_Filename)
 
  366                if (c[0] == 
'ncpus'):
 
  368                        Num_Cores = int(c[1])
 
  372                        Message.append(
'Unable to find number of cores from ' + Input_Filename)
 
  375    PROC_BENCHMARK = Num_Cores * Num_Node
 
  381    return(PROC_BENCHMARK, Error, Message)
 
  388def Parse_Benchmark(Input_Filename, PROC_BENCHMARK, Num_Core_Per_Socket, Num_Sock_Per_Node):
 
  391    Num_Core_Per_Node = Num_Core_Per_Socket * Num_Sock_Per_Node
 
  394    Check = [4, 8, 16, 32]
 
  401    for i 
in range(0, len(Check)):
 
  402        if (Num_Core_Per_Socket % Check[i] != 0):
 
  405        if (Num_Core_Per_Node % Check[i] != 0):
 
  409        if (Check_Node 
is True and Check_Socket 
is True):
 
  410            PROC_PER_GROUP = Check[i]
 
  418    Num_Groups = PROC_BENCHMARK/PROC_PER_GROUP
 
  421    concerned_node_groups = []
 
  422    concerned_socket_groups = []
 
  423    concerned_core_groups = []
 
  436    for i 
in range(0, Num_Groups):
 
  439        for j 
in range(0, PROC_PER_GROUP):
 
  440            Groups[i].append(count)
 
  443        for j 
in range(1, PROC_PER_GROUP - 1):
 
  444            if (Groups[i][j] % Num_Core_Per_Node == 0):
 
  445                concerned_node_groups.append(i)
 
  449            if (Groups[i][j] % Num_Core_Per_Socket == 0 
and Check_Node 
is False):
 
  450                concerned_socket_groups.append(i)
 
  454        if (Check_Node 
is False and Check_Socket 
is False):
 
  455            concerned_core_groups.append(i)
 
  461    f = open(Input_Filename, 
"r")
 
  476        pharsed = line.split()
 
  477        if (pharsed == [
'#', 
'Benchmarking', 
'Multi-Exchange']):
 
  481        if (pharsed == [
'#', 
'(', str(Num_Groups), 
'groups', 
'of', str(PROC_PER_GROUP), 
'processes', 
'each', 
'running', 
'simultaneous', 
')'] 
and Finder_0 
is True):
 
  485        if (pharsed == [
'Group', 
'#bytes', 
'#repetitions', 
't_min[usec]', 
't_max[usec]', 
't_avg[usec]', 
'Mbytes/sec'] 
and Finder_1 
is True):
 
  489        if (Finder_1 
is True and Finder_2 
is True):
 
  492                data.append([[],[],[],[],[],[],[]])
 
  494            if (pharsed == [
'#------------------------------------------------------------------------------------------']):
 
  497            data[count][5].append(float(pharsed[5]))
 
  498            data[count][6].append(float(pharsed[6]))
 
  502    count_lat_socket = 0.0
 
  505    for i 
in range(0, len(concerned_node_groups)):
 
  506        index = concerned_node_groups[i]
 
  507        count_lat_node += data[0][5][index]
 
  509    LAT_Node_To_Node = (count_lat_node/len(concerned_node_groups)) * 1e-06
 
  511    for i 
in range(0, len(concerned_socket_groups)):
 
  512        index = concerned_socket_groups[i]
 
  513        count_lat_socket += data[0][5][index]
 
  514    LAT_Socket_To_Socket = (count_lat_socket/len(concerned_socket_groups)) * 1e-06
 
  517    for i 
in range(0, len(concerned_core_groups)):
 
  518        index = concerned_core_groups[i]
 
  519        count_lat_core += data[0][5][index]
 
  521    LAT_Core_To_Core = (count_lat_core/len(concerned_core_groups)) * 1e-06
 
  525    count_band_node = 0.0
 
  526    count_band_socket = 0.0
 
  527    count_band_core = 0.0
 
  529    for i 
in range(0, len(concerned_node_groups)):
 
  530        index = concerned_node_groups[i]
 
  531        count_band_node += data[count - 3][6][index]
 
  533    BW_Node_To_Node = (count_band_node/len(concerned_node_groups)) * 1e06
 
  535    for i 
in range(0, len(concerned_socket_groups)):
 
  536        index = concerned_socket_groups[i]
 
  537        count_band_socket += data[count - 3][6][index]
 
  539    BW_Socket_To_Socket = (count_band_socket/len(concerned_socket_groups)) * 1e06
 
  542    for i 
in range(0, len(concerned_core_groups)):
 
  543        index = concerned_core_groups[i]
 
  544        count_band_core += data[count - 3][6][index]
 
  546    BW_Core_To_Core = (count_band_core/len(concerned_core_groups)) * 1e06
 
  549    return(BW_Node_To_Node, LAT_Node_To_Node, BW_Socket_To_Socket, LAT_Socket_To_Socket, BW_Core_To_Core, LAT_Core_To_Core)
 
  559    output_path = 
'Temporary_Files' 
  560    if os.path.exists(output_path):
 
  561        cmd_string_clear = 
'rm -r Temporary_Files/ \n' 
  562        process = Popen([cmd_string_clear],shell=
True, stdout=PIPE, stdin=PIPE)
 
  564        os.mkdir(output_path)
 
  566    if not os.path.exists(output_path):
 
  567        os.mkdir(output_path)
 
  570    cmd_string_uncompress = 
'Nekmesh ' + Input_Filename + 
' Temporary_Files/uncompressed_mesh.xml:xml:uncompress' + 
" \n" 
  573    process = Popen([cmd_string_uncompress],shell=
True, stdout=PIPE, stdin=PIPE)
 
  577        f = open(
'Temporary_Files/uncompressed_mesh.xml', 
"r")
 
  586        return([0], [element_count])
 
  589    cmd_string_partition = 
'IncNavierStokesSolver Temporary_Files/uncompressed_mesh.xml --part-only ' + str(PROC_XY) + 
" \n" 
  592    process = Popen([cmd_string_partition],shell=
True, stdout=PIPE, stdin=PIPE)
 
  596    current_directory = os.getcwd()
 
  597    mesh_part_folder = 
'/Temporary_Files/uncompressed_mesh_xml'  
  599    directory = current_directory + mesh_part_folder
 
  605    for root, dirs, files 
in os.walk(directory):
 
  607            if file.endswith(
".xml"):
 
  608                mesh_file.append(os.path.join(file))
 
  617    dictionary_edges = []
 
  620    for i 
in range(0, len(mesh_file)):
 
  623        f = open(
'Temporary_Files/uncompressed_mesh_xml/' + mesh_file[i], 
"r")
 
  627        dictionary_edges.append({})
 
  636                b = a[1].split(
'"', 2)
 
  638                    edges[i].append(int(b[1]))
 
  650        Num_Elements.append(element_count)
 
  653    for i 
in range(0, len(mesh_file)):
 
  654        for j 
in range(0, len(mesh_file)):
 
  656                dictionary_edges[i][str(j)] = 
'Self' 
  658            dictionary_edges[i][str(j)] = 0
 
  663    for i 
in range(0, len(mesh_file)):
 
  664        for k 
in range(0, len(mesh_file)):
 
  667            for j 
in range(0, len(edges[i])):
 
  669                for n 
in range(0, len(edges[k])):
 
  670                    if(a == edges[k][n]):
 
  671                        dictionary_edges[i][str(k)] += 1
 
  676    for i 
in range(0, len(mesh_file)):
 
  677        Num_Element_Msg.append([])
 
  678        for k 
in range(0, len(mesh_file)):
 
  679            Num_Element_Msg[i].append(dictionary_edges[i][str(k)])
 
  682    return (Num_Element_Msg, Num_Elements)
 
  693    PROC_TOT_HALF = PROC_TOT/2
 
  695    for i 
in range(1, PROC_TOT_HALF + 1):
 
  696        if(PROC_TOT % i == 0 
and Num_Modes % i == 0):
 
  698            PROC_XY.append(PROC_TOT/i)
 
  700    if((Num_Modes % PROC_TOT) == 0):
 
  701        PROC_Z.append(PROC_TOT)
 
  704    return (PROC_XY, PROC_Z)
 
def Find_Conditions(Input_Filename)
 
def Find_Hardware(Input_Filename)
 
def Partition(Input_Filename, PROC_XY)
 
def Find_Nektar_Elements(Input_Filename)
 
def Filename_Generate(Mesh, Max_N_Z, Conditions_File)
 
def PBS_Benchmark_Parse(Input_Filename)
 
def PBS_Job_Parse(Input_Filename)
 
def Parse_Nektar_CG_Benchmark_Output(Input_Filename)
 
def Find_Topologies(PROC_TOT, Num_Modes)
 
def Parse_Nektar_Output(Input_Filename)
 
def Parse_Benchmark(Input_Filename, PROC_BENCHMARK, Num_Core_Per_Socket, Num_Sock_Per_Node)
 
def Find_Nektar_Files(Input_Filename)