How to get a stack trace for C++ using gcc with line number information?

We use stack traces in proprietary assert like macro to catch developer mistakes - when error is caught, stack trace is printed. I find gcc's pair backtrace() / backtrace_symbols() methods insufficient: Names are mangled No line information 1st problem can be resolved by abi::__cxa_demangle. However 2nd problem s more tough. I found replacement for backtrace_symbols(). This is bet

如何使用gcc和行号信息获取C ++的堆栈跟踪?

我们在像宏这样的专有assert使用堆栈跟踪来捕捉开发人员的错误 - 当发现错误时,会打印堆栈跟踪。 我发现gcc的对backtrace() / backtrace_symbols()方法不够: 名字被破坏 没有线路信息 第一个问题可以通过abi :: __ cxa_demangle解决。 然而第二个问题更加困难。 我找到了backtrace_symbols()的替代品。 这比gcc的backtrace_symbols()更好,因为它可以检索行号(如果使用-g编译),并且不需要使用-rdynamic编译

Measure execution time in C++ OpenMP code

I am running a .cpp code (i) in sequential style and (ii) using OpenMP statements. I am trying to see the time difference. For calculating time, I use this: #include <time.h> ..... main() { clock_t start, finish; start = clock(); . . . finish = clock(); processing time = (double(finish-start)/CLOCKS_PER_SEC); } The time is pretty accurate in sequential (above) run of t

在C ++ OpenMP代码中测量执行时间

我以顺序方式运行.cpp代码(i)和(ii)使用OpenMP语句。 我想看看时差。 为了计算时间,我使用这个: #include <time.h> ..... main() { clock_t start, finish; start = clock(); . . . finish = clock(); processing time = (double(finish-start)/CLOCKS_PER_SEC); } 在代码的连续(上面)运行中,时间非常准确。 这需要大约8秒钟的时间。 当我在代码中插入OpenMP语句,然后计算出时间减少的

Why does MATLAB/Octave wipe the floor with C++ in Eigenvalue Problems?

I'm hoping that the answer to the question in the title is that I'm doing something stupid! Here is the problem. I want to compute all the eigenvalues and eigenvectors of a real, symmetric matrix. I have implemented code in MATLAB (actually, I run it using Octave), and C++, using the GNU Scientific Library. I am providing my full code below for both implementations. As far as I can

为什么MATLAB / Octave在特征值问题中用C ++擦拭地板?

我希望题目中问题的答案是我正在做一些愚蠢的事情! 这是问题。 我想计算一个真正的对称矩阵的所有特征值和特征向量。 我已经在MATLAB中实现了代码(实际上,我使用Octave来运行它)以及使用GNU科学库的C ++。 我在下面提供了两个实现的完整代码。 据我所知,GSL自带BLAS API实现(以下我称之为GSLCBLAS),并使用我编译的库: g++ -O3 -lgsl -lgslcblas GSL建议在此使用替代的BLAS库,例如自我优化的ATLAS库,以提高性

Debugging the CPU Caches

I'm currently trying to optimize my software for better CPU cache usage. There are some posts on SO which suggest that it's sometimes hard to guess what the CPU cache is doing and why there are some performance drops in certain cases. For example: Why does the speed of memcpy() drop dramatically every 4KB? Why is my program slow when looping over exactly 8192 elements? Why is tran

调试CPU高速缓存

我目前正试图优化我的软件以获得更好的CPU缓存使用率。 SO上有一些帖子表明,有时很难猜测 CPU缓存在做什么,以及为什么在某些情况下性能会下降。 例如: 为什么memcpy()的速度每4KB急剧下降? 为什么我的程序在循环8192个元素时很慢? 为什么转置一个512x512的矩阵要比转置513x513的矩阵慢得多? 因此,为了获得缓存未命中发生的线索,我可以运行perf来获得缓存未命中的次数,以及valgrind --tool=cachegrind模拟缓

Why does my 8M L3 cache not provide any benefit for arrays larger than 1M?

I was inspired by this question to write a simple program to test my machine's memory bandwidth in each cache level: Why vectorizing the loop does not have performance improvement My code uses memset to write to a buffer (or buffers) over and over and measures the speed. It also saves the address of every buffer to print at the end. Here's the listing: #include <stdio.h> #inc

为什么我的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, 51

how to create a vector of int 2D array in c++

This question already has an answer here: std::vector of an array 3 answers Native arrays are not copyable, moveable or assignable, so they cannot be stored in a standard container. However, the wrapper std::array<T,N> is, so std::vector<std::array<std::array<int, 2>, 2> > is one way to do what you want. You can create a 2D vector in this way: std::vector <std::

