#include<stdio.h>
#include<time.h>
#include<sys/time.h>
#include<omp.h>
#define PARALLEL 0
#define OMP_NUM_THREADS 24
void test();
int main(int argc,char *argv[])
{
//开始计时
printf("pragram start\n");
gettimeofday(&tpstart,NULL);
//设置OMP_NUM_THREADS个线程
#if PARALLEL
omp_set_num_threads(OMP_NUM_THREADS);
#endif // PARALLEL
//开始测试
#if PARALLEL
#pragma omp parallel for
#endif // PARALLEL
}
//计算运行时间
gettimeofday(&tpend,NULL);
printf("Total time = %ld ms\n\n", (tpend.tv_sec-tpstart.tv_sec)*1000+(tpend.tv_usec-tpstart.tv_usec)/1000);
return 0;
}
void test()
{
int i,a = 0;
for (i=0;i<300000000;i++)
a++;
#include<time.h>
#include<sys/time.h>
#include<omp.h>
#define PARALLEL 0
#define OMP_NUM_THREADS 24
void test();
int main(int argc,char *argv[])
{
int i,M=10;
struct timeval tpstart,tpend;
//开始计时
printf("pragram start\n");
gettimeofday(&tpstart,NULL);
//设置OMP_NUM_THREADS个线程
#if PARALLEL
omp_set_num_threads(OMP_NUM_THREADS);
#endif // PARALLEL
//开始测试
#if PARALLEL
#pragma omp parallel for
#endif // PARALLEL
for(i=0;i<M;i++)
{
test();}
//计算运行时间
gettimeofday(&tpend,NULL);
printf("Total time = %ld ms\n\n", (tpend.tv_sec-tpstart.tv_sec)*1000+(tpend.tv_usec-tpstart.tv_usec)/1000);
return 0;
}
void test()
{
int i,a = 0;
for (i=0;i<300000000;i++)
a++;
}