Fixed print statements and xrange to be compatibile with Python 2 and 3. (#55)
This commit is contained in:
committed by
Tianqi Chen
parent
0759d5ed2b
commit
440e81db0b
@@ -2,6 +2,8 @@
|
||||
"""
|
||||
demo python script of rabit
|
||||
"""
|
||||
from __future__ import print_function
|
||||
from builtins import range
|
||||
import os
|
||||
import sys
|
||||
import numpy as np
|
||||
@@ -14,12 +16,12 @@ rabit.init()
|
||||
n = 3
|
||||
rank = rabit.get_rank()
|
||||
a = np.zeros(n)
|
||||
for i in xrange(n):
|
||||
for i in range(n):
|
||||
a[i] = rank + i
|
||||
|
||||
print '@node[%d] before-allreduce: a=%s' % (rank, str(a))
|
||||
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))
|
||||
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))
|
||||
print('@node[%d] after-allreduce-sum: a=%s' % (rank, str(a)))
|
||||
rabit.finalize()
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"""
|
||||
demo python script of rabit
|
||||
"""
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import sys
|
||||
# add path to wrapper
|
||||
@@ -15,8 +16,8 @@ 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))
|
||||
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))
|
||||
print('@node[%d] after-broadcast: s=\"%s\"' % (rank, str(s)))
|
||||
rabit.finalize()
|
||||
|
||||
Reference in New Issue
Block a user