Linux Server set thread for Pytorch

During the time of doing my course work for Advanced Machine Learning, I ran my deep learning scripts on the server. In the first time, I saw the %CPU of my job was always very high. (And then, the admin killed my job since it stuck other jobs…sorry, i didn’t know this at that time)

To avoid the effect on other users, before runing our Pytorch scripts, we should run the following code in the beginning to set the thread.

1
2
OMP_NUM_THREADS=1
export OMP_NUM_THREADS

This allow us to use only one thread in our one job.