小编jop*_*rat的帖子

CUDA/OpenCL中的现实死锁示例

对于我正在编写的教程,我正在寻找一个"现实的"简单的例子,说明因无知SIMT/SIMD而造成的死锁.

我想出了这个片段,这似乎是一个很好的例子.

任何输入将不胜感激.

…
int x = threadID / 2;
if (threadID > x) {
    value[threadID] = 42;
    barrier();
    }
else {
    value2[threadID/2] = 13
    barrier();
}
result = value[threadID/2] + value2[threadID/2];
Run Code Online (Sandbox Code Playgroud)

我知道,既不是CUDA C也不是OpenCL C.

parallel-processing synchronization cuda simd opencl

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

推力结构矢量的迭代器

我试图以这种方式访问​​向量元素

struct point
{
    unsigned int x;
    unsigned int y;
};

...
thrust::device_vector<point> devPoints(hPoints.begin(), hPoints.end());

for(thrust::device_vector<point>::iterator iter = devPoints.begin(); iter != devPoints.end(); iter++) 
{
    std::cout << iter->x << " " << iter->y << " " << std::endl; (1)
}
Run Code Online (Sandbox Code Playgroud)

device_vector已正确初始化.我收到以下错误:

error: expression must have pointer type (at 1)
error: no suitable user-defined conversion from "const thrust::detail::normal_iterator<thrust::device_ptr<point>>" to "thrust::device_ptr<point>" exists
          detected during instantiation of "Pointer thrust::experimental::iterator_facade<Derived, Pointer, Value, Space, Traversal, Reference, Difference>::operator->() const [with Derived=thrust::detail::normal_iterator<thrust::device_ptr<point>>, Pointer=thrust::device_ptr<point>, Value=point, Space=thrust::detail::cuda_device_space_tag, Traversal=thrust::random_access_traversal_tag, Reference=thrust::device_reference<point>, Difference=ptrdiff_t]" …
Run Code Online (Sandbox Code Playgroud)

c++ iterator stl cuda thrust

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

C++对象构造函数通过const引用复制传递

当我将一个对象作为const引用传递给另一个对象时,是否有副本?我总是假设,因为我通过引用传递了对象,成员对象本身实际上是我传入的对象而不是副本.我做了一个测试程序,导致传入的引用对象在范围的末尾被销毁,但它没有像我预期的那样崩溃.这是一个等待发生的错误还是被复制的对象?

#include <iostream>
#include <string>

class Something
{
public:
    Something(const std::string& str) : mStr(str) {}
    const std::string& str() const
    {
        return mStr;
    }
private:
    std::string mStr;
};

int main()
{
    Something* something;
    {
        std::string temp = "Testing.";
        something = new Something(temp);
    }

    std::cout<<something->str()<<"\n";
    delete something;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

该std :: string是否仍然有效或被删除?(在对象本身)

c++ constructor copy const reference

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

C++:基类中的String参数在派生类解构时解构

我有一个名为A的基类,包含一个字符串类型参数.

B类派生自A.

我定义类C有参数A*a,并将其分配给B.

在main函数中,我无法获取基类的字符串值,因为它在b解构时变为空白.

我希望它输出:

"Hello!"
"Hello!"
end 
Run Code Online (Sandbox Code Playgroud)

但输出是:

"Hello!"

end
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

class A {
public:
    string str;
};

class B : public A {
public:
    B(string _str)  {
        str = _str;
    }
};

class C {
public:
    A *a;
public:
    void printOut() {
        B b("Hello!");
        a = &b;
        cout << a->str << endl;
    }
};

int main() {
    C c;
    c.printOut();
    cout << c.a->str << endl;
    cout << "end" << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我怎么处理它?

c++ string inheritance derived-class

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

Bash变量始终为空

以下bash脚本的结果是输出中的"空行"

ssh dev@my_service <<EOF
  START_SERVICE_TIME_IS_UP=124
  echo $START_SERVICE_TIME_IS_UP
  exit  
EOF
Run Code Online (Sandbox Code Playgroud)

无法理解为什么.我希望在输出中看到"124".远程服务器正在运行Red Hat linux.

linux bash heredoc

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