1. 따라서 push_back()이 발생할 때 아래처럼 처리하면 push_back()의 효과를 낼 수 있음
output.resize(input.rows);
int k = 0;
#pragma omp parallel for shared(k, input)
for( int i = 0; i < input.rows; i++ )
{
if(IsGoodMatch(input[I])
{
Newvalues newValues;
...
// ! prevent other threads to modify k !
output[k] = newValues;
k++;
// ! allow other threads to modify k again !
}
}
output.resize(k);
2. 또는 멀티 쓰레드 처리를 위해 개발된 concurrency vector의 push_back()을 사용하면 됨
#include <concurrent_vector.h>
Concurrency::concurrent_vector<int> // in c++11.
3차원 영상(공간?) 도메인에서 3차원 배열의 인덱스를 1차원으로 변환하는 식은 아래와 같음
public int to1D( int x, int y, int z ) {
return (z * xMax * yMax) + (y * xMax) + x;
}
public int[] to3D( int idx ) {
final int z = idx / (xMax * yMax);
idx -= (z * xMax * yMax);
final int y = idx / xMax;
final int x = idx % xMax;
return new int[]{ x, y, z };
}