RRZE-HPC / likwid

Performance monitoring and benchmarking suite
https://hpc.fau.de/research/tools/likwid/
GNU General Public License v3.0
1.65k stars 226 forks source link

[BUG] problems with long region names (segfaults and errors) #551

Closed melven closed 1 year ago

melven commented 1 year ago

Describe the bug With region names longer than ~100 characters, I get not a valid region description: ... sometimes followed by a segfault.

To Reproduce

Please supply the output of the command with -d added to the command line:

free(): double free detected in tcache 2 Aborted (core dumped)


**Example code**
```c
#include <stdlib.h>
#include <stdio.h>
#include <omp.h>
// This block enables compilation of the code with and without LIKWID in place
#ifdef LIKWID_PERFMON
#include <likwid-marker.h>
#else
#define LIKWID_MARKER_INIT
#define LIKWID_MARKER_THREADINIT
#define LIKWID_MARKER_SWITCH
#define LIKWID_MARKER_REGISTER(regionTag)
#define LIKWID_MARKER_START(regionTag)
#define LIKWID_MARKER_STOP(regionTag)
#define LIKWID_MARKER_CLOSE
#define LIKWID_MARKER_GET(regionTag, nevents, events, time, count)
#endif

#define N 10000

int main(int argc, char* argv[])
{
    int i;
    double data[N];
    const char* longRegionName = "fooXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    const char* shortRegionName = "foo";
    LIKWID_MARKER_INIT;

#pragma omp parallel
{
    LIKWID_MARKER_START(longRegionName);
    #pragma omp for
    for(i = 0; i < N; i++)
    {
        data[i] = omp_get_thread_num();
    }
    LIKWID_MARKER_STOP(longRegionName);
}

#pragma omp parallel
{
    LIKWID_MARKER_START(shortRegionName);
    #pragma omp for
    for(i = 0; i < N; i++)
    {
        data[i] = omp_get_thread_num();
    }
    LIKWID_MARKER_STOP(shortRegionName);
}
    LIKWID_MARKER_CLOSE;
    return 0;
}
melven commented 1 year ago

Hello from Cologne ;)

problem is not urgent for me - as a workaround I just shorten my region names (they are generated automatically from C++ template function names -> thus sometimes long)...

Best, Melven

TomTheBear commented 1 year ago

Hi Melven,

we have that issue also with others trying to integrate the MarkerAPI into some framework with auto-generated region names (e.g. OpenSYCL). The question is what is a reasonable maximal length for the region names. Or no string length limit at all? Your opinion?

The currently hardcoded limit is 100 characters.

Best, Thomas

melven commented 1 year ago

Hi Thomas,

I suspect there is an additional bug: it should not segfault when the string is too long. Would be fine for me if it takes the first 100 chars (just truncating the name). If someone really has tag names that differ only in the 105th character, that regions would just appear as one...

Best, Melven

TomTheBear commented 1 year ago

Please check the linked commit/branch. It follows your suggestion to truncate the region tag if larger than 100 characters.

melven commented 1 year ago

Works fine in all my tests, thanks!