openmp的g++并行执行

#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
void Test(int n) {
    for(int i = 0; i < 10000; ++i) {
    //do nothing, just waste time
    }   
    printf("%d, ", n);
}

int main(int argc,char* argv[]) {
    #pragma omp parallel for
    for(int i = 0; i < 10; ++i)
    Test(i);
}
 g++ openmp.cpp -fopenmp
0, 3, 6, 4, 9, 1, 7, 5, 2, 8,

原文地址:https://www.cnblogs.com/timssd/p/4810804.html