Ask Your Question

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

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

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

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

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

tmonteil gravatar image

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

SInce you have to run the computation on various graphs, you can do some basic parallelism provided by the @paralleldecorator, see

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


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 +0100 )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 +0100 )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 +0100 )edit

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

lisandrasp gravatar imagelisandrasp ( 2021-06-30 23:05:36 +0100 )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


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

Seen: 218 times

Last updated: Jun 30 '21