Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow threads to specify code to run on the main thread #109

Merged
merged 1 commit into from
Aug 3, 2015

Conversation

dmpelt
Copy link
Contributor

@dmpelt dmpelt commented Aug 3, 2015

In some cases, we want to run code on the main thread
instead of in the multiprocessing thread. For example, when
using CUDA functions in ASTRA, all cuda code has to be run
on the main thread. Currently, this has to be specified by the
user by setting ncore=1. If you forget to specify this, cuda
errors occur, and worse, the user has to kill the python process
(ctrl+c and such do not work). This happens to me a lot, for example
when switching from CPU to GPU ASTRA methods, and forgetting to specify
ncore=1.

This commit adds a shared Queue to the multiprocessing code, where
threads can put things in that have to be run by the main thread. After
all threads join, the main thread clears the queue by running all code
in it. The commit also updates the ASTRA wrapper to use the queue when
using CUDA functions of ASTRA. Therefore, ASTRA CUDA code always runs
on the main thread, even when running on multiple cores, and no errors
occur when forgetting to specify ncore=1.

In some cases, we want to run code on the main thread
instead of in the multiprocessing thread. For example, when
using CUDA functions in ASTRA, all cuda code has to be run
on the main thread. Currently, this has to be specified by the
user by setting ncore=1. If you forget to specify this, cuda
errors occur, and worse, the user has to kill the python process
(ctrl+c and such do not work). This happens to me a lot, for example
when switching from CPU to GPU ASTRA methods, and forgetting to specify
ncore=1.

This commit adds a shared Queue to the multiprocessing code, where
threads can put things in that have to be run by the main thread. After
all threads join, the main thread clears the queue by running all code
in it. The commit also updates the ASTRA wrapper to use the queue when
using CUDA functions of ASTRA. Therefore, ASTRA CUDA code always runs
on the main thread, even when running on multiple cores, and no errors
occur when forgetting to specify ncore=1.
dgursoy added a commit that referenced this pull request Aug 3, 2015
Allow threads to specify code to run on the main thread
@dgursoy dgursoy merged commit 23f5942 into tomopy:master Aug 3, 2015
carterbox pushed a commit that referenced this pull request Sep 16, 2018
Allow threads to specify code to run on the main thread

Former-commit-id: 23f5942
carterbox pushed a commit that referenced this pull request Sep 16, 2018
Allow threads to specify code to run on the main thread

Former-commit-id: 23f5942
carterbox pushed a commit that referenced this pull request Sep 16, 2018
Allow threads to specify code to run on the main thread

Former-commit-id: a328974 [formerly 23f5942]
Former-commit-id: 9890f26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants