parallel computing

How do I use this algorithm? What does that parameter do?
Post Reply
ling
Posts: 6
Joined: 23 Jul 2021, 06:42

parallel computing

Post by ling »

Hello,
Recently, when I submitted a task to the server, the administrator told me that the submitted task occupied all the cores on the server during calculation, and asked me to modify it before submitting.
But I didn't use any parallel-computing instructions when submitting the task.
I wonder if parallel computing is used in Tenpy?
Or is this caused by Python's multithreaded computing?
Or Is this error related to the UserWarning I received in the calculation that " Couldn't load compiled cython code. Code will run a bit slower." ?
Is there a method to solve this problem?
Your advice is very important to me, Looking forward to your reply.
Thanks!
User avatar
Johannes
Site Admin
Posts: 337
Joined: 21 Jul 2018, 12:52
Location: TU Munich

Re: parallel computing

Post by Johannes »

Hi Ling, sorry for the late reply!
Indeed, with your question I realized that we probably don't document this sufficiently.
I've just added a corresponding section in the simulation introduction.
Does that answer your questions?
ling
Posts: 6
Joined: 23 Jul 2021, 06:42

Re: parallel computing

Post by ling »

Hi Johannes,

Thank you very much for your reply!

In order to calculate different models and simplify the steps of submitting tasks, I have handled the model part and the submit-task part separately.
I don't know which part of the file should use the command about ‘export OMP_NUM_THREADS=1’ .
The following is the calling module part of the main program (I called tenpy in this file and made the main calculation), where ‘os.environ’ is used to set single thread, but it's failed.

import argparse
import json
import os
os.environ['OMP_NUM_THREADS']="1"
os.environ['MKL_NUM_THREADS']="1"
os.environ['MKL_DYNAMIC']="False"
import numpy as np
import tenpy.linalg.np_conserved as npc
from model import StaggerLadderModel
from tenpy.algorithms import dmrg
from tenpy.networks.mps import MPS
from tenpy.networks.mpo import MPO
from calc import negativity
from tenpy.algorithms.tebd import RandomUnitaryEvolution
from tenpy.tools.math import entropy as tenpyentropy

Should I add other commands here?
If not, should I put the ‘export OMP_NUM_THREADS=1’-command in the submit-task file?

Any advice is very important to me, Looking forward to your reply.
Thanks!
User avatar
Johannes
Site Admin
Posts: 337
Joined: 21 Jul 2018, 12:52
Location: TU Munich

Re: parallel computing

Post by Johannes »

The export OMP_NUM_THREADS=1 is a bash command. You should have a slurm/sge/bash script which you submit to the cluster, include this line there. For example, if you use the setup of the TeNPy project repository, you can explicitly add the corresponding line in the file cluster_templates/slurm.sh (or whichever template you use).

If you want to do this in python, you need to make sure you do this before any import of numpy/tenpy/scipy/any other package using numpy. In other words, move it to the very top of your python file. Then it should work, at least in theory - and I checked that it works on my laptop.
ling
Posts: 6
Joined: 23 Jul 2021, 06:42

Re: parallel computing

Post by ling »

Hi Johannes,

Thank you very much for your detailed explanation!

According to your suggestion, I successfully modified the submitted script.
Post Reply