小编Jia*_* Xu的帖子

如何解除 Ninja 对并行链接作业的限制?

我在 Debian 9 上使用 Ninja 1.8.2 来使用 llvm-5.0 构建 llvm-6.0。

当我检查系统的CPU使用率时,我发现CPU并没有100%使用,而且还有足够的内存。

检查 cmake 的输出后,我发现它将并行链接作业限制为 2 个,因为在我的机器上运行的 llvm 也是并行运行的。

我想尝试解除该限制是否会使我的构建速度更快,但几乎没有任何相关文档。

编辑:

我检查了构建目录中的rules.ninja 文件的内容,并发现了这些:

#############################################
# Pools defined by global property JOB_POOLS

pool link_job_pool
  depth = 2
Run Code Online (Sandbox Code Playgroud)

我还检查了 build.ninja 的内容并发现了这一点:

build lib/libLLVMDemangle.a: CXX_STATIC_LIBRARY_LINKER__LLVMDemangle lib/Demangle/CMakeFiles/LLVMDemangle.dir/ItaniumDemangle.cpp.o
  LANGUAGE_COMPILE_FLAGS = -Ofast -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -std=c++1y -Wal       l -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -W       non-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fcolor-diagnostics -ffunction-sections -fdata-sections -flto=thin -O3 -D       NDEBUG
  OBJECT_DIR = lib/Demangle/CMakeFiles/LLVMDemangle.dir
  POST_BUILD = :
  PRE_LINK = : …
Run Code Online (Sandbox Code Playgroud)

ninja

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

在启用JIT的情况下,编译的R代码实​​际上比纯R慢

从Efficient R编程字节编译器和R docment r字节编译器,我了解到cmpfun可以用来将纯R函数编译成字节代码以加速并enableJIT通过启用just-in-time编译来加速.

所以,我决定像我自己使用以下代码的第一个链接那样做基准测试:

library("compiler")
library("rbenchmark")

enableJIT(3)

my_mean = function(x) {
    total = 0
    n = length(x)
    for (each in x)
        total = total + each
    total / n
}

cmp_mean = cmpfun(my_mean, list(optimize = 3))

## Generate some data
x = rnorm(100000)
benchmark(my_mean(x), cmp_mean(x), mean(x), columns = c("test", "elapsed", "relative"), order = "relative", replications = 5000)
Run Code Online (Sandbox Code Playgroud)

不幸的是,结果与第一个链接所显示的不同.性能my_mean甚至比cmp_mean:

         test …
Run Code Online (Sandbox Code Playgroud)

jit bytecode r microbenchmark

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

boost :: container :: allocator_traits :: is_partially_propagable是什么意思?

当我遇到boost :: container :: allocator_traits :: is_partially_propagable时,我想了解boost :: container :: allocator_traits.

我在网上找不到任何关于它的文档,我可以理解除了is_partially_propagable和storage_is_unpropagable之外的所有其他boost :: container :: allocator_traits成员.

编辑:

并且,在编写容器时如何实现它们以及如何使用它们?

c++ boost boost-container

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

为什么我不能添加&&到Ret(Args ...)&?

当我试图写decay_t这样的时候:

#include <utility>
template <class T>
struct auto_decay {
    auto operator () () noexcept {
        return std::declval<T>();
    }
};

template <class T> using decay_t = decltype( (decl_as<decay_impl::auto_decay< T >>())() );
Run Code Online (Sandbox Code Playgroud)

并使用以下方法测试:

