# stop all thread One thread any, should stop all thread w

**URL:** <https://forums.developer.nvidia.com/t/stop-all-thread-one-thread-any-should-stop-all-thread-w/3390>\
**Category:** CUDA Programming and Performance\
**Created:** [April 17, 2008, 9:38pm UTC](https://forums.developer.nvidia.com/t/stop-all-thread-one-thread-any-should-stop-all-thread-w/3390 "2008-04-17T21:38:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![andreaaz](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@andreaaz](https://forums.developer.nvidia.com/u/andreaaz)\
**Post date:** [April 17, 2008, 9:38pm UTC](https://forums.developer.nvidia.com/t/stop-all-thread-one-thread-any-should-stop-all-thread-w/3390/1 "2008-04-17T21:38:53Z")

</div>

I have n thread and m block: nxm thread. One thread any, should stop all thread when occurs a condition…  
If I use a variable **shared** i can stop all thread of an block, but non all thread…

How can I do this?

---

<div class="post-metadata">

**Author:** ![kristleifur](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/kristleifur/32/12055_2.png) [@kristleifur](https://forums.developer.nvidia.com/u/kristleifur)\
**Post date:** [April 17, 2008, 9:56pm UTC](https://forums.developer.nvidia.com/t/stop-all-thread-one-thread-any-should-stop-all-thread-w/3390/2 "2008-04-17T21:56:14Z")

</div>

> [@](#):
>
> I have n thread and m block: nxm thread. One thread any, should stop all thread when occurs a condition…
> 
> If I use a variable **shared** i can stop all thread of an block, but non all thread…
> 
> How can I do this?
> 
> [snapback]363894[/snapback]

I think you will have to do some sort of an atomic sync/halt operation. This won’t be fast.

Are you looking to save processing power when you’ve done enough computation, or are you interested in preserving the data - i.e., not overprocessing when you’ve reached the goal?

---

<div class="post-metadata">

**Author:** ![andreaaz](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@andreaaz](https://forums.developer.nvidia.com/u/andreaaz)\
**Post date:** [April 17, 2008, 10:03pm UTC](https://forums.developer.nvidia.com/t/stop-all-thread-one-thread-any-should-stop-all-thread-w/3390/3 "2008-04-17T22:03:57Z")

</div>

> [@](#):
>
> I think you will have to do some sort of an atomic sync/halt operation. This won’t be fast.
> 
> Are you looking to save processing power when you’ve done enough computation, or are you interested in preserving the data - i.e., not overprocessing when you’ve reached the goal?
> 
> [snapback]363902[/snapback]

I must recovery password from a zip file, and every thread test one password, when password is correct the thread should stop all thread and should return the password

i am interesting to recovery passord in less time

---

<div class="post-metadata">

**Author:** ![jordyvaneijk](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@jordyvaneijk](https://forums.developer.nvidia.com/u/jordyvaneijk)\
**Post date:** [April 21, 2008, 12:25pm UTC](https://forums.developer.nvidia.com/t/stop-all-thread-one-thread-any-should-stop-all-thread-w/3390/4 "2008-04-21T12:25:02Z")

</div>

> [@](#):
>
> I must recovery password from a zip file, and every thread test one password, when password is correct the thread should stop all thread and should return the password
> 
> i am interesting to recovery passord in less time
> 
> [snapback]363904[/snapback]

This sounds very interesting. I would like to see some timings if this works.

Thanks,

Jordy

---

<div class="post-metadata">

**Author:** ![AndreiB](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/andreib/32/9727_2.png) [@AndreiB](https://forums.developer.nvidia.com/u/AndreiB)\
**Post date:** [April 21, 2008, 1:49pm UTC](https://forums.developer.nvidia.com/t/stop-all-thread-one-thread-any-should-stop-all-thread-w/3390/5 "2008-04-21T13:49:39Z")

</div>

andreaaz  
And why do you need to stop all threads? Just feed GPU with block of passwords, say several millions of them at a time and set some flag in global memory if password is found. Then read this flag from host and if it is set (i.e. password found) just don’t issue next kernel launch. Simple. Don’t make things complex where they are not.

BTW, are you not satisfied with speed of our [ARCHPR](http://elcomsoft.com/archpr.html)? (Not GPU-accelerated yet) :)

---

<div class="post-metadata">

**Author:** ![rplzzz](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@rplzzz](https://forums.developer.nvidia.com/u/rplzzz)\
**Post date:** [April 21, 2008, 1:57pm UTC](https://forums.developer.nvidia.com/t/stop-all-thread-one-thread-any-should-stop-all-thread-w/3390/6 "2008-04-21T13:57:34Z")

</div>

> [@](#):
>
> I must recovery password from a zip file, and every thread test one password, when password is correct the thread should stop all thread and should return the password
> 
> i am interesting to recovery passord in less time
> 
> [snapback]363904[/snapback]

You might consider breaking the password space up into chunks that run for a “reasonable” (however you define the term) length of time on the device. You could then launch a new kernel for each successive chunk and stop launching kernels when one of them returns success. If you do it that way, then not having an early termination within the kernel wastes at most the runtime of a single kernel.

Alternatively, if you are using a single thread for each password to be tested, then you will have a large number of blocks in the grid. Have each block check the value of a global flag at the beginning of its execution and exit immediately if it finds it set. Otherwise run its test and set the flag (and store the result) if successful. There is no need for a sync operation because only one password test should ever be successful; thus, there is no harm in a few superfluous blocks running because they missed the flag. The cost for this scheme is the extra global memory load at the beginning of each block, plus the time required for the remaining blocks in the grid to drain after the solution is found.

You could, of course, combine the two schemes to minimize the time wasted in draining the queued blocks.

-rpl

---

<div class="post-metadata">

**Author:** ![andreaaz](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@andreaaz](https://forums.developer.nvidia.com/u/andreaaz)\
**Post date:** [April 23, 2008, 12:29pm UTC](https://forums.developer.nvidia.com/t/stop-all-thread-one-thread-any-should-stop-all-thread-w/3390/7 "2008-04-23T12:29:27Z")

</div>

> [@](#):
>
> **andreaaz**
> 
> And why do you need to stop all threads? Just feed GPU with block of passwords, say several millions of them at a time and set some flag in global memory if password is found. Then read this flag from host and if it is set (i.e. password found) just don’t issue next kernel launch. Simple. Don’t make things complex where they are not.
> 
> ARCHPR? (Not GPU-accelerated yet) :)
> 
> [snapback]366080[/snapback]

I used a flag in global memory.
