我正在研究一个函数来转置一个NxN存储在floats 数组中的矩阵.我的第一个实现似乎导致函数无限循环,我似乎无法弄清楚为什么.这是原始代码:
for(int i = 0; i < numRows % 2 == 0 ? numRows / 2 : numRows / 2 + 1; i++)
{
for(int j = i + 1; j < numColumns; j++)
{
//Swap [i,j]th element with [j,i]th element
}
}
Run Code Online (Sandbox Code Playgroud)
但是函数永远不会返回.在我的逻辑中没有看到错误我改写了表达式,现在有了以下工作代码:
int middleRow = numRows % 2 == 0 ? numRows / 2 : numRows / 2 + 1;
for(int i = 0; i < middleRow; i++)
{
for(int j = i …Run Code Online (Sandbox Code Playgroud) c for-loop ternary-operator infinite-loop operator-precedence
我正在使用OpenCL/OpenGL Interop开发一个基本的光线跟踪器.我在内核中存在一些问题,这些内核共享工作组内共享的本地内存.
这是内核:
__kernel void ComputeDirectionalShadowTexture(
write_only image2d_t shadowTexture,
read_only image2d_t positionTexture,
__constant float3* lightDirection, __constant float4* spheres,
)
{
__local bool* shadowReduce[2];
__local size_t idX, idY, idZ, localID;
idX = get_global_id(0);
idY = get_global_id(1);
idZ = get_global_id(2);
localID = get_local_id(2);
//...Read Textures
//...Perform Computation
//...Write results
if(shadowReduce[localID])
write_imagef(shadowTexture, threadCoord.xy, (float4)(1.0f, 0.0f, 0.0f, 1.0f));
}
Run Code Online (Sandbox Code Playgroud)
运行此时,就好像get_local_id()函数永远不会返回0(或只返回1).
我希望问题与我调用内核的方式有关:
size_t numGlobal[3] =
{
rBuffer->textureWidth,
rBuffer->textureHeight,
numSpheres
};
size_t numLocal[3] = { 1, 1, numSpheres};
cl_event execution;
//Execute kernel
clError = clEnqueueNDRangeKernel
( …Run Code Online (Sandbox Code Playgroud)