OpenMP Parallel For Loop

此示例显示如何将循环划分为相等的部分并并行执行它们。

//    Splits element vector into element.size() / Thread Qty
//    and allocate that range for each thread.
#pragma omp parallel for
for    (size_t i = 0; i < element.size(); ++i)
    element[i] = ...

//    Example Allocation (100 element per thread)
//    Thread 1 : 0 ~ 99
//    Thread 2 : 100 ~ 199
//    Thread 2 : 200 ~ 299
//    ...

//    Continue process
//    Only when all threads completed their allocated
//    loop job
...

*请特别注意不要修改并行 for 循环使用的向量的大小,因为分配的范围索引不会自动更新