Ask Your Question
1

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

asked 3 years ago

updated 3 years ago

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.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 3 years ago

tmonteil gravatar image

updated 3 years ago

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)

Preview: (hide)
link

Comments

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

lisandrasp gravatar imagelisandrasp ( 3 years ago )

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 ( 3 years ago )

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

tmonteil gravatar imagetmonteil ( 3 years ago )
1

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

lisandrasp gravatar imagelisandrasp ( 3 years ago )

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: 3 years ago

Seen: 314 times

Last updated: Jun 30 '21