From 0b1c98d3f61e8b201888fe8f5f94cea01dcdec9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Sun, 5 Feb 2012 11:57:03 +0000 Subject: [PATCH] allow MPI to compute term size. --- C/utilpreds.c | 20 +++++++++++++++----- library/lam_mpi.yap | 3 +-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/C/utilpreds.c b/C/utilpreds.c index f8842c716..4c99d7673 100644 --- a/C/utilpreds.c +++ b/C/utilpreds.c @@ -1668,9 +1668,9 @@ p_export_term( USES_REGS1 ) sz += 4096; free(export_buf); } - } while (osz); - return Yap_unify(ARG2,MkIntegerTerm(osz)) && - Yap_unify(ARG3, MkIntegerTerm((Int)export_buf)); + } while (!osz); + return Yap_unify(ARG3,MkIntegerTerm(osz)) && + Yap_unify(ARG2, MkIntegerTerm((Int)export_buf)); } static Int @@ -1680,10 +1680,19 @@ p_import_term( USES_REGS1 ) if (!export_buf) return FALSE; Int out = Yap_unify(ARG2,Yap_ImportTerm(export_buf)); - free(export_buf); return out; } +static Int +p_kill_exported_term( USES_REGS1 ) +{ + char *export_buf = (char *)IntegerOfTerm(Deref(ARG1)); + if (!export_buf) + return FALSE; + free(export_buf); + return TRUE; +} + static Term vars_in_complex_term(register CELL *pt0, register CELL *pt0_end, Term inp USES_REGS) { @@ -4818,8 +4827,9 @@ void Yap_InitUtilCPreds(void) Yap_InitCPred("subsumes", 2, p_subsumes, 0); Yap_InitCPred("variables_within_term", 3, p_variables_within_term, 0); Yap_InitCPred("new_variables_in_term", 3, p_new_variables_in_term, 0); - Yap_InitCPred("import_term", 2, p_import_term, 0); Yap_InitCPred("export_term", 3, p_export_term, 0); + Yap_InitCPred("kill_exported_term", 1, p_kill_exported_term, SafePredFlag); + Yap_InitCPred("import_term", 2, p_import_term, 0); CurrentModule = cm; #ifdef DEBUG Yap_InitCPred("$force_trail_expansion", 1, p_force_trail_expansion, SafePredFlag|HiddenPredFlag); diff --git a/library/lam_mpi.yap b/library/lam_mpi.yap index 8144d2d76..36fca143d 100644 --- a/library/lam_mpi.yap +++ b/library/lam_mpi.yap @@ -31,5 +31,4 @@ mpi_msg_size(Term, Size) :- terms:export_term(Term, Buf, Size), - terms:import_term(Buf, _). - + terms:kill_exported_term(Buf). \ No newline at end of file