I'm implementing a physics solver where I want to loop over pairs of points for collision solving, is this possible to do multithreaded?
Using this I can loop over single points multithreaded:
// GA_RWHandleV3D p_handle( gdp->findAttribute(GA_ATTRIB_POINT, "P"));// GA_SplittableRange range = gdp->getPointRange();// in the THREADED_METHOD functionfor(GA_PageIteratorpit=range.beginPages(info);!pit.atEnd();++pit){GA_Offsetstart,end;for(GA_Iteratorit(pit.begin());it.blockAdvance(start,end);){for(GA_Offseti=start;i<end;++i){UT_Vector3p=p_handle.get(0);// do work for each pointp_handle.set(0,p);}}}
The pairs I want to loop over are stored in a vector<pair<int,int>> where none of the points is listed twice.
I need to fetch multiple point attributes from each point. For example I need to get the v@P, v@v v@pscale of both points then update then solve and update the new v@P and v@v attribute.
There is also this comment in GA_PageIterator.h above GAparallelForEachPage:
/// Invokes the body approximately once per worker thread with/// a shared atomic int to provide load-balanced iteration over the/// pages in the range./// shouldthread allows you to easily disable threading, for example if/// you know some cases are not threadsafe or you have a larger grain/// size./// Body Signature: void body(GA_PageIterator page_iterator)/// Usage:/// GAparallelForEachPage(range, shouldthread, [&](GA_PageIterator pit)/// {/// /* Thread local data structures / scratchpads *//// UT_IntArray scratchpad;/// GA_ROPageHandleF pagehandle; /* page handles must be per thread *//// GAforEachPageBlock(pit, [&](GA_Offset start, GA_Offset end)/// {/// pagehandle.setPage(start);/// for (GA_Offset off = start; off < end; off++)/// { /* Process off, using scratchpad */ }/// });/// });////// NOTE: Using [&] capture on GAparallelForEachPage will share the outer/// scope's stack variables between threads - you must treat them as const/// (and in particular, re-build pagehandles inside this loop. For non/// trivial loops explicit binding may be safer.