As an aside, it looks like you're generating an array of coordinates and then mapping it to an array of results. You don't need to create the coordinate array if you use the init function instead of map : Array.Parallel. Init 1000 (fun y -> Array.
Init 1000 (fun x -> this.colorArray. CalcZ (x, y))) EDIT: The following may be inaccurate: Your problem could be that you call a tiny function a million times, causing the scheduling overhead to overwhelm that actual work you're doing. You should partition the array into much larger chunks so that each individual task takes a millisecond or so.
You can use an array of arrays so that you would call Array.Parallel. Map on the outer arrays and Array. Map on the inner arrays.
That way each parallel operation will operate on a whole row of pixels instead of just a single pixel.
As an aside, it looks like you're generating an array of coordinates and then mapping it to an array of results. You don't need to create the coordinate array if you use the init function instead of map: Array.Parallel. Init 1000 (fun y -> Array.
Init 1000 (fun x -> this.colorArray. CalcZ (x, y))) EDIT: The following may be inaccurate: Your problem could be that you call a tiny function a million times, causing the scheduling overhead to overwhelm that actual work you're doing. You should partition the array into much larger chunks so that each individual task takes a millisecond or so.
You can use an array of arrays so that you would call Array.Parallel. Map on the outer arrays and Array. Map on the inner arrays.
That way each parallel operation will operate on a whole row of pixels instead of just a single pixel.
I imagined that but I couldn't find anything about that on MSDN. And I will look into the init function, thanks for the tips. – Gorgen Nov 15 '10 at 14:13 @Gorgen: This shouldn't really be an issue.
It _may be) better to have thousands of iterations, rather than millions (and it sounds logical), but in some tests I did, there wasn't any observable difference. But of course, the important advice when writing parallel code is to measure it yourself... – Tomas Petricek Nov 15 '10 at 15:19 Tomas: You may be right. I was thinking of ForEach rather than For; I'm not sure how For works.
Regardless, I believe my suggestions are good ideas. – Gabe Nov 15 '10 at 15:26 I will take a closer look on this tomorrow, I have my wife behind my back as I write this... Yes, it is really a home project :) – Gorgen Nov 15 '10 at 15:27.
Per the comment on the original post, here is the code I wrote to test the function. The fast version only takes a few seconds on my average workstation. It is fully sequential, and has no parallel code.It's moderately long, so I posted it on another site: pastebin.com/Rjj8EzCA I'm suspecting that the slowdown you are seeing is in the rendering code.
Thank you very much, I will take a look on this as soon as I got time to spare. Pastebin seems like a nice tool too. – Gorgen Nov 18 '10 at 8:26 I'm starting to suspect that it is the rendering code too.... – Gorgen Nov 19 '10 at 9:17.
I don't think that the Array.Parallel. Map function (which uses Parallel. For from .
NET 4.0 under the cover) should have trouble parallelizing the operation if it runs a simple function ~1 million times. However, I encountered some weird performance behavior in a similar case when F# didn't optimize the call to the lambda function (in some way). I'd try taking a copy of the Parallel.
Map function from the F# sources and adding inline. Try adding the following map function to your code and use it instead of the one from F# libraries: let inline map (f: 'T -> 'U) (array : 'T) : 'U= let inputLength = array. Length let result = Array.
ZeroCreate inputLength Parallel. For(0, inputLength, fun I -> result. I ignore result.
I have tried your function but for some reason it is choking on the fact that I have an array of (double * double) at least I interpret the error message as that: 'c -> 'd is not compatible with type seq – Gorgen Nov 15 '10 at 14:33 When I put it in my function as a local function it worked – Gorgen Nov 15 '10 at 14:52.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.