如何在c ++中创建int 2D数组的向量

这个问题在这里已经有了答案: 数组3的答案向量 本地数组不可复制,可移动或可分配,因此它们不能存储在标准容器中。 然而,包装std::array<T,N>是,所以std::vector<std::array<std::array<int, 2>, 2> >是一种做你想做的事情的方法。 你可以用这种方式创建一个2D矢量: std::vector <std::vector <data_type> > vector_name 注意:在C ++ 03中, >和>之间必须有一个空格

How do I declare a 2d array in C++ using new?

How do i declare a 2d array using new? Like, for a "normal" array I would: int* ary = new int[Size] but int** ary = new int[sizeY][sizeX] a) doesn't work/compile and b) doesn't accomplish what: int ary[sizeY][sizeX] does. A dynamic 2D array is basically an array of pointers to arrays. You can initialize it using a loop, like this: int** a = new int*[rowCount]; for(i

我如何使用new在C ++中声明2d数组?

我如何使用new声明2d数组? 就像,对于一个“正常”的阵列,我会: int* ary = new int[Size] 但 int** ary = new int[sizeY][sizeX] a)不工作/编译和b)没有完成: int ary[sizeY][sizeX] 确实。 动态2D数组基本上是指向数组的指针数组。 您可以使用循环来初始化它,如下所示: int** a = new int*[rowCount]; for(int i = 0; i < rowCount; ++i) a[i] = new int[colCount]; 以上,对于colCount= 5和rowCou

Error: bad register name `%rax' MinGW, Windows 7, x64 CPU, C++

In my previous topic: How to read registers: RAX, RBX, RCX, RDX, RSP. RBP, RSI, RDI in C or C++? I asked about reading those registers. Now I wrote a code to read (just for now on) RAX and RBX. Im using Windows 7 64 bit OS, CodeBlocks with MinGW as a compiler and Im working on x64 CPU. When I tried to compile the below code, I got those errors: Error: bad register name `%rax' Error: bad

错误:错误的寄存器名称'%rax'MinGW,Windows 7,x64 CPU,C ++

在我之前的主题中:如何读取寄存器:RAX,RBX,RCX,RDX,RSP。 C或C ++中的RBP,RSI,RDI? 我询问有关阅读这些寄存器 现在我写了一个代码来阅读(就目前来说)RAX和RBX。 我使用Windows 7 64位操作系统,CodeBlocks与MinGW作为编译器和Im在x64 CPU上工作。 当我试图编译下面的代码时,我得到了这些错误: Error: bad register name `%rax' Error: bad register name `%rbx' 代码: #include <iostream> #inclu

Any advantage of XOR AL,AL + MOVZX EAX, AL over XOR EAX,EAX?

I have some unknown C++ code that was compiled in Release build, so it's optimized. The point I'm struggling with is: xor al, al add esp, 8 cmp byte ptr [ebp+userinput], 31h movzx eax, al This is my understanding: xor al, al ; set eax to 0x??????00 (clear last byte) add esp, 8 ; for some unclear reason, set the stack pointer higher cmp byte ptr [ebp+use

XOR AL,AL + MOVZX EAX,AL在XOR EAX,EAX上的优势?

我有一些未知的C ++代码,它是在发布版本中编译的,因此它已经过优化。 我正在努力的一点是: xor al, al add esp, 8 cmp byte ptr [ebp+userinput], 31h movzx eax, al 这是我的理解: xor al, al ; set eax to 0x??????00 (clear last byte) add esp, 8 ; for some unclear reason, set the stack pointer higher cmp byte ptr [ebp+userinput], 31h ; set zero flag if user input was "1

Unable to compile program using boost on Mac

I recently installed boost 1.48 on my MacOSX 10.7 using MacPorts. While I am able to compiler some examples given in boost documentation, I am failing in this one (http://www.boost.org/doc/libs/1_48_0/libs/bimap/example/step_by_step.cpp). Here is the error message: g++ -Wall -I/opt/local/include -L/opt/local/lib step_by_step.cpp -o step_by_step In file included from /usr/include/machine/

无法在Mac上使用boost进行编译

我最近使用MacPorts在MacOSX 10.7上安装了boost 1.48。 虽然我能够编译boost文档中给出的一些示例,但我在这个失败(http://www.boost.org/doc/libs/1_48_0/libs/bimap/example/step_by_step.cpp)。 这是错误消息: g++ -Wall -I/opt/local/include -L/opt/local/lib step_by_step.cpp -o step_by_step In file included from /usr/include/machine/_types.h:32, from /usr/include/sys/_types.h:33,