#include <type_traits>
int main() {
    static_assert(is_same<decay_t<int ()&>, int (*)()>{}());
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

In file included from test_decay.cc:1:
In file included from ./../src/decay.hpp:4:
In file included from ./../src/utility.hpp:3:
./../src/add_reference.hpp:17:14: error: reference to function type 'int () &' cannot have '&' qualifier
    typedef T&& type;
             ^
./../src/add_reference.hpp:20:1: note: in instantiation …
Run Code Online (Sandbox Code Playgroud)

c++ types function

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

当分配失败时,C++ allocator :: allocate应该抛出还是返回nullptr?

该分配器的概念和标准:: allocator_traits不说什么allocate时候分配失败,会做-将它返回nullptr或抛出?

当我使用标准分配器API编写容器时,我应该

  1. 检查返回值并捕获noexcept版本成员函数中的异常(例如push_back,resize...);

  2. 检查返回值,如果在抛出异常中失败则抛出

所以无论它是否抛出,我都会得到正确的行为.

c++ std allocator

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

编译器生成的汇编文件中的“#APP”是什么意思?

我写了以下代码:

// a.c
#include <stdlib.h>
#include <sys/syscall.h>
#include <unistd.h>

_Noreturn void _start()
{
    register int syscall_num asm ("rax") = __NR_exit;
    register int exit_code   asm ("rdi") = 0;

    // The actual syscall to exit
    asm volatile ("syscall"
        : /* no output Operands */
        : "r" (syscall_num), "r" (exit_code));
}
Run Code Online (Sandbox Code Playgroud)

然后使用clang-7 -Oz -pipe -flto -c a.c并使用llc-7 -filetype=asm a.o将其编译为人类可读的汇编文件a.o.s:

    .text
    .file   "a.c"
    .globl  _start                  # -- Begin function _start
    .type   _start,@function
_start:                                 # @_start
    .cfi_startproc
# %bb.0: …
Run Code Online (Sandbox Code Playgroud)

c assembly gcc directive inline-assembly

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

如何告诉编译器在_Noreturn函数中内联asm后不生成"retq"?

我写了下面的代码来调用syscall exit而不用glibc链接:

// a.c
#include <stdlib.h>
#include <sys/syscall.h>
#include <unistd.h>

_Noreturn void _start()
{
    register int syscall_num asm ("rax") = __NR_exit;
    register int exit_code   asm ("rdi") = 0;

    // The actual syscall to exit
    asm volatile ("syscall"
        : /* no output Operands */
        : "r" (syscall_num), "r" (exit_code));
}
Run Code Online (Sandbox Code Playgroud)

的Makefile:

.PHONY: clean

a.out: a.o
    $(CC) -nostartfiles -nostdlib -Wl,--strip-all a.o

a.o: a.c
    $(CC) -Oz -c a.c

clean:
    rm a.o a.out
Run Code Online (Sandbox Code Playgroud)

我用make它CC=clang-7并且它工作得很好,除了当我检查生成的组件时objdump -d a.out …

c assembly inline-assembly noreturn

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

在Python 3解释器模式下粘贴代码时出现IndentationError

当我运行以下代码时,这些代码在函数内部具有空白行(无空格),在解释器模式下逐行运行代码时,我得到的行为与Python 3.6.5不同python3 split.py:

# File split.py

def find(s, start, predictor):
    for i in range(start, len(s)):
        if predictor(s[i]):
            return i
    return -1

def find_all(s, sep=" \t\n"):
    beg_of_nonsep = 0
    while beg_of_nonsep < len(s):
        beg_of_nonsep = find(s, beg_of_nonsep, lambda ch, sep_chs=sep: ch not in sep_chs)
        if beg_of_nonsep == -1:
            break

        end_of_nonsep = find(s, beg_of_nonsep + 1, lambda ch, sep_chs=sep: ch in sep_chs)
        if end_of_nonsep == -1:
            end_of_nonsep = len(s)

        yield (beg_of_nonsep, end_of_nonsep)

        beg_of_nonsep = end_of_nonsep + 1

split = lambda …
Run Code Online (Sandbox Code Playgroud)

python

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

在C/C++中通过指针调用函数时,编译器如何正确处理ABI?

编译器如何知道函数指针指向的函数的ABI?

在计算机软件中,应用程序二进制接口(ABI)是两个程序模块之间的接口.

因为在C/C++中,函数指针只指定API,不知道它实际使用的是哪种ABI,这对编译器来说不是一个问题,特别是当他们无法静态地解决这个问题时?

这是否意味着使用这种指针的程序员需要手动指定调用约定?

如果是这样,怎么办?任何人都可以给我一些关于这个编译器文档的链接吗?

c c++ function-pointers function

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

T :: T(T&)有什么用?

为什么会出现T::T(T&)时,有T::T(const T&)哪个更适合copy?

(可能它用于实现move语义???)

原始描述(证明是错误的melpomene):

在C++11,支持一种新形式的复制构造函数T::T(T&)(来自cppreferene/Copy构造函数隐式声明的复制构造函数),我想知道它的实际用途是什么?

c++ constructor

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