小编hew*_*ewy的帖子

为什么我的8M L3缓存不能为大于1M的阵列带来任何好处?

我受到这个问题的启发,编写了一个简单的程序来测试我的机器在每个缓存级别的内存带宽:

为什么矢量化循环没有性能改进

我的代码使用memset反复写入缓冲区(或缓冲区)并测量速度.它还保存了最后打印的每个缓冲区的地址.这是列表:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>

#define SIZE_KB {8, 16, 24, 28, 32, 36, 40, 48, 64, 128, 256, 384, 512, 768, 1024, 1025, 2048, 4096, 8192, 16384, 200000}
#define TESTMEM 10000000000 // Approximate, in bytes
#define BUFFERS 1

double timer(void)
{
    struct timeval ts;
    double ans;

    gettimeofday(&ts, NULL);
    ans = ts.tv_sec + ts.tv_usec*1.0e-6;

    return ans;
}

int main(int argc, char **argv)
{
    double *x[BUFFERS];
    double t1, t2;
    int kbsizes[] = SIZE_KB;
    double bandwidth[sizeof(kbsizes)/sizeof(int)];
    int …
Run Code Online (Sandbox Code Playgroud)

c c++ optimization performance cpu-cache

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

c ++ undefined对头文件外定义的成员函数的引用

我的印象是,您可以在一个文件中定义类的成员函数,然后在另一个文件中使用这些函数,只要这两个文件都被编译并发送到链接器即可.但是,如果我使用g ++(4.6.4),这样做会给我一个未定义的引用错误.有趣的是,使用intel编译器(icpc 11.0)不会出错,一切正常.是否有一些我可以用g ++设置的标志来使这个工作,或者是英特尔编译器让我逃避我不应该做的事情?以下是一些可以重现我的问题的代码:

class.h:

#ifndef _H
#define _H

typedef class
{
    public:
            int a;
            int b;

            void set(int x, int y);
            int add(void);
} Test;

#endif
Run Code Online (Sandbox Code Playgroud)

class.cpp:

#include "class.h"

void Test::set(int x, int y)
{
    a = x;
    b = y;
}

int Test::add(void)
{
    return a+b;
}
Run Code Online (Sandbox Code Playgroud)

main.cpp中:

#include <cstdio>
#include "class.h"

int main(void)
{
    Test n;
    n.set(3, 4);
    printf("%d\n", n.add());

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

为了编译,我做:

$ g++ class.cpp main.cpp -o test 
/tmp/ccRxOI40.o: In function `main':
main.cpp:(.text+0x1a): undefined reference …
Run Code Online (Sandbox Code Playgroud)

c++ g++ class member-functions undefined-reference

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