I wrote code to compute the dynamics of a large set of coupled basic equations using the Runge-Kutta method. The code contains many for-loops where each step is independent. I intend to use Grand Central Dispatch to speed up the program. I based my attempt on an example that I found at http://www.macresearch.org/cocoa-scientists-xxxi-all-aboard-grand-central . Neither my code nor the macro network example compiles on my computer (MacOSX 10.6.8 Xcode 4.0.2). So here is my code:
... double values[SpaceSize], k1[SpaceSize]; for ( int t=1 ; t<Time ; t++ ) { dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); //k1 for (int k=0 ; k<SpaceSize ; k++ ) values[k]=Concentration[k][t-1]; dispatch_apply(SpaceSize, queue, ^(size_t k) { k1[k]=h * derives(values, SpaceSize, k); //<--error } ); ...
It fails with an error:
Semantic problem: cannot refer to declaration with modified change type inside block
I tried replacing arrays (values, k1) with vectors, but instead I get another error message:
Semantic issue: read-only variable not assigned
That's where I got stuck, not knowing what these error messages are trying to tell me. I spend quite a lot of time and ask if anyone can help. I would be very grateful for the advice or the best ways to solve this problem.
source share