小编L. *_* F.的帖子

Eigen 中的多线程(未使用 OpenMP)

我在库中使用多线程时遇到问题Eigen。这是我的代码:

#include <QCoreApplication>
#include <iostream>
#include "Eigen/Core"
#include <QDebug>

using namespace Eigen;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    Eigen::setNbThreads(6);
    qDebug()  << Eigen::nbThreads( );

    int n = 1000;
    MatrixXd A = MatrixXd::Ones(n,n);
    MatrixXd B = MatrixXd::Ones(n,n);
    MatrixXd C = MatrixXd::Ones(n,n);
    C.noalias() += A*B;
    std::cout << C.sum() << "\n";


    return a.exec();
}
Run Code Online (Sandbox Code Playgroud)

无论我做什么Eigen::nbThreads( )总是返回 1 无论我使用什么数字Eigen::setNbThreads(6)!

我读到这里,但它实际上并没有清楚地说明我们如何在不存在的情况下实际Eigen以并行模式运行!OpenMP

我也做了很多搜索,但它们都与OpenMP!

刚刚发生了什么?是Eigen只支持OpenMP多线程还是也有内置的多线程?

提前致谢!

c++ parallel-processing qt multithreading eigen

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

为什么矢量会导致细分错误?

我想从Openssl制作随机数。

所以。我做了程序:

#include "openssl/rand.h"
struct randomData
{
     char str[32];
}

int main()
{
    std::vector<randomData> vecStr;
    randomData rd;
    vecStr.emplace_back(rd);

    RAND_bytes((unsigned char *)vecStr[i].str, sizeof(vecStr[i].str));

    std::string ss = to_hex(vecStr[i].str, sizeof(vecStr[i].str));
    std::cout << "Random Nonce Hex Data : " << ss << " // Key Length : " << ss.length()<<std::endl;

    return 0;
}
// [out put]
// Random Nonce Hex Data : f0f5e38e596fdb2f7cef79d3706fcbf111decaa844154295b89b90eb65925a53 // Key Length : 64
Run Code Online (Sandbox Code Playgroud)

但是我不想构造。只需使用vector即可。所以,我尝试了。

std::vector<char> str;
str.reserve(33);
RAND_bytes((unsigned char *)&str, sizeof(str));
std::string ss = to_hex((char*)&str, sizeof(str));
std::cout …
Run Code Online (Sandbox Code Playgroud)

c++ vector segmentation-fault

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

为什么 rand() 一直给出相同的值?

每次调用该函数时,总是“number = 5”。数字始终保持为 5。我已经检查过它以确保 srand 只运行一次,有些我很困惑。这是一个类内部的函数。

int playType::getComputerMove(){
    int number;
    if(gamesPlayed == 0){
        srand(time(NULL));
    }
    number = rand() % 1 + 5;
    return number;
}
Run Code Online (Sandbox Code Playgroud)

c++

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

为什么我遇到细分错误:此代码中为11

我的C ++代码有问题。我想将参数传递给我的代码,但有时它将为空。我的代码很简单。

#include <iostream>

int main(int argc, char **argv) {

  std::cout << argv[0] << std::endl;
  std::cout << argv[1] << std::endl;

}
Run Code Online (Sandbox Code Playgroud)

我想要的是在没有提供的情况下显示空参数。我得到的是

./main
Segmentation fault: 11
Run Code Online (Sandbox Code Playgroud)

c++

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

Which is the best way to yield thread?

Program language: C++ 11
I use pipeline threads mode to deal data.
One thread generate data.
One thread process data.
While no data to deal, which is the best way to yield thread?
Now I use

std::this_thread::sleep_for(100ms); 
Run Code Online (Sandbox Code Playgroud)
  1. I wonder if there is a better way to yield?
  2. If sleep is well enough, how long time to sleep is better?

c++ multithreading c++11

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

为什么“应使用 'empty' 方法来检查是否为空,而不是使用 clang-tidy 的 'size”?

执行检查时:

std::string st = "hello";
bool is_empty = st.size() > 0;
Run Code Online (Sandbox Code Playgroud)

我收到了上面提到的 Clang-Tidy 警告。

为什么最好使用该empty()方法?

c++ containers std stdvector clang-tidy

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

Template for constructor

I see one constructor of class so strange:

class HashTable
{
public:
    template <int N>
    HashTable(const char(&str)[N])

    {
    }
};
Run Code Online (Sandbox Code Playgroud)

Could you please explain it and some example or give me a related link? I really don't understand const char(&str)[N].

c++ c++11

-3
推荐指数
1
解决办法
66
查看次数

"和"之间的差异

我已经看到,如果我使用printf'foo',我会收到警告.

printf('numero');
Run Code Online (Sandbox Code Playgroud)

警告:字符常量太长,因为它的类型[默认启用]警告:传递'printf'的参数1使得指针来自整数而没有强制转换./usr/include/stdio.h:362:12:注意:预期'const char*restrict '但参数类型为'int'extern int printf(const char*__ restrict __format,...); 警告:格式不是字符串文字而没有格式参数[-Wformat-security]

当我使用时,""我没有得到任何警告printf("numero");

那么,''和之间的区别是""什么?

c

-6
推荐指数
3
解决办法
975
查看次数