1

I'm new in "parallelization". I'm trying to parallelize an easy code to get a better performance, but I'm having very bad runtimes. here is the code:

#include<iostream>
#include<omp.h>
#include<cstdio>

using namespace std;
double omp_get_wtime(void);

int main(){
const double starttime = omp_get_wtime();
    #pragma omp parallel num_threads(10)
            {
            cout<<"sbam"<<endl;
            }
const double endtime = omp_get_wtime();
    cout << "work took time: " << endtime-starttime << " s"<<endl;
    cout << "work took time: " << (endtime-starttime)*1000000.00 << " mus"<<endl;
    return 0;
}

what am I doing wrong?? thank you!!

4

1 回答 1

1

控制台是独占资源,当 10 个线程想要同时使用它时,需要锁定!

那个补充。锁定会增加开销,这解释了您所看到的时间


顺便说一句,磁盘访问或更确切地说是任何专有/有限资源也是如此

于 2013-06-04T12:02:24.190 回答