小编Tre*_*als的帖子

openCL 内核计算 Pi 的值不正确

再会,

我有一个 openCL 内核,它使用莱布尼茨公式来计算 pi。目前我的问题是我得到的值不是 pi,而是 4。

__kernel void calculatePi(int numIterations, __global float *outputPi,
                          __local float* local_result, int numWorkers)
{
    __private const uint gid = get_global_id(0);
    __private const uint lid = get_local_id(0);
    __private const uint offset = numIterations*gid*2; 
    __private float sum = 0.0f;

    // Have the first worker initialize local_result
    if (gid == 0)
    {
        for (int i = 0; i < numWorkers; i++)
        {
            local_result[i] = 0.0f;
        }
    }

    // Have all workers wait until this is completed
    barrier(CLK_GLOBAL_MEM_FENCE); …
Run Code Online (Sandbox Code Playgroud)

c kernel for-loop pi opencl

2
推荐指数
1
解决办法
385
查看次数

警告修复后将初始化

晚上好(感恩节快乐),

我有以下代码(从我的主代码中摘录到一个独立的文件中),并且收到一些我想解决的警告消息。

这是代码:

#include <cassert>
#include <ostream>
#include <climits>
#include <iostream>
#include <string>

using namespace std;

class WordCount
{
public:
   // Constructors
   WordCount() : word(""), count(0) { }
   WordCount(string theWord, unsigned theCount = 1) : word(theWord), count(theCount) { }

   // Accessors
   string Word() const { return word; }
   unsigned Count() const { return count; }

   // Mutator
   void Update() { ++count; }

   // Output a Word to a stream.
   void Show(ostream &os)  { os << word << "=" << count; …
Run Code Online (Sandbox Code Playgroud)

c++ warnings initialization class

1
推荐指数
1
解决办法
1758
查看次数

标签 统计

c ×1

c++ ×1

class ×1

for-loop ×1

initialization ×1

kernel ×1

opencl ×1

pi ×1

warnings ×1