-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathopenmm_mpi_run.py
115 lines (84 loc) · 2.65 KB
/
openmm_mpi_run.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
'''
date: 10/26/2019
taken from
sources: https://gist.github.com/fspaolo/51eaf5a20d6d418bd4d0
'''
from impress_md import interface_functions
import os
import sys
import numpy as np
from mpi4py import MPI
from queue import Queue
WORKTAG = 1
DIETAG = 0
class Work(object):
def __init__(self):
# importat: sort by file size in decreasing order!
q = Queue()
with open('file_list.txt', 'r') as f:
paths_to_run_mmgbsa = map(lambda x: x.strip(), f.readlines())
for f in paths_to_run_mmgbsa:
q.put(f)
self.work = q
def get_next(self):
if self.work.empty():
return None
return self.work.get()
def do_work(work):
print("running", work)
interface_functions.RunMinimization(work, work, True)
print("done with ", work)
# def process_result(result):
# pass
def master(comm):
num_procs = comm.Get_size()
status = MPI.Status()
# generate work queue
wq = Work()
# Seed the slaves, send one unit of work to each slave (rank)
for rank in range(1, num_procs):
work = wq.get_next()
comm.send(work, dest=rank, tag=WORKTAG)
# Loop over getting new work requests until there is no more work to be done
while True:
work = wq.get_next()
if not work: break
# Receive results from a slave
result = comm.recv(source=MPI.ANY_SOURCE, tag=MPI.ANY_TAG, status=status)
# process_result(result)
# Send the slave a new work unit
comm.send(work, dest=status.Get_source(), tag=WORKTAG)
# No more work to be done, receive all outstanding results from slaves
for rank in range(1, num_procs):
result = comm.recv(source=MPI.ANY_SOURCE, tag=MPI.ANY_TAG, status=status)
# process_result(result)
# Tell all the slaves to exit by sending an empty message with DIETAG
for rank in range(1, num_procs):
comm.send(0, dest=rank, tag=DIETAG)
def slave(comm):
my_rank = comm.Get_rank()
status = MPI.Status()
while True:
# Receive a message from the master
work = comm.recv(source=0, tag=MPI.ANY_TAG, status=status)
# Check the tag of the received message
if status.Get_tag() == DIETAG: break
# Do the work
do_work(work)
# Send the result back
comm.send(1, dest=0, tag=0)
def main():
comm = MPI.COMM_WORLD
my_rank = comm.Get_rank()
my_name = MPI.Get_processor_name()
# comm.Barrier()
# start = MPI.Wtime()
if my_rank == 0:
master(comm)
else:
slave(comm)
# comm.Barrier()
# end = MPI.Wtime()
# print 'time:', end - start
if __name__ == '__main__':
main()