-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgather_test.py
41 lines (29 loc) · 1.14 KB
/
gather_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import sys, os
from mpi4py import MPI
import numpy as np
parent_path, current_dir = os.path.split(os.path.abspath('.'))
##################### (just to handle my particular path structure) #####################
# Crawl up to the repos folder
while current_dir not in ['repos', 'nse']:
print('In loop!')
parent_path, current_dir = os.path.split(parent_path)
p = os.path.join(parent_path, current_dir)
# Add uoicorr and pyuoi to the path
if '%s/uoicor' % p not in sys.path:
sys.path.append('%s/uoicorr' % p)
if '%s/PyUoI' % p not in sys.path:
sys.path.append('%s/PyUoI' % p)
from pyuoi.mpi_utils import Gatherv_rows
########################################################################################
# Initialize comm object
comm = MPI.COMM_WORLD
rank = comm.rank
numproc = comm.Get_size()
# Generate some random data
data = np.random.random_integers(0, 100, size = (np.random.randint(1, 10), 1000))
#data = np.random.random_integers(0, 100, size = (10, 1000))
print('Rank %d has size (%d, %d)' % (rank, data.shape[0], data.shape[1]))
print('Starting gather')
# Gather data
data = Gatherv_rows(data, comm, root = 0)
print('Data gathered!')