Merge commit 'd87691ec603db325d5b1c5db1186295a748df7cc' as 'subtree/rabit'
This commit is contained in:
25
subtree/rabit/guide/basic.py
Executable file
25
subtree/rabit/guide/basic.py
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/python
|
||||
"""
|
||||
demo python script of rabit
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import numpy as np
|
||||
# import rabit, the tracker script will setup the lib path correctly
|
||||
# for normal run without tracker script, add following line
|
||||
# sys.path.append(os.path.dirname(__file__) + '/../wrapper')
|
||||
import rabit
|
||||
|
||||
rabit.init()
|
||||
n = 3
|
||||
rank = rabit.get_rank()
|
||||
a = np.zeros(n)
|
||||
for i in xrange(n):
|
||||
a[i] = rank + i
|
||||
|
||||
print '@node[%d] before-allreduce: a=%s' % (rank, str(a))
|
||||
a = rabit.allreduce(a, rabit.MAX)
|
||||
print '@node[%d] after-allreduce-max: a=%s' % (rank, str(a))
|
||||
a = rabit.allreduce(a, rabit.SUM)
|
||||
print '@node[%d] after-allreduce-sum: a=%s' % (rank, str(a))
|
||||
rabit.finalize()
|
||||
Reference in New Issue
Block a user