Skip to content

Commit

Permalink
Unify DUMP_GRAPH and DUMP_Q_
Browse files Browse the repository at this point in the history
  • Loading branch information
hrue committed Feb 20, 2025
1 parent a1c7c30 commit dc65a3c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
11 changes: 2 additions & 9 deletions gmrflib/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,21 +246,14 @@ int GMRFLib_graph_write(const char *filename, GMRFLib_graph_tp *graph)
/*
* write graph to file filename in the format so it can be read by 'read_graph'
*/

FILE *fp = NULL;

if (!filename) {
return GMRFLib_SUCCESS;
}
if (!graph) {
if (!filename || !graph) {
return GMRFLib_SUCCESS;
}

fp = fopen(filename, "w");
FILE *fp = fopen(filename, "w");
if (!fp) {
GMRFLib_ERROR(GMRFLib_EOPENFILE);
}

GMRFLib_graph_write2(fp, graph);
fclose(fp);

Expand Down
29 changes: 15 additions & 14 deletions gmrflib/pre-opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,22 +747,23 @@ int GMRFLib_preopt_init(GMRFLib_preopt_tp **preopt, int npred, int nf, int **c,

SHOW_TIME("graph-union");

#if !defined(WINDOWS)
if (getenv("INLA_INTERNAL_DUMP_GRAPH")) {
static int count = 0;
char *homedir = getenv("HOME");
if (!homedir) {
homedir = getpwuid(getuid())->pw_dir;
static int write_graph = -1;
if (write_graph < 0) {
#pragma omp critical (Name_31e81e1b3b565490a6c6d611d9de4707f32faca3)
if (write_graph < 0) {
int res = (getenv("INLA_INTERNAL_DUMP_GRAPH") ? 1 : 0);
write_graph = res;
}
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

if (getenv("INLA_INTERNAL_DUMP_GRAPH")) {
char *filename = NULL;
GMRFLib_sprintf(&filename, "./inla_graph_XXXXXX");
int fd = mkstemp(filename);
close(fd);
GMRFLib_graph_write(filename, (*preopt)->preopt_graph);
fprintf(stderr, "\n\t*** write graph to file [%s]\n", filename);
}

(*preopt)->preopt_Qfunc = GMRFLib_preopt_Qfunc;
(*preopt)->preopt_Qfunc_arg = (void *) *preopt;
Expand Down
20 changes: 13 additions & 7 deletions gmrflib/smtp-taucs.c
Original file line number Diff line number Diff line change
Expand Up @@ -876,21 +876,27 @@ int GMRFLib_build_sparse_matrix_TAUCS(int thread_id, taucs_ccs_matrix **L, GMRFL
Free(ic_idx);
}

// write matrix to file
if (0) {
static int dump_Q = -1;
if (dump_Q < 0) {
#pragma omp critical (Name_29d46bdd6abbbf3b1bd5098a4281a9dd165fe114)
if (dump_Q < 0) {
dump_Q = (getenv("INLA_INTERNAL_DUMP_Q") ? 1 : 0);
}
}

if (dump_Q > 0) {
// write matrix to file
#pragma omp critical (Name_e9854d763a7a40f3e47e8b55bd2e61a67241870d)
{
taucs_crs_matrix *QQ = GMRFLib_ccs2crs(Q);

char *filename = NULL;
int nz = n + graph->nnz / 2;
GMRFLib_sprintf(&filename, "./inla_Qmatrix_XXXXXX");
int fd = mkstemp(filename);
close(fd);
FILE *fp = fopen(filename, "wb");

double dn = (double) QQ->n;
double dnz = (double) nz;
FILE *fp = fopen(filename, "wb");
double dn = (double) QQ->n, dnz = (double) nz;
fwrite((void *) &dn, sizeof(double), (size_t) 1, fp);
fwrite((void *) &dnz, sizeof(double), (size_t) 1, fp);

Expand All @@ -909,7 +915,7 @@ int GMRFLib_build_sparse_matrix_TAUCS(int thread_id, taucs_ccs_matrix **L, GMRFL
fclose(fp);
Free(itmp);
taucs_crs_free(QQ);
printf("write file [%s]\n", filename);
fprintf(stderr, "\n\t*** write Q-matrix to file [%s]\n", filename);
}
}

Expand Down

0 comments on commit dc65a3c

Please sign in to comment.