OpenCL furthest point from line /parallel reduction

Hello All,

Have been testing with ofxMSAOpenCl particle systems; I’d like to try and use it to detect the particle that is furthest from a given point.

i.e. parallelise a furthest point test so that it can run inline with the particle.cl

Does anyone know how to go about doing this/have a working example?

Thanks
Sam

Update: It looks like what I am looking for is an OpenCL parallel reduction example written for Openframeworks.
There is an article on parallel reduction here: http://developer.amd.com/resources/documentation-articles/articles-whitepapers/opencl-optimization-case-study-simple-reductions/ but whilst I understand the concept I can’t figure out a great deal more yet.

[longer update]

I’ve been hacking away at the C example implementation of an openCL reduction provided here:
https://developer.apple.com/library/mac/samplecode/OpenCL_Parallel_Reduction_Example/Introduction/Intro.html

It is a little confusing to my novice eye, but I may have a simplified version working for OF: 150719_reducio.zip (60.5 KB)

I think that this attempt extracts the largest value from a random array of 4million integers. It takes circa 0.9s to do this on an Intel HD Graphics 4000. Seems a little slow to me. I have a few questions about how it appears to be running; mainly why it only does two passes, why it is fixed to 1000 iterations and if anything in ofxmsaopenCl can do a similar job.

Can anyone verify and or help explain the attached for me?
In hope

Sam