# Can operations with the CDF of random variables be parallelized?

I am trying to parallelize the computation of the CDF of a random variable (more precisely, a doubly noncentral $F$ variable) for a matrix of values.

This is a MWE:

rows = {3, 4, 5};
columns = {0.1, 0.2, 0.3};
ones = Table[{1}, 3];
RO = ones.{rows};(* 3x3 matrix with all ROWS equal to rows *)
CO = Transpose[
ones.{columns}];(* 3x3 matrix with all COLUMNS equal to columns *)
Q1 = RO + CO; (* Matrix of input values *)
Q2 = Parallelize[CDF[NoncentralFRatioDistribution[10, 2, 5, 1], Q1]]


The result is

Parallelize::nopar1: CDF[NoncentralFRatioDistribution[10,2,5,1],Q1] cannot be parallelized; proceeding with sequential evaluation.

[...]

My real problem does not deal with $3 \times 3$ but $400 \times 400$ matrices, and the time consumed is excessive without parallelization. Can this be done in a different way, taking profit of parallelization?

UPDATE

I am not very familiar with parallelizing operations. I would usually do this with two nested for loops. But, as fas as I know, many languages allow for parallelization, which is, operating on a vector or a matrix as if it was a number (roughly speaking), and it seems to be faster than nested loops.

So... That is how I finally arrived to the impasse I have just reported. I do not know how to continue or solve this.

You may use ParallelMap. First note that CDF[dist] should return a Pure Function of the CDF but in some cases, like the 4-parameter version of NoncentralFRatioDistribution, it does not. Therefore, a pure function of the CDF is created and mapped in parallel over the items in Q1.

ParallelMap[CDF[NoncentralFRatioDistribution[10, 2, 5, 1], #] &, Q1, {-1}]

{{0.745711,0.800896,0.836492},
{0.752554,0.805134,0.839367},
{0.759042,0.809196,0.842143}}


A read of the Method option of Parallelize would help you as ParallelMap uses this option as described there.

Hope this helps.

• Thank you. How would this be done with a function that needs two inputs?? I am trying to do it, without success for now. – Vicent Nov 29 '17 at 16:25
• I think it can be done with MapThread. Is it a good solution? – Vicent Nov 29 '17 at 16:33
• @Vicent Try something along the lines of ParallelMap[f[#[[1]], 1, #[[2]]] &, Partition[Range[12], 2]]. You should have a look at the Functional Programming guide and the tutorials found there. – Edmund Nov 29 '17 at 20:11