C++ (Qt)struct CData { void DoCalc( float x, float y ); ... int mX, int mY; CCube mCube[9]; ...}; void CData::DoCalc( float x, float y ){ int ix = (int) floor(x); int iy = (int) floor(y); if (ix != mX || iy != mY) { mX = ix; mY = iY; for (int i = -1; i <= +1; ++i) for (int j = -1; j <= +1; ++j) SetupCube(mCube[(j + 1) * 3 + i + 1], mX + i, mY + j); } DoSomethingWithCubes(mCube); ...}
i j (j + 1) * 3 + i + 1-1 -1 0-1 0 3-1 +1 6 0 -1 1 0 0 4 0 +1 7+1 -1 2+1 0 5+1 +1 8
for (int i = -1; i <= +1; ++i){ QSetupCubeThread Threads[3]; for (int j = -1; j <= +1; ++j) { Threads[j+1].arg1 = (j + 1) * 3 + i + 1; Threads[j+1].arg2 = mX + i; Threads[j+1].arg3 = mY + j; Threads[j+1].start(); } for (int j = -1; j <= +1; ++j) Threads[j+1].wait();}
class CData{ private : int mX, int mY; CCube mCube[9]; mutable QReadWriteLock m_Locker; public : void DoCalc(float x, float y); CCube cube(int i) const;}void CData::DoCalc(float x, float y){ QWriteLocker WL(&m_Locker); // ... вычисляем ...}CCube CData::cube(int i) const{ QReadLocker RL(&m_Locker); return mCube[i];}
C++ (Qt)#pragma omp parallel forfor (int i = 0; i < data.size(); ++i) DoCalc(data[i].x, data[i].y);
// if (ix != mX || iy != mY) {if (1) {..// и сделать mCube локальным массивом (а не членом класса)