I have a series of computations that I'd like to run in parallel to speed it up.
The program looks something like this:
Type InputData = record
....
end;
var InputD: Array[1..10000] of InputData;
OutputD: Array[1..10000] of real;
Procedure AnalyzeIt(Index: PtrInt; Data: Pointer; Item: TmultiThreadProcItem);
// This does computations using data from InputD[Index], and stores the output in OutputD[index]
// The routine calls lots of other global procedures and functions, none of which use global variables except
// InputD and OutputD,
// and then only to the array element [Index]
begin
// other routines build up input data
ProcThreadPool.DoParallel(@AnalyzeIt, 1, 10000, nil);
//other routines store the output somewhere
The program runs, the data is saved, and it is garbage. If you run it twice, you get different results for each data point (and there are no random calls or changing inputs). Clearly I am missing something big picture here.
Any suggestions?
If I have a global function Add(x,y) for example, and Add gets called in two threads at the same time, I am assuming that Add is run locally in each thread. Is that incorrect?