chianti-atomic / ChiantiPy

ChiantiPy is a python package to calculate the radiative properties of astrophysical plasmas based on the CHIANTI atomic database
63 stars 32 forks source link

Problem with mspectrum? #459

Open Rogerthatx opened 7 months ago

Rogerthatx commented 7 months ago

Hello all, when I run the mspectrum function I noticed that all the cores get 100% load after doing an htop.

htop htop_simple

I am running ChiantiPy in my persona computer and in a server and I get the same behavior. (see attached images). On my personal setup I am just trying to run an example from the notebooks (see test_code.png). This happens even if I lower the number of processor to 3 for example. test_code

Do you have any idea of why this could be happening?

Cheers,

-Rogelio.

Rogerthatx commented 7 months ago

Update: apparently, the problem happens when mspectrum starts to calculate emission lines. If I calculate only the continuum, then the calculations are faster. But if I set DoLines = True the routine takes every available core.

kdere commented 7 months ago

Hi Rogelio,

in mspectrum you can set the keyword argument proc = 2, or whatever number of cores you want it to use. The current default value is 3.

hope this helps,

Ken

Rogerthatx commented 7 months ago

This happens even if I set to 2 the number of cores. Does the keyword argument proc refers to the physical processors of the machine? Or is meant to be the total number of available cpus? When I run the routine in a machine with 48 cpus and I set proc = 10, this happens, again only when I set Dolines = True. If I only calculate the continuum, the mspectrum respects the maximum number of processes I set with the proc argument.

-Rogelio.

kdere commented 7 months ago

It should set the number of cores that you want to use.

Ken

wtbarnes commented 7 months ago

@Rogerthatx What happens if you compute the intensity for a single ion, ie without using the mspectrum class? I think it may be that the NumPy linalg.solve call used for the level populations may implicitly use all available cores depending on how you've installed NumPy. As such, you would see all cores being used independent of what option you're passing to nproc

Rogerthatx commented 7 months ago

When I calculate the intensity for a single ion with ch.ion, it does not change the cpu load, the calculations are done instantly. I did another test,first I calculated the intensity, and then I calculated the spectrum of a single ion with my_ion.spectrum(wvl). The calculations are done almost instantly but this function seem to be taking all the cores for a moment to do the calculations.

kdere commented 7 months ago

I checked whether setting proc is effective and it seems that it is now working correctly. On my cpu, setting proc=4 and all 6 cores are used.

I am looking into this.

kdere commented 7 months ago

also, if you only calculate the line radiations (doLine = False), the only a single core is involved.

still checking

kdere commented 7 months ago

I have been looking into the matter and doing some testing. It seems that it is not possible to limit the multiprocessing queues to a single core. Also, sometimes you do not get increased speed for some problems. You might want to time the single processor spectrum vs. mspectrum for a small problems (set minAbund = 1.e-4, a small number of wavelengths ...) and see which is faster etc.

There is a bug in mspectrum and will try to chase that down

Ken