Multiprocessing for Tensors is not working for Macintosh. (SageMath 9.0)

90 views
Skip to first unread message

Alan Stafford

unread,
May 24, 2020, 9:15:14 AM5/24/20
to sage-support
Multiprocessing of Tensors is not working for Macintosh.

show(version())
#MacBook Pro dual core i5, hyper-threaded. Should support 4 ply multiprocessing.

%display latex  # LaTeX rendering turned on

Parallelism().set('tensor',4)  #Only works if set to one.
Parallelism().set('linbox',4) 
Parallelism()

M = Manifold(4, 'M')
MChart = M.open_subset('MChart')
Chart.<u,v,x,y>   = MChart.chart(r'u:(-oo,+oo) v:(-oo,+oo) x:(-oo,+oo) y:(-oo,+oo)') 

gT= MChart.riemannian_metric('gT')
var('du','dv','dx','dy')

dsds= -du*dv+dx*dx+dy*dy+e^(x*y)*du*du


dsds=dsds.expand()
g00=dsds.coefficient(du,2)
g11=dsds.coefficient(dv,2)
g22=dsds.coefficient(dx,2)
g33=dsds.coefficient(dy,2)
g01=dsds.coefficient(du*dv,1)
g01=g01/2
g10=g01

gT[0,0] = g00.factor() #du du
gT[1,1] = g11.factor() #dv dv
gT[2,2] = g22.factor() #dx dx
gT[3,3] = g33.factor() #dy dy
gT[0,1] = g01.factor() #du dv 
%display latex
show(gT.display())

Metric=gT

Nabla = Metric.connection()

%time Bach=(Nabla(Metric.cotton()).up(Metric,3)['^u_aub'])+((Metric.schouten().up(Metric))*(Metric.weyl().down(Metric)))['^uv_aubv']
show(Bach.display())
%time Bach=Nabla(Nabla(Metric.weyl().down(Metric))).up(Metric,4).up(Metric,5)['^bd_abcd']-(1/2)*((Metric.ricci().up(Metric))*(Metric.weyl().down(Metric)))['^bd_abcd']
show(Bach.display())
%time Bach=-(Metric.schouten()*(Metric.weyl().down(Metric))).up(Metric,1).up(Metric,2)['^cd_cdab'] - Nabla(Nabla(Metric.schouten())).up(Metric,3)['^c_cab'] + Nabla(Nabla(Metric.schouten())).up(Metric,3)['^c_abc']

Cotton=-Nabla(Metric.ricci())['_i[jk]']-1/(2*(4-1))*Nabla(Metric.ricci_scalar()*Metric)['_i[kj]']

%time Bach=(Nabla(Cotton).up(Metric,3)['^u_aub'])+((Metric.schouten().up(Metric))*(Metric.weyl().down(Metric)))['^uv_aubv']
show(Bach.display())
BachTensor.ipynb

Eric Gourgoulhon

unread,
May 25, 2020, 3:22:45 PM5/25/20
to sage-support
Hi,

Le dimanche 24 mai 2020 15:15:14 UTC+2, Alan Stafford a écrit :
Multiprocessing of Tensors is not working for Macintosh.


Alas, this is a known issue that has been reported repeatedly by macOS users: Sage's multiprocessing seems broken on macOS. No fix has been proposed yet.
What is strange is that the doctests involving multiprocessing are passed on macOS. So there is something in the doctest framework that makes it work. But in an interactive session, it fails, as you noticed. I am not familiar at all with macOS and cannot help on this point. Sorry...

Eric.

Alan Stafford

unread,
May 29, 2020, 7:43:35 AM5/29/20
to sage-support
I have an inkling that it is the code to probe the number of processors present that is at fault. It uses the right command but doesn't use the result and always returns one. This causes problems with the interface to maxima if one has set the number of cores for tensor computations to other than one. I will try this out by changing the code the I get some time.


Eric Gourgoulhon

unread,
May 29, 2020, 9:12:06 AM5/29/20
to sage-support
Le vendredi 29 mai 2020 13:43:35 UTC+2, Alan Stafford a écrit :
I have an inkling that it is the code to probe the number of processors present that is at fault. It uses the right command but doesn't use the result and always returns one. This causes problems with the interface to maxima if one has set the number of cores for tensor computations to other than one. I will try this out by changing the code the I get some time.

Thank you for investigating this! I've opened the ticket
Feel free to report any investigation / code change in the ticket.

Eric.

Alan Stafford

unread,
May 30, 2020, 5:07:07 PM5/30/20
to sage-support
How do I make sure the changes I have made to the code are present.
Do I need to restart sage or even recompile it? Or just restart the Kernel?
The change I have made is to ncpus.py .

Indeed Mac OS has no hasattr(os, "sysconf"): . 

It should execute "sysctl -n hw.ncpu" which on my machine returns 4.

I can't quite follow the code as I am not used to indentation level affecting code semantics. I know ncpus always returns 1.


Dima Pasechnik

unread,
May 30, 2020, 5:52:43 PM5/30/20
to sage-support
if you change *.py files in src/sage/ it's enough to do

./sage -b

to install the changed files in local/

(it's trickier with Cython files)
> --
> You received this message because you are subscribed to the Google Groups "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/b8a51fb5-40af-4787-8d8e-472c5baee34c%40googlegroups.com.

Alan Stafford

unread,
May 30, 2020, 8:33:06 PM5/30/20
to sage-support
I have just updated to SageMath 9.1 and updated my OS. I see that ncpus.py has been changed. 
I have tested the multiprocessing with the file enclosed above and others and it is  working. Thank you all for fixing this.

Eric Gourgoulhon

unread,
Jun 2, 2020, 2:45:45 AM6/2/20
to sage-support
Le dimanche 31 mai 2020 02:33:06 UTC+2, Alan Stafford a écrit :
I have just updated to SageMath 9.1 and updated my OS. I see that ncpus.py has been changed. 
I have tested the multiprocessing with the file enclosed above and others and it is  working. Thank you all for fixing this.

Thanks for this good news. I am happy to see that this long standing issue with macOS is fixed!

Best wishes,

Eric.
Reply all
Reply to author
Forward
0 new messages