He Andrew,
I used @parallel in sage to parallelize some tensorial calculus (for example : src/sage/tensor/modules/comp.py)
It is not very complicate to use it but sometimes you need to reorganize your computation.
The parallelism depends strictly on your code so the part of code you posted is not enough to understand how parallelize it.
The main actions you have to do are:
1) Create a function (with @parallel decoration) which will be used by your cores to computes a part of the computation :
ex:
@parallel(p_iter='multiprocessing',ncpus=24)
def paral_prod(myfunc,local_list_ind):
partial = []
# local_list_ind is a subset of set of "s" and "t" pairs
for ind in local_list_ind :
# ind[0] is the "s", ind[1] is the "t" of your code
partial.append([ind[0],ind[0],myfunc(ind[0],ind[0]))
return partial
Note that multiprocessing does not use really shared memory so you have to give to your function all the variable you need to use in it.
2) Then create a "list" of input (so of "tuple"):
ex :
listParalInput =[(self._inner_product_st,[[1,2],[1,3]]),(self._inner_product_st,[[2,3],[1,3]],.......) ]
In this example any tuple in the list will be send to a core.
Then the first core will execute :
paral_prod(self._inner_product_st,[[1,2],[1,3]])
and so on for the other cores.
3) Now you can call the parallel function and put the results in "mat"
for ii,val in paral_prod(listParalInput):
for jj in val:
# any jj in val contains : [ s ,t , self._inner_product_st(1,2)]
mat[jj[0],jj[1]] = jj[2]
mat[jj[1],jj[0]] = jj[2]
I have not tested this code but it should work (at least in principle).
It remains to create the listParalInput automatically (you have to do a partition of the indices of the triangular matrix).
I have also a little doubt concerning the use of self._inner_product_st as an argument, but you should test it.
Regards,
Marco