小编Zif*_*ong的帖子

在zsh中,"local -a foo"是什么意思?

Zsh手册提到选项-a意味着ALL_EXPORT,

ALL_EXPORT (-a, ksh: -a)

  All parameters subsequently defined are automatically exported.  
Run Code Online (Sandbox Code Playgroud)

虽然export使变量可用于子流程,但同一个变量如何foo是本地的?

shell zsh

13
推荐指数
2
解决办法
3689
查看次数

C++模板的朋友操作符重载

我的代码出了什么问题?

template<int E, int F>
class Float
{
 friend Float<E, F> operator+ (const Float<E, F> &lhs, const Float<E, F> &rhs);
};
Run Code Online (Sandbox Code Playgroud)

G ++只是警告:

float.h:7: warning: friend declaration ‘Float<E, F> operator+(const Float<E, F>&, const Float<E, F>&)’ declares a non-template function

float.h:7: warning: (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here) -Wno-non-template-friend disables this warning

我试着add <> after the function name here在警告说明中提到,但是g ++给了我一个错误.

我用clang …

c++ templates operator-overloading friend

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

CPU缓存对速度的影响

我刚刚写了一个程序来测试CPU缓存对速度性能的影响.

void* foo(void* ptr)
{
    int* r = (int*) ptr;

    for (int i = (r - s); i < N; i += NUM_THREADS)
        *r += num[i];        
    return NULL;
}

void* bar(void* ptr)
{
    int* r = (int*) ptr;
    int idx = r - s;
    int block = N/NUM_THREADS;
    int start = idx * block, end = start + block;

    for (int i = start; i < end; ++i)
        *r += num[i];        
    return NULL;
}
Run Code Online (Sandbox Code Playgroud)

基本上,foo()另一方面,隔行扫描bar()是逐块扫描阵列.

测试结果表明 …

c optimization caching pthreads cpu-architecture

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

“ linux-2.6.3x.x / include / asm-generic /”的作用是什么?

我的操作系统手册上说,如果要向Linux内核添加系统调用,请编辑linux-2.x/include/asm-i386/unistd.h

但是linux内核的源代码结构似乎发生了很大变化。在linux-2.6.34.1版本内核源代码树中,我仅找到linux-2.6.34.1/include/asm-generic/unistd.hlinux-2.6.34.1/arch/x86/include/asm/unistd.h

似乎编辑后一个更有意义。

我的问题是什么/inlcude/asm-generic用?与asm相关的代码如何通用?

linux kernel linux-kernel

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

这种红宝石注射魔法是如何起作用的?

我今天看到了一个ruby代码片段.

[1,2,3,4,5,6,7].inject(:+)  
Run Code Online (Sandbox Code Playgroud)

=> 28

[1,2,3,4,5,6,7].inject(:*)  
Run Code Online (Sandbox Code Playgroud)

=> 5040

这里的注射与我之前看到的完全不同,比如

[1,2,3,4,5,6,7].inject {|sum, x| sum + x}
Run Code Online (Sandbox Code Playgroud)

请解释它是如何工作的?

ruby

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

CUDA上的块间障碍

我想在CUDA上实现Inter-block障碍,但遇到了严重的问题.

我无法弄清楚为什么它不起作用.

#include <iostream>
#include <cstdlib>
#include <ctime>

#define SIZE 10000000
#define BLOCKS 100 

using namespace std;

struct Barrier {
    int *count;

    __device__ void wait() {
        atomicSub(count, 1);
        while(*count)
            ;
    }

    Barrier() {
        int blocks = BLOCKS;
        cudaMalloc((void**) &count, sizeof(int));
        cudaMemcpy(count, &blocks, sizeof(int), cudaMemcpyHostToDevice);
    }

    ~Barrier() {
        cudaFree(count);
    }
};


__global__ void sum(int* vec, int* cache, int *sum, Barrier barrier)
{
    int tid = blockIdx.x;

    int temp = 0;
    while(tid < SIZE) {
        temp += vec[tid];
        tid += gridDim.x;
    } …
Run Code Online (Sandbox Code Playgroud)

c cuda gpgpu nvidia

5
推荐指数
2
解决办法
5649
查看次数

是否可以在scala中重载构造函数?

我的问题是,如果可以在scala中重载构造函数?

所以我可以编写如下代码:

var = new Foo(1)
var = new Foo("bar")
Run Code Online (Sandbox Code Playgroud)

如果不可能,有没有相同的技巧?

overriding scala

3
推荐指数
2
解决办法
5174
查看次数