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

Multithreaded Programming using OpenBLAS #4217

Open
solahn opened this issue Sep 6, 2023 · 7 comments
Open

Multithreaded Programming using OpenBLAS #4217

solahn opened this issue Sep 6, 2023 · 7 comments

Comments

@solahn
Copy link

solahn commented Sep 6, 2023

I want to create 3 threads which are using gemm function with OpenBLAS.

Thread 1 - core affinity with CPU core 1 (openblas_set_num_threads(1))
Thread 2 - core affinity with CPU core 2,3 (openblas_set_num_threads(2))
Thread 3 - core affinity with CPU core 4,5,6 (openblas_set_num_threads(3))

Do those threads run at once without editing any codes of your library?

https://github.com/xianyi/OpenBLAS/wiki/faq#multi-threaded

I saw the link.
If I use the USE_THREAD and USE_LOCKING environment variables, will it behave like the above situation?

If that is correct, how do I use them?

@brada4
Copy link
Contributor

brada4 commented Sep 7, 2023

All 3 your threads will be serialized in 3-thread 'thread'. If your 3 threads are processes it will work as you expect.

@solahn
Copy link
Author

solahn commented Sep 7, 2023

All 3 your threads will be serialized in 3-thread 'thread'. If your 3 threads are processes it will work as you expect.

I want to run 3 threads in parallel, not in series. Is it possible to run in parallel? (in 1 process)

@brada4
Copy link
Contributor

brada4 commented Sep 7, 2023

If you use_thread=0 but keep use_locking then you can schedule your single-threaded calls from your code. You cannot have both at once.

@HaileeKim
Copy link

HaileeKim commented Sep 7, 2023

If you use_thread=0 but keep use_locking then you can schedule your single-threaded calls from your code. You cannot have both at once.

if I set USE_THREAD=1, USE_LOCKING=0, then is above situation possible without lock?

I want programming without race condition

@brada4
Copy link
Contributor

brada4 commented Sep 7, 2023

There is common structure in memory.c that tracks allocations and you need locking for that. USE_THREAD means dllinit()/.init() will start thread per core at startup, for aforementioned reason locking is implied in this case.

@HaileeKim
Copy link

There is common structure in memory.c that tracks allocations and you need locking for that. USE_THREAD means dllinit()/.init() will start thread per core at startup, for aforementioned reason locking is implied in this case.

Then, if I programmed with multi-processors not multi-threading,do those programs not have locking?

@brada4
Copy link
Contributor

brada4 commented Sep 7, 2023

OpenBLAS locks own critical structures when single-threaded version is called concurrently.
Obviously you have to barrier writes to not have them concurrenlty in same place, and then barrier reads to not read up half-written data, including activities done with OpenBLAS. Think of memcpy()-like behaviour with heavy computation in process.

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

No branches or pull requests

3 participants