Hi everyone, I am fairly new to Ray and I am struggling to understand what the ray.get() function actually does. I found a small example online here that can help.
If I run the code below I get:
duration = 15.932732820510864
sum_prime = 9914236193
If I change the result = ray.get(prime.SumPrime.remote(num))
to result = prime.SumPrime.remote(num)
I get:
duration = 0.0009586811065673828
sum_prime = ObjectRef(76385d6aec5a2d681682b671b29cf0241608aada0100000001000000)
I am unsure as to why it takes so long when I us the ray.get() method. I use this in my code and so I am seeing no improvement from using ray. I guess I am using it incorrectly?
I would appreciate any advise.
@ray.remote
class Prime:
# Constructor
def __init__(self,number) :
self.num = number
def SumPrime(self,num) :
tot = 0
for i in range(3,num):
c = 0
for j in range(2, int(i**0.5)+1):
if i%j == 0:
c = c + 1
if c == 0:
tot = tot + i
return tot
num = 500000
prime = Prime.remote(num)
start = time.time()
result = ray.get(prime.SumPrime.remote(num))
print("duration =", time.time() - start, "\nsum_prime = ",result)