日期:2014-05-20  浏览次数:21248 次

#pragma omp parallel for 导致程序线程数增加
在用了 #pragma omp parallel for ,设置num_threads 为2后, 
程序的线程数不断增加, 内存数也不断增加,

为什么会有这种情况呢?

C/C++ code

#pragma omp parallel for shared(elementIndexToBoundsSet, elementIndexToSizeSet, bufferPtr) private(currentCoord) firstprivate(elementIndex, threadId) num_threads(numOfThreads)
    for (int i = 0; i < bufferSize; i++)
    {
        // Get element index
        elementIndex = bufferPtr[i];

        // In case no element - continue
        if (elementIndex == 0)
            continue;

        // One time read of the threadId
        if (threadId == -1)
            threadId = omp_get_thread_num();
        
        // Update element size
        elementIndexToSizeSet->at(threadId)->at(elementIndex)++;
    }



------解决方案--------------------
我也想知道