Пример #1
0
def bench_function(f):
    samples = util.get_sample_count()

    start_time = time.time()

    pi = f(samples)

    end_time = time.time()

    util.output(samples, pi, start_time, end_time)
        x = random.random()
        y = random.random()
        if (x * x) + (y * y) < 1:
            inside += 1
    mypi = (4.0 * inside) / nsamples

    # capital Reduce works with C/NumPy compatible data
    # -types and avoids the need to serialize data at
    # transmission and receipt. Lowercase reduce would
    # work on Python objects.
    #
    # The value of mypi will be summed into pi on rank 0
    comm.Reduce(np.array(mypi), pi, op=MPI.SUM, root=0)
    return pi / mpisize


if __name__ == '__main__':
    samples = util.get_sample_count()

    comm = MPI.COMM_WORLD
    rank = comm.Get_rank()

    start_time = MPI.Wtime()

    pi = calcpi(samples)

    end_time = MPI.Wtime()

    if rank == 0:
        util.output(samples, pi, start_time, end_time)