         gethostname(nm, 1024);                                                                                     \
         printf("hostname: %s\n", nm);                                                                              \
         printf("Error in %s at line %i of file %s: %s\n", #func__, __LINE__, __FILE__, cudaGetErrorString(error)); \
-        raise(SIGTERM);                                                                                            \
-        exit(-100);                                                                                                \
+        stack_backtrace();                                                                                         \
     }                                                                                                              \
 }
 #else

        gethostname(nm, 1024);                                                                                     \
        printf("hostname: %s\n", nm);                                                                              \
        printf("Error in %s at line %i of file %s: %s\n", #func__, __LINE__, __FILE__, cudaGetErrorString(error)); \
        raise(SIGTERM);                                                                                            \
        exit(-100);                                                                                                \
    }                                                                                                              \
}
#endif

//================
// CUDA functions
//================
void stack_backtrace()
{
    void *array[10];
    char **strings;
    int size = backtrace(array, 10);
    strings = backtrace_symbols(array, size);
    printf ("Stack backtrace:\n");
    for (size_t i = 0; i < size; i++) printf ("%s\n", strings[i]);
    raise(SIGQUIT);
}

#ifdef NDEBUG
#define CALL_CUDA(func__, args__)                                                                                  \
