add function to flesh to query name of currently executing function

Create issue
Issue #817 closed
Roland Haas created an issue

It would be nice if there was a function:

#include <cctk.h>

const cFunctionData * CCTK_QueryScheduledFunction(const cGH * cctkGH);

const cFunctionData * func = QueryScheduledFunction(cctkGH);
printf("Currently running: %s::%s\n", func->thorn, func->routine);

to find the function most recently called via CCTK_CallFunction. In the simplest implementation CCTK_CallFunction() (in main/ScheduleInterface.c) would simply store its attribute arguement in a global variable for later retrieval. A more complete implementation might have stack of called functions (in case CallFunction can be called recurively) or store the information in cctkGH (though CallFunction does not take cctkGH as an argument).

I currently have a hacked version of the first option running to find out who is calling CarpetReduce in local mode. BUt it might be useful also in eg. the interpolator calls (as in "AEILocalInterpolator: point foo out of bounds").

Keyword:

Comments (10)

  1. Erik Schnetter
    • removed comment

    This function is a very good idea. The suggested implementation (using a single global variable) is fine.

    I would call the function CCTK_ScheduleQueryCurrentFunction, which follows more closely the naming scheme used elsewhere in the flesh.

  2. Roland Haas reporter
    • removed comment

    attached please find a patch to the flesh implementing CCTK_ScheduleQueryCurrentFunction, as well as documentation updates for it.

    Ok to apply (need two "yes" votes since it is the flesh)?

  3. Frank Löffler
    • removed comment

    Two comments:

    1) trivial typo: there -> their

    2) Why does CCTK_ScheduleQueryCurrentFunction take an argument (GH)? It does not use it.

    3) Is it really necessary to abort when CCTK_CallFunction is called recursively? This is not the case right now and would be a side-effect of this patch.

  4. Erik Schnetter
    • removed comment

    I think it should take the GH argument to give us the freedom to store the queried information later elsewhere and not in a global variable. We will then need a data structure such as the GH to find this information.

    However: if LangNone "should never happen", then this should lead to an abort, not a fall through.

  5. anonymous
    • removed comment

    Frank: I am not I understand your comment about it aborting. The warning in CCTK_ScheduleQueryCurrentFunction is level CCTK_WARN_PICKY (level 3) which should not abort as far as I know. The reason for passing cctkGH is as Erik outlined, though I agree that this can be a problem if one is within a function that does not have access to cctkGH. I did not check if there were any such that would be candidates.

    The "LangNone" was put there to avoid a compiler warning. It currently reproduces the existing behaviour which is also non-fatal.

  6. Frank Löffler
    • removed status
    • removed comment

    Warning with CCTK_WARN_PICKY is probably ok - although calling it recursively is either ok (and then it shouldn't warn at all) or wrong (and then is should probably abort the run).

    Concerning GH: I think it would be nice to to have to pass GH to every function where I would like to use this function (on the other hand, using a global for that wouldn't be a big deal either). I do understand the idea of storing the information about the currently executed function within GH though. So, in the end: yes, please commit. However, please use CCTK_ATTRIBUTE_UNUSED for GH until we do use it.

  7. Log in to comment