这两者有什么区别吗?还是我的安全,以取代所有出现boost::bind的std::bind在我的代码,从而消除对加速的依赖?
问题
我们有一个用于模拟任务的中型程序,我们需要对其进行优化.我们已经尽最大努力优化我们的编程技能,包括使用Gprof和Valgrind进行分析.
最后完成后,我们希望在几个系统上运行该程序可能已有几个月了.因此,我们真的很有兴趣将优化推向极限.
所有系统都将在相对较新的硬件(Intel i5或i7)上运行Debian/Linux.
问题
使用最新版本的g ++有哪些可能的优化选项,超出-O3/-Ofast?
我们也对昂贵的小优化感兴趣,从长远来看,这将是非常重要的.
我们现在用的是什么
现在我们使用以下g ++优化选项:
-Ofast:最高"标准"优化级别.包含-ffast-math在我们的计算中没有引起任何问题,因此我们决定采用它,尽管非标准符合性.-march=native:启用所有CPU特定指令.-flto 允许跨不同编译单元的链接时间优化.是否有C++ 11等效的boost::shared_mutex.或者在C++ 11中处理多个读者/单个写入者情况的另一个解决方案?
我想要的只是以毫秒为单位获取纪元以来的时间并将其存储在无符号长整数中.
我发现了这个相关的问题.但老实说,这不是执行这么简单任务的最简单方法,是吗?我希望更简单的东西,但在std :: chrono引用中找不到任何东西.任何建议都是最受欢迎的.我不一定要使用std::chrono,但我希望它与平台无关.
是否有适用于Linux的TextMate替代方案?
类似于e-TextEditor for Windows
在我的Makefile中,我需要获取其他目录中存在的所有目录的列表.
要获取与Makefile我使用的文件夹相同的所有目录的列表:
DIRECTORIES = $(wildcard */)
all:
echo $(DIRECTORIES)
Run Code Online (Sandbox Code Playgroud)
哪个工作正常,并给我所需的清单.但是,如果我想要使用另一个目录中的所有目录的列表
DIRECTORIES = $(wildcard ../Test/*/)
all:
echo $(DIRECTORIES)
Run Code Online (Sandbox Code Playgroud)
我得到的所有文件(路径)在该目录中,包括列表.h和.cpp文件.
任何建议为什么会发生这种情况以及如何解决它?其他获得该清单的解决方案也是受欢迎的.
我试图在g ++中启用链接时间优化.没有-flto选项,我的程序编译正常.当我将它添加到我的Makefile时,目标文件编译没有错误,例如
g++ main.cpp -I ../includes -std=c++0x -fopenmp -Wall -pedantic -Wno-vla -flto -D INFO_ -c -o .obj/main.o
Run Code Online (Sandbox Code Playgroud)
但是当谈到链接程序时:
g++ -fwhole-program -I ../includes -std=c++0x -fopenmp -Wall -pedantic -Wno-vla -flto -D INFO_ .obj/main.o .obj/atom.o .obj/bee.o .obj/colony.o ../includes/.obj/error.o ../includes/.obj/CmdLine.o ../includes/boost_lib_deb/libboost_program_options.a ../includes/gmp_lib_deb/lib/libgmpxx.a ../includes/gmp_lib_deb/lib/libgmp.a -o BeeBench
Run Code Online (Sandbox Code Playgroud)
我收到很多这样的错误:
includes/gmp_lib_deb/lib/libgmpxx.a ../includes/gmp_lib_deb/lib/libgmp.a -o BeeBench
`typeinfo for boost::program_options::too_many_positional_options_error' referenced in section `.rodata._ZTVN5boost15program_options33too_many_positional_options_errorE[vtable for boost::program_options::too_many_positional_options_error]' of ../includes/boost_lib_deb/libboost_program_options.a(cmdline.o): defined in discarded section `.gnu.linkonce.t._ZTIN5boost15program_options33too_many_positional_options_errorE' of .obj/main.o (symbol from plugin)
`typeinfo for boost::program_options::too_many_positional_options_error' referenced in section `.rodata._ZTIN5boost16exception_detail19error_info_injectorINS_15program_options33too_many_positional_options_errorEEE[typeinfo for boost::exception_detail::error_info_injector<boost::program_options::too_many_positional_options_error>]' of ../includes/boost_lib_deb/libboost_program_options.a(cmdline.o): …Run Code Online (Sandbox Code Playgroud) 我需要找到模式exe/dll构建查看其标题.[edit]只使用c ++而无需任何外部工具.[/ edit]
有一个旧的讨论如何确定在发布或调试模式下构建的DLL. http://forums.codeguru.com/archive/index.php/t-485996.html
但不幸的是,我没有找到任何明确的答案.
我编写了以下模板函数,它检查仲裁容器是否包含特定元素:
template<template<class, class...> class container_t, class item_t, class... rest_t>
bool contains(const container_t<item_t, rest_t...> &_container, const item_t &_item) {
for(const item_t &otherItem : _container) {
if(otherItem == _item) { return true; }
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
这适用于大多数容器.然而,对于所有类型的集合(和地图),它是次优的,因为我们可以使用:
template<template<class, class...> class set_t, class item_t, class... rest_t>
bool contains(const set_t<item_t, rest_t...> &_set, const item_t &_item) {
return _set.count(_item) > 0;
}
Run Code Online (Sandbox Code Playgroud)
显然,由于含糊不清,我们不能同时使用这两个模板.现在我正在寻找一种方法,用于std::enable_if启用第一个模板,如果container_t不提供count成员函数,第二个模板,如果它没有.但是我无法弄清楚如何检查特定成员函数(使用C++ 11).
在这个博客中,我找到了一个非常巧妙的例子,说明如何使用boost :: asio创建一个简单的线程池.我基本上想要像这样使用它:
#include <thread>
#include <functional>
#include <boost/asio.hpp>
int main ( int argc, char* argv[] ) {
asio::io_service io_service;
asio::io_service::work work(io_service);
std::vector<std::thread> threadPool;
for(size_t t = 0; t < std::thread::hardware_concurrency(); t++){
threadPool.push_back(thread(std::bind(&asio::io_service::run, &io_service)));
}
io_service.post(std::bind(an_expensive_calculation, 42));
io_service.post(std::bind(a_long_running_task, 123));
//Do some things with the main thread
io_service.stop();
for(std::thread& t : threadPool) {
t.join();
}
}
Run Code Online (Sandbox Code Playgroud)
据我所知,Boost :: asio主要用于网络IO.但是,我主要想将它用于通用功能.将使用并发问题asio::io_service::strand.
所以我的问题:创建这样的线程池是一个好主意,即使我的程序不使用网络IO?与其他线程池实现相比,是否存在明显的性能损失?如果是这样,那么还有更好的实现吗?