def global_iterating(arr, iters=10000): size = arr.globalsize time = measure_time() for _ in range(iters): for index in range(size): arr[index] time = measure_time() - time return time/iters
def local_setting(arr, iters=10000, comm=MPI.COMM_WORLD): comm.Barrier() time = measure_time() for _ in range(iters): arr.local[0] = 1.0 time = measure_time() - time comm.reduce(time, op=MPI.MAX, root=0) return time / iters
def global_iterating(arr, iters=10000, comm=MPI.COMM_WORLD): size = arr.globalsize comm.Barrier() time = measure_time() for _ in range(iters): for index in range(size): arr[index] time = measure_time() - time comm.reduce(time, op=MPI.MAX, root=0) return time/iters
def local_setting(arr, iters=10000): time = measure_time() for _ in range(iters): arr.local[0] = 1.0 time = measure_time() - time return time / iters
def local_slicing(arr, iters=10000): time = measure_time() for _ in range(iters): arr.local[::2] time = measure_time() - time return time / iters
import numpy as np import scipy.cluster.vq as cluster from operations import gen_blobs, measure_time if __name__ == '__main__': t_time = measure_time() print("Type,Obs,Feats,Clusters,Time") for obs_power in range(4, 11): num_obs = 2**obs_power for feats_power in range(1, 11): for clust_power in range(1, obs_power): features = 2**feats_power k = 2**clust_power seed = np.zeros((k, features)) observations, labels = gen_blobs(num_obs, features, k) for _ in range(5): time = measure_time() centroids, labels = cluster.kmeans2(observations, k, minit='points') time = measure_time() - time print("scipy,%d,%d,%d,%.9f" % (num_obs, features, k, time)) total_time = measure_time() - t_time print(total_time)
from mpi4py import MPI import mpids.MPInumpy as mpi_np import mpids.MPIscipy.cluster as mpi_cluster from operations import gen_blobs, measure_time if __name__ == '__main__': comm = MPI.COMM_WORLD rank = comm.Get_rank() n_procs = comm.Get_size() runs = int(sys.argv[1]) obs_power = int(sys.argv[2]) local_size = 2**obs_power num_obs = n_procs * local_size k = 2 features = 2 observations, labels = gen_blobs(num_obs, features, k) mpi_obs = mpi_np.array(observations, dist='b', dtype=np.float64) for _ in range(runs): comm.Barrier() time = measure_time() centroids, labels = mpi_cluster.kmeans(mpi_obs, k) time = measure_time() - time comm.reduce(time, op=MPI.MAX, root=0) if rank == 0: print("mpi_scipy,%d,%d,%d,%d,%.9f" % (n_procs, local_size, features, k, time)) del centroids, labels