📄 负载平衡.cpp
字号:
// 负载平衡.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include"omp.h"
#include <windows.h>
void smallwork()
{
}
void bigwork()
{
_int64 sum = 0;
for(int i = 0; i < 100000000; i++)
sum += i;
}
int _tmain(int argc, _TCHAR* argv[])
{
_int64 counter_begin;
_int64 counter_end;
_int64 diff1,diff2,diff3;
QueryPerformanceCounter((LARGE_INTEGER*)&counter_begin);
for(int i = 0; i < 100; i++)
{
if(i < 50)
smallwork();
else
bigwork();
}
QueryPerformanceCounter((LARGE_INTEGER*)&counter_end);
diff1 = counter_end - counter_begin;
printf("count = %I64d\n",diff1);
QueryPerformanceCounter((LARGE_INTEGER*)&counter_begin);
#pragma omp parallel for
for(int i = 0; i < 100; i++)
{
if(i < 50)
smallwork();
else
bigwork();
}
QueryPerformanceCounter((LARGE_INTEGER*)&counter_end);
diff2 = counter_end - counter_begin;
printf("count = %I64d\n",diff2);
QueryPerformanceCounter((LARGE_INTEGER*)&counter_begin);
#pragma omp parallel for
for(int i = 0; i < 100; i++)
{
if(i % 2)
smallwork();
else
bigwork();
}
QueryPerformanceCounter((LARGE_INTEGER*)&counter_end);
diff3 = counter_end - counter_begin;
printf("count = %I64d\n",diff3);
//double r;
//r = (double)diff1/(double)diff3;
//printf("Accelerate = %I64d\n",r);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -