Ask Your Question
1

Is it possible for the spectrum() method to use all CPU cores?

asked 2021-06-30 18:41:11 +0200

updated 2021-06-30 21:07:05 +0200

I need to compute the Laplacian spectrum of a ton of graphs and was wondering if it's possible to use all CPU cores instead of only one.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-06-30 18:46:00 +0200

tmonteil gravatar image

updated 2021-06-30 22:54:14 +0200

SInce you have to run the computation on various graphs, you can do some basic parallelism provided by the @paralleldecorator, see https://doc.sagemath.org/html/en/refe...

EDIT if tou use the @parallel decorator, you have to specify the number of cpus, e.g. @parallel(ncpus=8)

edit flag offensive delete link more

Comments

Thanks! I was trying to use Python's multiprocessing library before, I'll try using the decorator then.

lisandrasp gravatar imagelisandrasp ( 2021-06-30 18:56:20 +0200 )edit

I'm experimenting with the @parallel decorator but the spectrum() method doesn't seem to accept more than one input at a time.

vertex = 7
parameters = str(vertex) + " -c " + str(vertex) + ":" + str(vertex)
graphs_nauty = list(graphs.nauty_geng(parameters))

@parallel def laplacian_spectrum(graph): return graph.spectrum(laplacian = True)

spectrum_all = laplacian_spectrum(graphs_nauty)

for i in spectrum_all: print(i)

Is there a way to use @parallel with the spectrum() method instead of using it on a function I defined myself?

lisandrasp gravatar imagelisandrasp ( 2021-06-30 21:05:51 +0200 )edit

The way you did works for me, if i replace @parallel with @parallel(ncpus=8)

tmonteil gravatar imagetmonteil ( 2021-06-30 22:51:30 +0200 )edit
1

It isn't working for me at all. Which Sage version are you using?

lisandrasp gravatar imagelisandrasp ( 2021-06-30 23:05:36 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2021-06-30 18:41:11 +0200

Seen: 231 times

Last updated: Jun 30 '21