我试图弄清楚我在Haskell中遇到的一些性能问题.作为其中的一部分,我编写了一个小比较程序来比较C和Haskell.具体来说,我尽可能少地将C程序翻译成Haskell.然后,Haskell程序的速度测量部分以非常强制的方式编写.
程序在一定范围内生成两个随机数列表,然后通过简单地连接这些点来计算形成的图的积分,其中一个列表是x值,一个列表是y值.从本质上讲,它是梯形规则.
以下是两个代码:
main.c中
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 5000000
#define maxY 1e5f/N
#define maxXgap 1
int main(){
int i;
float *y, *x;
float xaccum, area;
clock_t begin, end;
double time_spent;
y = (float*)malloc(sizeof(float)*N);
x = (float*)malloc(sizeof(float)*N);
srand(50546345); // change seed for different numbers
//populate y and x fields with random points
for(i = 0; i < N; i++){
y[i] = ((float)rand())/((float)RAND_MAX)*maxY;
}
xaccum = 0;
for(i = 0; i < N; i++){
x[i] = …Run Code Online (Sandbox Code Playgroud) 我还没有在IE上测试它.
我想为我的网站上的搜索栏[死网站]设置背景图像和文本框形状以及边框的样式.
如果您在Firefox或Opera上访问它并看到左栏中的搜索栏,那就是我想要的.现在,如果您在Safari或Chrome上访问它,您应该会看到它被默认输入文本字段替换,这会使文本难以辨认.
即使在这些浏览器上,我如何设置文本框的样式?
我正在编写一个Python Web应用程序,其中我计划利用Wikipedia.在尝试一些URL提取代码时,我能够同时获取Google和Facebook(通过Google App Engine服务),但当我尝试获取wikipedia.org时,我收到了一个例外.任何人都可以确认维基百科不接受这些类型的页面请求吗?维基百科如何区分我和用户?
代码片段(它是Python!):
import os
import urllib2
from google.appengine.ext.webapp import template
class MainHandler(webapp.RequestHandler):
def get(self):
url = "http://wikipedia.org"
try:
result = urllib2.urlopen(url)
except urllib2.URLError, e:
result = 'ahh the sky is falling'
template_values= {
'test':result,
}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
Run Code Online (Sandbox Code Playgroud) 标题是问题的核心,但问题来自于我从SpaceSimulator.net的教程中获得的代码.我会在这里发给你的.
#include <stdio.h>
#include <stdlib.h>
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
typedef struct {
float x,y,z;
} vertex_type;
typedef struct {
int a,b,c;
} polygon_type;
#define MAX_POLYGONS 2000
polygon_type polygon[MAX_POLYGONS];
#define MAX_VERTICES 2000
vertex_type vertex[MAX_VERTICES];
typedef struct {
vertex_type vertex[MAX_VERTICES];
polygon_type polygon[MAX_POLYGONS];
} obj_type,*obj_type_ptr;
int screen_width, screen_height, filling;
GLfloat rotation_x_increment, rotation_y_increment, rotation_z_increment;
GLfloat rotation_x, rotation_y, rotation_z;
obj_type cube =
{
{
-10,-10, 10, //vertex v0
10,-10, 10, //vertex v1
10,-10,-10, //vertex v2
-10,-10,-10, //vertex v3
-10, 10, 10, //vertex v4 …Run Code Online (Sandbox Code Playgroud) 我一直有这些与Visual Studio 2010中非常奇怪的问题,在这一点上,行为是如此的不稳定,我真希望我没有使用它的CUDA(我知道我并不需要,但它很难不使用它).
我遇到的许多基本问题之一是头文件不止一次被包含在内.例如:
//vars.cuh
#if !defined(VARS_cuh)
#define VARS_cuh
#include <cuda.h>
#include <cuda_runtime_api.h>
int* kern_xstart, *kern_xend, *kern_ystart, *kern_yend, *kern_zstart, *kern_zend;
/* more variable definitions */
#endif
Run Code Online (Sandbox Code Playgroud)
然后我在大多数源文件中包含此文件:
//source_file.cu
extern "C"{
#include "vars.cuh"
/* more includes of my own headers */
#include <cuda.h>
#include <cuda_runtime_api.h>
}
/* source file body */
Run Code Online (Sandbox Code Playgroud)
VS 2010编译器发出如下错误:"错误LNK2005:foo已在other_source_file_I_wrote.cu.obj中定义"
它为什么这样做?另外,为了用一块石头杀死两只鸟,使用这种设置,我也有在source_file.cu中编写函数,然后在vars.cuh中进行原型设计的问题.问题是vars.cuh无法看到定义,即使我在source_file.cu中明确包含vars.cuh!
谢谢!
我正在写一个国际象棋引擎并获得伪随机移动,我传递一个移动生成函数和一个数组来填充.这是一些代码:
...
else if(pstrcmp(input, (char*)"check", 5)){
int checkIndex = getIndex(input[6], input[7] - 49);
printf("checkindex %i\n", checkIndex);
if(!(checkIndex < 0 || checkIndex > 127)){
//we've received a valid check
struct m mUn[MOVE_BUFF];
gen_psm(checkIndex, mUn);
int i = 0;
while(mUn[i].start != mUn[i].end && i < MOVE_BUFF){
printf("%s\n", GSQ(mUn[i].end));
i++;
}
}
}
Run Code Online (Sandbox Code Playgroud)
...
第一行只是一些输入检查.代码的内容在struct m mUn[MOVE_BUFF]while循环之间.所以我创建了一个struct m数组,我创建了一个数组,它包含一些指定特定移动的整数,然后我传递给它,gen_psm其中需要检查方形的索引和要填充的数组.它为数组填充了位于索引处的片段的有效移动.第一步,精致和花花公子.然后我尝试第二步,我发现数组从第一步开始仍然有数据,即使我已经退出了我声明它的mUn的范围.结构的某些性质是否会保留其数据?我是否需要填充整个事物(当我尝试它时似乎充满了0).如果我需要0填充它,是否有更快的方法(如果我必须0填充它几亿次,这是一个问题)?
我有一个简单的问题,我似乎无法在网上找到.
我正在使用CUDA做一些GPU工作,我需要在GPU上分配一些数据.cudaMalloc函数如下:
cudaMalloc(void** identifier, size_t space);
Run Code Online (Sandbox Code Playgroud)
很容易.所以,让我们分配一个整数.
int i = 5;
cudaMalloc((void**)&(&i), sizeof(int));
Run Code Online (Sandbox Code Playgroud)
但是这个错误("表达式必须是左值或函数指示符").明显的解决方法是声明i为开头的指针,然后获取它的地址,并且完全正常; 我只是讨厌变通办法.
我觉得这个问题应该有一个明显的答案-毕竟**,***即使**********在C.工作得很好,所以,我怎么得到一个变量的地址的地址"干净"?
谢谢!
I am setting up some framework for a little 2D game. Right now, I just have a few classes, but I am immediately falling into compiler problems.
I have run this program with only the main function, so I can confirm that the Allegro (graphics library) library linking has worked.
I have put all my header files (.h) under the "Header Files" section in the Solution explorer and all my source (.cpp) in the "Source Files" section. I have only …