0
$\begingroup$

I'm trying to create a model for intensive computations for a homomorphic encryption scheme. The core of my problems is a series of function calls

h00=Function[PadLeft[IntegerDigits[Mod[(#1[[2]]-#1[[1]][[1]])*(#2[[2]]-#2[[1]][[1]]),q],2],wrdLen+1]];

hi0=Function[Table[PadLeft[IntegerDigits[Mod[#1[[1]]*(#2[[1]][[1]]-#2[[2]])-#1[[2]]*#2[[1]],q],2][[u]],wrdLen+1],{u,2,n+1}]];

h0j=Function[Table[PadLeft[IntegerDigits[Mod[#1[[1]][[1]]*#2[[1]],q],2][[i]],wrdLen+1],{i,2,n+1}]];

hij=Function[Table[PadLeft[IntegerDigits[Table[Mod[#1[[1]][[i]]*#2[[1]][[j]],q],{i,2,n+1},{j,2,n+1}],2][[u]][[v]],wrdLen+1],{u,1,n},{v,1,n}]];
hijτ=Function[Join[{Catenate[{{h00[#1,#2]},h0j[#1,#2]}]},Transpose[Catenate[{{hi0[#1,#2]},Transpose[hij[#1,#2]]}]]]];

SHMult=Function[Catenate[{{Mod[Sum[hijτ[#1,#2][[i]][[j]][[wrdLen+2-τ]]*a[[1]][[i]][[j]][[τ]],{i,1,n+1},{j,1,n+1},{τ,1,wrdLen+1}],q]},{Mod[Sum[hijτ[#1,#2][[i]][[j]][[wrdLen+2-τ]]*k[[1]][[i]][[j]][[τ]],{i,1,n+1},{j,1,n+1},{τ,1,wrdLen+1}],q]}}]];

Function SHMult calls all previous functions and depending on the number of simulations this might be repeated a lot of times. Basically, what it does is that it creates a big square matrix hijτ where h00 produces the element {0, 0}, hi0 produces all other elements of the first column, h0j produces all other elements of the first row, and hij produces a submatrix with all other elements of the matrix.

Not also that the indices for i, j, τ might be also large; for example a 256 x 256 matrix of 32-bit values. As a first step I tried to use Compile instead of Function for all these functions with the parallelization option given, but I got errors. Also I tried ParallelTable instead of Table, but I got an error saying that ParallelTable can't be used in a nested environment.

Is there any way to optimize this somehow?

$\endgroup$
  • 1
    $\begingroup$ What is wrdLen? How did you try to call compile? $\endgroup$ – Feyre Mar 24 '17 at 11:20
  • $\begingroup$ It is a constant defined before calling the functions. I just didn't define it to simplify the question. For compile I set Compile[{x,y}...,Option] and replaced the #1, #2 in the function definitions with x and y. $\endgroup$ – Jimakos Mar 24 '17 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.