I have a script that repeatedly runs and returns a result for each row in the data table. I cannot be broken down into an operation for each cell in the table, so each iteration returns a vector of results corresponding to a value for each row in the data table.
dt=current data table();
nr=n rows(dt);
result=J(nr, 1, .)
/*
script body assigns values to result vector
*/
result;
I need to iterate this operation hundreds or thousands of times, and each iteration take about 0.5 second. I gather all the returned results into matrix which then will be further summarized. The order of the results generated do not matter.
If this could be parallelized/multi-threaded, it would run much faster.
I want to use the Parallel Assign() function, which has the syntax. I think what I need to do is create a global variable result_matrix = [], pass that through to the local function used in Parallel Assign() and then at the end of the expression append the result vector to the result_matrix. result_matrix will have nr rows and n_iterations columns.
</CODE></PRE>
<P>Any suggestions on how to do this. Ultimately what need to do is calculate the mean result for each row in <STRONG>result_matrix</STRONG> to get an assigned value for each row in the data table, that is</P>
<PRE><CODE class=" language-jsl">final_result_vector = V Mean(results_matrix`);