目前,我正在尝试将一个流程与我在网上找到的使用opencl的示例程序进行比较。然而,当我尝试计算这个过程时,我会得到非常奇怪的值,如下所示。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <CL/cl.h>
#include <time.h>
int main(void) {
int n = 100000;
size_t bytes = n * sizeof(double);
double *h_a;
double *h_b;
double *h_c;
h_a = (double*)malloc(bytes);
h_b = (double*)malloc(bytes);
h_c = (double*)malloc(bytes);
int i;
for(i = 0; i < n; i++)
{
h_a[i] = sinf(i)*sinf(i);
h_b[i] = cosf(i)*cosf(i);
}
clock_t start = clock();
for(i = 0; i < n; i++)
h_c[i] = h_a[i] + h_b[i];
clock_t stop = clock();
double time = (stop - start) / CLOCKS_PER_SEC;
printf("Clocks per Second: %E\n", CLOCKS_PER_SEC);
printf("Clocks Taken: %E\n", stop - start);
printf("Time Taken: %E\n", time);
free(h_a);
free(h_b);
free(h_c);
system("PAUSE");
return 0;
}
结果:
C:\MinGW\Work>systesttime
Clocks per Second: 1.788208E-307
Clocks Taken: 1.788208E-307
Time Taken: 0.000000E+000
Press any key to continue . . .
它为那里的一切提供了非常奇怪的价值。我明白它一定是大约1,000,000,我不知道为什么这样做。它过去常常为6E + 256的值提供同样关注的所有内容。
答案 0 :(得分:1)
看起来您的<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Web Roulette</title>
</head>
<body>
<p id="number" value=""> </p>
<form id="form3" name="form3" method="post" action="">
<label>
<input type="radio" name="rollSelection" value="0" id="rollSelection_0" />0
</label>
<br />
<label>
<input type="radio" name="rollSelection" value="1" id="rollSelection_1" />1
</label>
<br />
</form>
<form name="form2" method="post" action="" onsubmit="genNr(); return false">
<!--<label>Bet:
<input name="betInput" type="text" id="betInput" size="5" />
</label>//-->
<input type="submit" name="placeBet" id="placeBet" value="Roll" onclick="genNr();" />
<p id="roll">???</p>
<!--<p id="money">Money:</p>//-->
</form>
<script type="text/javascript">
var userBet = 0;
function genNr() {
if (document.getElementById('rollSelection_0').checked) {
userbet = 0;
} else if (document.getElementById('rollSelection_1').checked) {
userbet = 1;
}
document.getElementById('number').innerHTML = Math.floor(Math.random() * 2) + 0;
if (parseInt(document.getElementById('number').innerHTML) == userBet) {
document.getElementById('roll').innerHTML = "You Win!";
//document.getElementById('money').innerHTML = "Money: " + betInput * 2;
}
if (parseInt(document.getElementById('number').innerHTML) != userBet) {
document.getElementById('roll').innerHTML = "You Lost!";
}
}
</script>
</body>
</html>
不是双倍的,因此clock_t
是错误的格式说明符。
可能%E
。试试这个:
long