forked from caocscar/populationdotmap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdotmap_mpi_reduce.py
More file actions
63 lines (54 loc) · 1.58 KB
/
dotmap_mpi_reduce.py
File metadata and controls
63 lines (54 loc) · 1.58 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 10 16:22:34 2015
@author: Alex Cao, University of Michigan
"""
from mpi4py import MPI
import pandas as pd
import time
import createtile as tile
import numpy as np
#%% Phase 1: Generate People
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
# timing
t0 = time.time()
# specify zoom level limits
lowerzoom = 3
upperzoom = 13
#%% Phase 2: Generate Tile
# convert list to dataframe
data = pd.read_csv("Vermont_pop.csv", header=0, usecols=[1,2,3])
t2 = time.time()
if rank == 0:
print("Read csv {:.1f}s".format(t2-t0))
# create a range of descending zoomlevels
zoomlevels = range(upperzoom,lowerzoom,-1)
# mpi4py requires that we pass numpy objects
N = np.zeros(1)
# loop through zoom levels
for j in range(len(zoomlevels)):
level = zoomlevels[j]
# grab correct quadkey string based on zoom level
data.loc[:,'quadkey'] = data['quadkey'].map(lambda x: x[0:level])
# group dataframe by quadkey
groups = data.groupby('quadkey')
# get list of unique quadkeys and length
quadtree = data['quadkey'].unique()
n = len(quadtree)
count = 0
# loop through quadkeys
for i in range(rank, n, comm.size):
quadkey = quadtree[i]
# generate tile function
tile.generate_tile(groups.get_group(quadkey), quadkey, level)
count += 1
# keep count of tiles
N += count
# mpi4py requires that we pass numpy objects
total = np.zeros(1)
# reduce call
comm.Reduce(N, total, op=MPI.SUM, root=0)
t3 = time.time()
if rank == 0:
print("Creating {:.0f} png files took {:.1f}s".format(total[0],t3-t2))