# Understanding the ray.get() method

**URL:** <https://discuss.ray.io/t/understanding-the-ray-get-method/16082>\
**Category:** Ray Core\
**Created:** [October 24, 2024, 1:34pm UTC](https://discuss.ray.io/t/understanding-the-ray-get-method/16082 "2024-10-24T13:34:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kitsearle](https://avatars.discourse-cdn.com/v4/letter/k/f4b2a3/32.png) [@kitsearle](https://discuss.ray.io/u/kitsearle)\
**Post date:** [October 24, 2024, 1:34pm UTC](https://discuss.ray.io/t/understanding-the-ray-get-method/16082/1 "2024-10-24T13:34:00Z")

</div>

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](https://stackoverflow.com/questions/64321153/how-to-use-ray-parallelism-within-a-class-in-python) that can help.

If I run the code below I get:

```auto
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:

```auto
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.

```auto
@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)

```

---

<div class="post-metadata">

**Author:** ![sangcho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sangcho/32/425_2.png) [@sangcho](https://discuss.ray.io/u/sangcho)\
**Post date:** [October 24, 2024, 6:37pm UTC](https://discuss.ray.io/t/understanding-the-ray-get-method/16082/2 "2024-10-24T18:37:50Z")

</div>

prime.SumPrime.remote(num) only launches tasks and return future immediately. ray.get actually waits until computation is finished

---

<div class="post-metadata">

**Author:** ![ruisearch42](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/ruisearch42/32/6012_2.png) [@ruisearch42](https://discuss.ray.io/u/ruisearch42)\
**Post date:** [October 24, 2024, 7:08pm UTC](https://discuss.ray.io/t/understanding-the-ray-get-method/16082/3 "2024-10-24T19:08:54Z")

</div>

> 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

Also @ray.remote just runs your method on a remote process, it does not speed up execution by itself. If you use @ray.remote to distribute a number of methods to different processes, you will get speed up due to parallelism.
