basic allreduce lib ready
This commit is contained in:
23
guide/basic.py
Executable file
23
guide/basic.py
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/python
|
||||
"""
|
||||
demo python script of rabit
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import numpy as np
|
||||
# add path to wrapper
|
||||
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: a=%s' % (rank, str(a))
|
||||
rabit.finalize()
|
||||
|
||||
22
guide/broadcast.py
Executable file
22
guide/broadcast.py
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/python
|
||||
"""
|
||||
demo python script of rabit
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
# add path to wrapper
|
||||
sys.path.append(os.path.dirname(__file__) + '/../wrapper')
|
||||
import rabit
|
||||
|
||||
rabit.init()
|
||||
n = 3
|
||||
rank = rabit.get_rank()
|
||||
s = None
|
||||
if rank == 0:
|
||||
s = {'hello world':100, 2:3}
|
||||
print '@node[%d] before-broadcast: s=\"%s\"' % (rank, str(s))
|
||||
s = rabit.broadcast(s, 0)
|
||||
|
||||
print '@node[%d] after-broadcast: s=\"%s\"' % (rank, str(s))
|
||||
rabit.finalize()
|
||||
|
||||
Reference in New Issue
Block a user