How to limit CPU usage to a single core with freud.Box.wrap
?
#1301
-
DescriptionI am using import freud
import numpy as np
import threading
import time
fr_box = freud.Box.from_box([10, 10, 0])
a = np.random.random((100, 3))
while True:
fr_box.wrap(a)
if int(time.time()) % 2 == 0:
print(f"Active threads: {threading.active_count()}")
The output of the code repeatedly shows the following:
Active threads: 8
Active threads: 8
Active threads: 8
Active threads: 8
Active threads: 8
Whe I run the program in the foreground, the program consumes 100% CPU across all available cores, even though I expect it to run on a single core.
![image](https://github.com/user-attachments/assets/b1bd9fa3-b355-479a-b626-609ad62ece36)
## I have tried:
```python
import freud
freud.parallel.set_num_threads(1)
## version
freud 3.1.0
Thanks for your help~
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
I am not able to reproduce the behavior you describe.
When I run the the following script:
I get the expected 100% CPU usage:
Your image doesn't show which processes are contributing to that CPU usage. It is possible that another program is running in the background consuming the other 7 CPUs. |
Beta Was this translation helpful? Give feedback.
You failed to run the exact script I provided, so you should not expect the same results.
freud.parallel.set_num_threads(1)
must be the first function call that you make to the freud module.