Exemplo n.º 1
0
comm = Teuchos.DefaultComm.getComm()
rank = comm.getRank()
nprocs = comm.getSize()

file_dir = os.path.dirname(__file__)

filename = 'input_fo_gis_analysis_beta_smbT.yaml'

parameter_index = 0
response_index = 0

timers = Utils.createTimers(["PyAlbany: Create Albany Problem", 
                        "PyAlbany: Read multivector directions",
                        "PyAlbany: Set directions",
                        "PyAlbany: Perform Solve",
                        "PyAlbany: Get Reduced Hessian",
                        "PyAlbany: Write Reduced Hessian",
                        "PyAlbany: Total"])

timers[6].start()
timers[0].start()
problem = Utils.createAlbanyProblem(filename)
timers[0].stop()

timers[1].start()
n_directions=4
parameter_map = problem.getParameterMap(0)
directions = Utils.loadMVector('random_directions', n_directions, parameter_map, distributedFile = False, useBinary = True)
timers[1].stop()
Exemplo n.º 2
0
def main(parallelEnv):
    comm = MPI.COMM_WORLD
    nMaxProcs = comm.Get_size()
    myGlobalRank = comm.rank

    timerNames = [
        "PyAlbany: Create Albany Problem", "PyAlbany: Set directions",
        "PyAlbany: Perform Solve", "PyAlbany: Total"
    ]

    nTimers = len(timerNames)

    # number of times that the test is repeated for a fixed
    # number of MPI processes
    N = 10

    timers_sec = np.zeros((nMaxProcs, nTimers, N))
    mean_timers_sec = np.zeros((nMaxProcs, nTimers))

    speedUp = np.zeros((nMaxProcs, nTimers))

    for nProcs in range(1, nMaxProcs + 1):
        newGroup = comm.group.Incl(np.arange(0, nProcs))
        newComm = comm.Create_group(newGroup)

        if myGlobalRank < nProcs:
            parallelEnv.comm = Teuchos.MpiComm(newComm)

            for i_test in range(0, N):
                timers = Utils.createTimers(timerNames)
                timers[3].start()
                timers[0].start()

                filename = 'input_conductivity_dist_paramT.yaml'
                problem = Utils.createAlbanyProblem(filename, parallelEnv)
                timers[0].stop()

                timers[1].start()
                n_directions = 4
                parameter_map = problem.getParameterMap(0)
                directions = Tpetra.MultiVector(parameter_map,
                                                n_directions,
                                                dtype="d")

                directions[0, :] = 1.
                directions[1, :] = -1.
                directions[2, :] = 3.
                directions[3, :] = -3.

                problem.setDirections(0, directions)
                timers[1].stop()

                timers[2].start()
                problem.performSolve()
                timers[2].stop()
                timers[3].stop()

                if myGlobalRank == 0:
                    for j in range(0, nTimers):
                        timers_sec[nProcs - 1, j,
                                   i_test] = timers[j].totalElapsedTime()

    if myGlobalRank == 0:
        for i in range(0, nMaxProcs):
            for j in range(0, nTimers):
                mean_timers_sec[i, j] = np.mean(timers_sec[i, j, :])
            speedUp[i, :] = mean_timers_sec[0, :] / (mean_timers_sec[i, :])

        print('timers')
        print(mean_timers_sec)

        print('speed up')
        print(speedUp)
        if printPlot:
            fig = plt.figure(figsize=(10, 6))
            plt.plot(np.arange(1, nMaxProcs + 1), np.arange(1, nMaxProcs + 1),
                     '--')
            for j in range(0, nTimers):
                plt.plot(np.arange(1, nMaxProcs + 1),
                         speedUp[:, j],
                         'o-',
                         label=timerNames[j])
            plt.ylabel('speed up')
            plt.xlabel('number of MPI processes')
            plt.grid(True)
            plt.legend()
            plt.savefig('speedup.jpeg', dpi=800)
            plt.close()
Exemplo n.º 3
0
def main(parallelEnv):
    # This example illustrates how PyAlbany can be used to compute
    # reduced Hessian-vector products w.r.t to the basal friction.

    comm = parallelEnv.comm
    rank = comm.getRank()
    nprocs = comm.getSize()

    file_dir = os.path.dirname(__file__)

    filename = 'input_fo_gis_analysis_beta_smbT.yaml'

    parameter_index = 0
    response_index = 0

    timers = Utils.createTimers([
        "PyAlbany: Create Albany Problem",
        "PyAlbany: Read multivector directions", "PyAlbany: Set directions",
        "PyAlbany: Perform Solve", "PyAlbany: Get Reduced Hessian",
        "PyAlbany: Write Reduced Hessian", "PyAlbany: Total"
    ])

    timers[6].start()
    timers[0].start()
    problem = Utils.createAlbanyProblem(filename, parallelEnv)
    timers[0].stop()

    timers[1].start()
    n_directions = 4
    parameter_map = problem.getParameterMap(0)
    directions = Utils.loadMVector('random_directions',
                                   n_directions,
                                   parameter_map,
                                   distributedFile=False,
                                   useBinary=True)
    timers[1].stop()

    timers[2].start()
    problem.setDirections(parameter_index, directions)
    timers[2].stop()

    timers[3].start()
    problem.performSolve()
    timers[3].stop()

    timers[4].start()
    hessian = problem.getReducedHessian(response_index, parameter_index)
    timers[4].stop()

    timers[5].start()
    Utils.writeMVector("hessian_nprocs_" + str(nprocs),
                       hessian,
                       distributedFile=True,
                       useBinary=False)
    Utils.writeMVector("hessian_all_nprocs_" + str(nprocs),
                       hessian,
                       distributedFile=False,
                       useBinary=False)
    timers[5].stop()

    print(hessian[0, 0])
    print(hessian[1, 0])
    print(hessian[2, 0])
    print(hessian[3, 0])

    timers[6].stop()

    Utils.printTimers(timers, "timers_nprocs_" + str(nprocs) + ".txt")