学习如何使用 c++17 中的执行库。我正在使用 Linux,但也在我的 Mac 上尝试过。我收到此错误:
致命错误:找不到“执行”文件
当我在两个操作系统中编译时。
我宁愿坚持使用我输入的 linux:
g++ -g -std=c++17 ModuleDevelopmentStage13.cc -lboost_system -lboost_thread -pthread
也许我需要在-l....此处的参数中添加更多库。我是 C++ 的新手,不知道在哪里可以找到要添加的内容?我已经安装了 LLVM 并在类似的帖子上尝试了一些选项,但没有运气。有什么建议吗?
所以在我的 mac 上我做了 gcc -v 并得到:
gcc -v Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1 Apple LLVM version 10.0.0 (clang-1000.11.45.5) Target: x86_64-apple-darwin18.6.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
好的,更新 - 我现在切换到通过自制软件安装的 gcc-9.1。
没有像以前一样的“包含”错误,但是当我尝试编译使用 c++17 库的简单代码示例时,我现在遇到了这个问题:
g++-9 -std=c++17 example.cc
In file included from /usr/local/Cellar/gcc/9.1.0/include/c++/9.1.0/pstl/parallel_backend.h:14,
from /usr/local/Cellar/gcc/9.1.0/include/c++/9.1.0/pstl/algorithm_impl.h:25,
from /usr/local/Cellar/gcc/9.1.0/include/c++/9.1.0/pstl/glue_execution_defs.h:52,
from /usr/local/Cellar/gcc/9.1.0/include/c++/9.1.0/execution:3,
from example.cc:6:
/usr/local/Cellar/gcc/9.1.0/include/c++/9.1.0/pstl/parallel_backend_tbb.h:19:10 fatal error: tbb/blocked_range.h: No such file or directory …
我只是在学习如何std::thread在c ++ 11中使用。基本上,我使用的硬件中有很长的数据列表(想象一下0-15000之间的for循环)和1568线程。我想要一个单独的线程来处理每个样本。我了解如何创建第一个1568线程,它工作正常。但是一旦到达N_thread + 1示例,我便要检查是否有可用线程。如果存在,则将该数据样本发送到该线程。每个线程都发送到互斥锁功能,该功能最后会解锁。也许我误解了线程是如何工作的,不能以这种方式做事?也许有更好的线程/ CPU分配库可以提供帮助?
就像我说的那样,我可以说创建了1568个线程,然后运行并加入它们,最终结果很好。只需要更多信息。
这是我的主要
int main(){
cout<<"In main"<<endl;
CSVReaderUpdatedStructure reader("data.csv");
vector<STMDataPacket> DataList = reader.GetData();
thread_pool Pool(THREAD_COUNT);
auto startT0 = chrono::high_resolution_clock::now();
for(unsigned s=0; s<DataList.size()-1; s++){
cout<<"analysing sample "<<s<<endl;
auto done = Pool.add_task([s= s, Sample= DataList[s], t_inf = time_info,wf=writefile, f=factor]{GetDMWPulses(s, Sample, t_inf, wf,f);});
done.wait();
}
auto stop = chrono::high_resolution_clock::now();
cout<<"pulses "<<pulses.size()<<endl;
auto duration = chrono::duration_cast<chrono::microseconds>(stop - startT0);
cout <<"time for MWD full process = "<< duration.count() <<" microseconds "<< endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)