我正在尝试为我的OpenCl / GL流体创建一个3d网格。我遇到的问题是由于某种原因我的网格初始化功能无法正常工作。这是我的* .h,* .c设置和(在最后)调用main:
(grid.h):
#if RunGPU
#define make_float3(x,y,z) (float3)(x,y,z)
#define make_int3(i,j,k) (int3)(i,j,k)
#else
typedef struct i3{
int i,j,k;
} int3;
typedef struct f3{
float x,y,z;
} float3;
#define __global
#define make_float3(x,y,z) {x , y , z}
#define make_int3(x,y,z) {x , y ,z}
#endif
typedef struct grid3 * grid3_t; // u,v,w
typedef struct grid * grid_t; // p
struct grid3 {
__global float3* values_;
__global float * H_;
__global float * h_;
int dimx_;
int dimy_;
int dimz_;
} ;
struct grid {
__global float * values_;
int dimx_;
int dimy_;
int dimz_;
};
void grid3_init(grid3_t grid,__global float3* vel,__global float* H,__global float *h, int X, int Y, int Z);
(grid.c):
void grid3_init(grid3_t grid,__global float3* val,__global float* H,__global float *h, int X, int Y, int Z){
grid->values_ = val;
grid->H_ = H;
grid->h_ = h;
grid->dimx_ = X;
grid->dimy_ = Y;
grid->dimz_ = Z;
}
主要即时初始化我的网格:
int main(int argc, char** argv)
{
const int size3d = Bx*(By+2)*Bz;
const int size2d = Bx*Bz;
float3 * velocities = (float3*)malloc(size3d*sizeof(float3));
float * H = (float*)malloc(size2d*sizeof(float));
float * h = (float*)malloc(size2d*sizeof(float));
for(int i = 0; i < size3d; i++){
float3 tmp = make_float3(0.f,0.f,0.f);
velocities[i] = tmp;
if(i < size2d){
H[i] = 1;
h[i] = 2;
}
}
grid3_t theGrid;
grid3_init(theGrid, velocities, H, h, Bx, By, Bz); // <- ERROR OCCURS HERE
}
错误即时获取是在运行时 - “运行时检查失败#3 - 变量'theGrid'正在使用而未初始化”。但这正是grid3_init的工作?
当我试图编写代码来为主机和GPU工作时,我不得不牺牲类的使用并严格使用结构 - 我对它的经验较少。
此时我也不知道该怎么去谷歌,我赞赏我能得到的任何帮助。
答案 0 :(得分:1)
struct grid3 theGrid;
grid3_init(&theGrid, velocities, H, h, Bx, By, Bz);
您需要创建grid3
实例并将其指针传递给grid3_init
。您现有的代码只使用未初始化的指针。