Skip to content

Commit

Permalink
Dump graph upon request
Browse files Browse the repository at this point in the history
  • Loading branch information
hrue committed Oct 17, 2024
1 parent 91f6fb3 commit dceca95
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions gmrflib/pre-opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
#include "GMRFLib/GMRFLib.h"
#include "GMRFLib/GMRFLibP.h"

#if !defined(WINDOWS)
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#endif

int GMRFLib_preopt_init(GMRFLib_preopt_tp **preopt, int npred, int nf, int **c, double **w,
GMRFLib_graph_tp **f_graph, GMRFLib_Qfunc_tp **f_Qfunc, void **f_Qfunc_arg,
Expand Down Expand Up @@ -708,6 +713,23 @@ int GMRFLib_preopt_init(GMRFLib_preopt_tp **preopt, int npred, int nf, int **c,
g_arr[1] = (*preopt)->like_graph;
GMRFLib_graph_union(&((*preopt)->preopt_graph), g_arr, 2);

#if !defined(WINDOWS)
if (getenv("INLA_INTERNAL_DUMP_GRAPH")) {
static int count = 0;
char *homedir = getenv("HOME");
if (!homedir) {
homedir = getpwuid(getuid())->pw_dir;
}
if (!homedir) {
homedir = strdup("./");
}
char *fnm = NULL;
GMRFLib_sprintf(&fnm, "%s/INLA-graph-pid%1d-count%1d.txt", homedir, (int) getpid(), ++count);
GMRFLib_graph_write(fnm, (*preopt)->preopt_graph);
fprintf(stderr, "\n\t*** write graph to file [%s]\n", fnm);
}
#endif

(*preopt)->preopt_Qfunc = GMRFLib_preopt_Qfunc;
(*preopt)->preopt_Qfunc_arg = (void *) *preopt;
(*preopt)->gcpo_Qfunc = GMRFLib_preopt_gcpo_Qfunc;
Expand Down

0 comments on commit dceca95

Please sign in to comment.