Merge branch 'master' of ssh://git.dcc.fc.up.pt/yap-6.3

This commit is contained in:
Vitor Santos Costa 2015-02-11 10:33:43 +00:00
commit 61625ca7ad
19 changed files with 430 additions and 318 deletions

View File

@ -3204,7 +3204,7 @@ YAP_Reset(yap_reset_t mode)
/* always have an empty slots for people to use */ /* always have an empty slots for people to use */
P = CP = YESCODE; P = CP = YESCODE;
// ensure that we have slots where we need them // ensure that we have slots where we need them
Yap_CloseSlots(1); Yap_RebootSlots( worker_id );
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return res; return res;
} }

View File

@ -1844,7 +1844,7 @@ Yap_InitYaamRegs( int myworker_id )
h0var = MkVarTerm(); h0var = MkVarTerm();
REMOTE_AttsMutableList(myworker_id) = Yap_NewTimedVar(h0var); REMOTE_AttsMutableList(myworker_id) = Yap_NewTimedVar(h0var);
#endif #endif
REMOTE_CurSlot(myworker_id) = 1; /* This function has direct access to the Handles class AKA InitSlot */ Yap_RebootSlots( myworker_id );
h0var = MkVarTerm(); h0var = MkVarTerm();
REMOTE_GcGeneration(myworker_id) = Yap_NewTimedVar(h0var); REMOTE_GcGeneration(myworker_id) = Yap_NewTimedVar(h0var);
REMOTE_GcCurrentPhase(myworker_id) = 0L; REMOTE_GcCurrentPhase(myworker_id) = 0L;

View File

@ -14,12 +14,12 @@ enum PropTag {
FUNCTOR_TAG = FunctorProperty, // 0xBB00, FUNCTOR_TAG = FunctorProperty, // 0xBB00,
// SPARSE_FUNCTOR_TAG = 0xFFDF, // SPARSE_FUNCTOR_TAG = 0xFFDF,
/// arithmetic function /// arithmetic function
ARITHMETIC_PROPERTY_TAG = ExpProperty, // 0xFFE3, ARITHMETIC_PROPERTY_TAG = ExpProperty, // 0xFFE0,
/// map the atom to an integer /// map the atom to an integer
TRANSLATION_TAG = TranslationProperty, // 0xFFF4, TRANSLATION_TAG = TranslationProperty, // 0xFFF4,
/// SWI-STYLE ATOM Extension /// ensure the atom may not be garbafe colected
BLOB_TAG = BlobProperty, // 0xFFF5, HOLD_TAG = HoldProperty, // 0xFFF6
/// named mutEX /// named mutEX
MUTEX_TAG = MutexProperty, // 0xFFF6, MUTEX_TAG = MutexProperty, // 0xFFF6,
/// A typed array, may be in-db or in-stack deped /// A typed array, may be in-db or in-stack deped
ARRAY_TAG = ArrayProperty, // 0xFFF7, ARRAY_TAG = ArrayProperty, // 0xFFF7,
@ -29,12 +29,12 @@ enum PropTag {
MODULE_TAG = ModProperty, // 0xFFFA, MODULE_TAG = ModProperty, // 0xFFFA,
/// the original SICStus blackboard /// the original SICStus blackboard
BLACKBOARD_TAG = BBProperty, // 0xFFFB, BLACKBOARD_TAG = BBProperty, // 0xFFFB,
/// asociate an atomic value with the atom /// associate an atomic value with the atom
VALUE_TAG = ValProperty, // 0xFFFC, VALUE_TAG = ValProperty, // 0xFFFC,
/// Demoen's proposal for gkobal variables /// Demoen's proposal for gkobal variables
GLOBAL_VAR_TAG = GlobalProperty, // 0xFFFD GLOBAL_VAR_TAG = GlobalProperty, // 0xFFFD
/// ensure the atom may not be garbafe colected /// SWI-STYLE ATOM Extension
HOLD_TAG = HoldProperty, // 0xFFF BLOB_TAG = BlobProperty, // 0xFFFE,
/// Prolog operator, /// Prolog operator,
OPERATOR_TAG = OpProperty, // 0xFFFF, OPERATOR_TAG = OpProperty, // 0xFFFF,
}; };

View File

@ -48,6 +48,17 @@ Slots are not known to the yaam. Instead, A new set of slots is created when the
*************************************************************************************************/ *************************************************************************************************/
/// @brief reboot the slot system.
/// Used when wwe start from scratch (Reset).
#define Yap_RebootSlots( wid ) Yap_RebootSlots__( wid PASS_REGS )
static inline void
Yap_RebootSlots__( int wid USES_REGS ) {
// fprintf( stderr, " StartSlots = %ld", LOCAL_CurSlot);
REMOTE_CurSlot(wid) = 1;
}
/// @brief declares a new set of slots. /// @brief declares a new set of slots.
/// Used to tell how many slots we had when we entered a segment of code. /// Used to tell how many slots we had when we entered a segment of code.
#define Yap_StartSlots() Yap_StartSlots__( PASS_REGS1 ) #define Yap_StartSlots() Yap_StartSlots__( PASS_REGS1 )

View File

@ -1598,7 +1598,7 @@ AbsBlobProp (BlobPropEntry * p)
#endif #endif
#define BlobProperty ((PropFlags)0xfff5) #define BlobProperty ((PropFlags)0xfffe)
INLINE_ONLY inline EXTERN PropFlags IsBlobProperty (int); INLINE_ONLY inline EXTERN PropFlags IsBlobProperty (int);

125
configure vendored
View File

@ -700,6 +700,7 @@ ARCHIVE_CPPFLAGS
ARCHIVE_LIBS ARCHIVE_LIBS
ARCHIVE_PLTARGETS ARCHIVE_PLTARGETS
ARCHIVE_TARGETS ARCHIVE_TARGETS
CLIB_FLAGS_LIBUUID
CLIB_LIBUUID CLIB_LIBUUID
CLIB_CRYPTOBJ CLIB_CRYPTOBJ
CLIB_CRYPTLIBS CLIB_CRYPTLIBS
@ -10501,7 +10502,8 @@ done
if test "$yap_cv_mysql" = yes if test "$yap_cv_mysql" = yes
then then
YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_MYSQL" use_myddas=true
YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_MYSQL"
fi fi
case "$target_os" in case "$target_os" in
@ -10728,6 +10730,7 @@ done
if test "$yap_cv_odbc" != no if test "$yap_cv_odbc" != no
then then
use_myddas=true
YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_ODBC" YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_ODBC"
fi fi
@ -10791,6 +10794,7 @@ done
if test "$yap_cv_sqlite3" != no if test "$yap_cv_sqlite3" != no
then then
use_myddas=true
YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_SQLITE3" YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_SQLITE3"
fi fi
@ -10804,6 +10808,11 @@ done
YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_TOP_LEVEL" YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_TOP_LEVEL"
fi fi
if test "$use_myddas" = true; then
YAP_EXTRAS="$YAP_EXTRAS -DUSE_MYDDAS=1"
fi
MYDDAS_LIBS="$LIBS" MYDDAS_LIBS="$LIBS"
LIBS="$OLD_LIBS" LIBS="$OLD_LIBS"
CPPFLAGS="$OLD_CPPFLAGS" CPPFLAGS="$OLD_CPPFLAGS"
@ -10829,8 +10838,6 @@ fi
@ -11801,6 +11808,7 @@ fi
CLIB_TARGETS="socket.$SO cgi.$SO memfile.$SO files.$SO mime.$SO crypt.$SO time.$SO" CLIB_TARGETS="socket.$SO cgi.$SO memfile.$SO files.$SO mime.$SO crypt.$SO time.$SO"
case "$PLARCH" in case "$PLARCH" in
@ -11980,7 +11988,69 @@ fi
fi fi
dl to be installed in various places.
# brew in OSX
if test -d /usr/local/opt/ossp-uuid; then
CPPFLAGS="$CPPFLAGS -I /usr/local/opt/ossp-uuid/include"
UUID_LIB_PATH="-L /usr/local/opt/ossp-uuid/lib"
fi
# /opt
if test -d /opt/include/ossp; then
CPPFLAGS="$CPPFLAGS -I /opt/include"
UUID_LIB_PATH="-L /opt/lib"
fi
# /usr/local
if test -d /opt/include/ossp; then
CPPFLAGS="$CPPFLAGS -I /opt/include"
UUID_LIB_PATH="-L /opt/lib"
fi
if test x"$UUID_H" = "x"; then
ac_fn_c_check_header_compile "$LINENO" "ossp/uuid.h" "ac_cv_header_ossp_uuid_h" "/*first*/
"
if test "x$ac_cv_header_ossp_uuid_h" = xyes; then :
UUID_H=ossp/uuid.h
has_uuid=true
fi
fi
if test x"$UUID_H" = "x" -a ! -d /usr/include/uuid; then
ac_fn_c_check_header_compile "$LINENO" "uuid/uuid.h" "ac_cv_header_uuid_uuid_h" "/*first*/
"
if test "x$ac_cv_header_uuid_uuid_h" = xyes; then :
UUID_H=uuid/uuid.h
has_uuid=true
fi
fi
if test x"$UUID_H" = "x"; then
ac_fn_c_check_header_compile "$LINENO" "uuid.h" "ac_cv_header_uuid_h" "/*first*/
"
if test "x$ac_cv_header_uuid_h" = xyes; then :
UUID_H=uuid.h
has_uuid=true
fi
fi
if test x"$UUID_H" = "x"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Cannot find uuid.h -- dropping uuid.pl" >&5
$as_echo "$as_me: WARNING: Cannot find uuid.h -- dropping uuid.pl" >&2;}
else
cat >>confdefs.h <<_ACEOF
#define UUID_H <$UUID_H>
_ACEOF
has_uuid=true
fi
if test x"$has_uuid" != "x"; then
ac_fn_c_check_func "$LINENO" "uuid_create" "ac_cv_func_uuid_create" ac_fn_c_check_func "$LINENO" "uuid_create" "ac_cv_func_uuid_create"
if test "x$ac_cv_func_uuid_create" = xyes; then : if test "x$ac_cv_func_uuid_create" = xyes; then :
has_uuid=true has_uuid=true
@ -12024,7 +12094,7 @@ fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_uuid_uuid_create" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_uuid_uuid_create" >&5
$as_echo "$ac_cv_lib_uuid_uuid_create" >&6; } $as_echo "$ac_cv_lib_uuid_uuid_create" >&6; }
if test "x$ac_cv_lib_uuid_uuid_create" = xyes; then : if test "x$ac_cv_lib_uuid_uuid_create" = xyes; then :
CLIB_LIBUUID=-luuid CLIB_LIBUUID="$UUID_LIB_PATH -luuid"
has_uuid=true has_uuid=true
fi fi
@ -12038,45 +12108,6 @@ $as_echo "$as_me: WARNING: Cannot find libossp-uuid or libuuid -- dropping uuid
fi fi
if test x"$has_uuid" != "x"; then
if test x"$UUID_H" = "x"; then
ac_fn_c_check_header_compile "$LINENO" "ossp/uuid.h" "ac_cv_header_ossp_uuid_h" "/*first*/
"
if test "x$ac_cv_header_ossp_uuid_h" = xyes; then :
UUID_H=ossp/uuid.h
fi
fi
if test x"$UUID_H" = "x" -a ! -d /usr/include/uuid; then
ac_fn_c_check_header_compile "$LINENO" "uuid/uuid.h" "ac_cv_header_uuid_uuid_h" "/*first*/
"
if test "x$ac_cv_header_uuid_uuid_h" = xyes; then :
UUID_H=uuid/uuid.h
fi
fi
if test x"$UUID_H" = "x"; then
ac_fn_c_check_header_compile "$LINENO" "uuid.h" "ac_cv_header_uuid_h" "/*first*/
"
if test "x$ac_cv_header_uuid_h" = xyes; then :
UUID_H=uuid.h
fi
fi
if test x"$UUID_H" = "x"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Cannot find uuid.h -- dropping uuid.pl" >&5
$as_echo "$as_me: WARNING: Cannot find uuid.h -- dropping uuid.pl" >&2;}
else
cat >>confdefs.h <<_ACEOF
#define UUID_H <$UUID_H>
_ACEOF
CLIB_TARGETS="$CLIB_TARGETS uuid.$SO"
fi
fi fi
@ -14317,7 +14348,7 @@ else
JAVA_TEST=Test.java JAVA_TEST=Test.java
CLASS_TEST=Test.class CLASS_TEST=Test.class
cat << \EOF > $JAVA_TEST cat << \EOF > $JAVA_TEST
/* #line 14320 "configure" */ /* #line 14351 "configure" */
public class Test { public class Test {
} }
EOF EOF
@ -14493,7 +14524,7 @@ EOF
if uudecode$EXEEXT Test.uue; then if uudecode$EXEEXT Test.uue; then
ac_cv_prog_uudecode_base64=yes ac_cv_prog_uudecode_base64=yes
else else
echo "configure: 14496: uudecode had trouble decoding base 64 file 'Test.uue'" >&5 echo "configure: 14527: uudecode had trouble decoding base 64 file 'Test.uue'" >&5
echo "configure: failed file was:" >&5 echo "configure: failed file was:" >&5
cat Test.uue >&5 cat Test.uue >&5
ac_cv_prog_uudecode_base64=no ac_cv_prog_uudecode_base64=no
@ -14624,7 +14655,7 @@ else
JAVA_TEST=Test.java JAVA_TEST=Test.java
CLASS_TEST=Test.class CLASS_TEST=Test.class
cat << \EOF > $JAVA_TEST cat << \EOF > $JAVA_TEST
/* #line 14627 "configure" */ /* #line 14658 "configure" */
public class Test { public class Test {
} }
EOF EOF
@ -14659,7 +14690,7 @@ JAVA_TEST=Test.java
CLASS_TEST=Test.class CLASS_TEST=Test.class
TEST=Test TEST=Test
cat << \EOF > $JAVA_TEST cat << \EOF > $JAVA_TEST
/* [#]line 14662 "configure" */ /* [#]line 14693 "configure" */
public class Test { public class Test {
public static void main (String args[]) { public static void main (String args[]) {
System.exit (0); System.exit (0);

View File

@ -78,6 +78,8 @@ if (MPI_C_FOUND)
include_directories (${MPI_INCLUDE_DIRS}) include_directories (${MPI_INCLUDE_DIRS})
add_definitions (-DHAVE_MPI_H=1)
install(TARGETS yap_mpi install(TARGETS yap_mpi
LIBRARY DESTINATION ${dlls} LIBRARY DESTINATION ${dlls}
) )

View File

@ -3,9 +3,6 @@
# (EROOT for architecture-dependent files) # (EROOT for architecture-dependent files)
# #
# #
# default base directory for YAP installation
# (EROOT for architecture-dependent files)
#
prefix = @prefix@ prefix = @prefix@
exec_prefix = @exec_prefix@ exec_prefix = @exec_prefix@
ROOTDIR = $(prefix) ROOTDIR = $(prefix)
@ -62,7 +59,7 @@ hash.o: $(srcdir)/hash.c $(srcdir)/hash.h
@DO_SECOND_LD@ @SHLIB_LD@ $(LDFLAGS) -o yap_mpi.@SO@ $(OBJS) $(MPILDF) @EXTRA_LIBS_FOR_DLLS@ @DO_SECOND_LD@ @SHLIB_LD@ $(LDFLAGS) -o yap_mpi.@SO@ $(OBJS) $(MPILDF) @EXTRA_LIBS_FOR_DLLS@
install: all install-examples install: all install-examples
@if test "$(SOBJS)" = ""; then echo ""; else $(INSTALL_PROGRAM) $(SOBJS) $(DESTDIR)$(YAPLIBDIR); fi if test x"$(SOBJS)" != "x"; then $(INSTALL_PROGRAM) $(SOBJS) $(DESTDIR)$(YAPLIBDIR); fi
clean: clean:
rm -f *.o *~ $(OBJS) $(SOBJS) *.BAK rm -f *.o *~ $(OBJS) $(SOBJS) *.BAK

View File

@ -35,7 +35,7 @@ fi
dnl LAM/MPI interface dnl LAM/MPI interface
if test "$yap_cv_mpi" != "no" -a "$INSTALL_DLLS" != "no"; then if test "$yap_cv_mpi" != "no" -a "$INSTALL_DLLS" != "no"; then
if test "$yap_cv_mpi" != "yes"; then if test "$yap_cv_mpi" = "yes"; then
AC_PATH_PROG(MPI_CC,mpicc,"$CC",$PATH:/sbin:/usr/sbin:/usr/etc:/usr/local/sbin:/usr/lib64/openmpi/bin:/usr/lib/openmpi/bin) AC_PATH_PROG(MPI_CC,mpicc,"$CC",$PATH:/sbin:/usr/sbin:/usr/etc:/usr/local/sbin:/usr/lib64/openmpi/bin:/usr/lib/openmpi/bin)
else else
AC_PATH_PROG(MPI_CC,mpicc,"$CC",$yap_cv_mpi/bin:$PATH:/sbin:/usr/sbin:/usr/etc:/usr/local/sbin:/usr/lib64/openmpi/bin:/usr/lib/openmpi/bin) AC_PATH_PROG(MPI_CC,mpicc,"$CC",$yap_cv_mpi/bin:$PATH:/sbin:/usr/sbin:/usr/etc:/usr/local/sbin:/usr/lib64/openmpi/bin:/usr/lib/openmpi/bin)

47
library/lammpi/examples/gowait Executable file
View File

@ -0,0 +1,47 @@
#!/usr/local/bin/yap -L --
% called with
% mpirun -np 2 gowait.
% prints
% ------
% main
% main
% after_init
% after_init
% [0,2]
% [1,2]
% irecv
% wait_end
% after_send
% c(535755152,)
:- use_module(library(lam_mpi)).
:- use_module(library(system)).
main:-
write(main),nl,
mpi_init,
write(after_init),nl,
mpi_comm_size(S),
mpi_comm_rank(R),
write([R,S]),nl,
(R == 0->
sleep(2),
write(wait_end),nl,
mpi_send(ciao,1,201),
write(after_send),nl
;
mpi_irecv(0,_201,H),
write(irecv),nl,
test(H)
),
mpi_finalize.
test(H):-
(mpi_wait_recv(H,S,Data)->
write(c(S,Data)),nl
;
write(no),nl,
test(H)
).
:-main.

View File

@ -98,11 +98,23 @@ expand_buffer(const size_t space ) {
/* /*
* Changes the size of the buffer to contain at least newsize bytes * Changes the size of the buffer to contain at least newsize bytes
*/ */
void void change_buffer_size(const size_t newsize) {
change_buffer_size(const size_t newsize) { if ( BUFFER_PTR == NULL )
if ( BUFFER_SIZE>=BLOCK_SIZE && BUFFER_SIZE>=newsize) {
return; if ((BUFFER_PTR = malloc( BLOCK_SIZE < newsize ? newsize : BLOCK_SIZE)) == NULL) {
if (realloc( BUFFER_PTR, newsize) == NULL) { YAP_Error(0,0,"Prolog2Term: Out of memory.\n");
#ifdef MPI
MPI_Finalize();
#endif
YAP_Exit( 1 );
}
}
else if ((BUFFER_SIZE>=BLOCK_SIZE &&
BUFFER_SIZE>=newsize) )
{
return;
}
else if ((BUFFER_PTR = realloc( BUFFER_PTR, newsize)) == NULL) {
YAP_Error(0,0,"Prolog2Term: Out of memory.\n"); YAP_Error(0,0,"Prolog2Term: Out of memory.\n");
#ifdef MPI #ifdef MPI
MPI_Finalize(); MPI_Finalize();
@ -137,7 +149,7 @@ p2c_putt(const YAP_Term t) {
size_t size_t
write_term_to_stream(const int fd,const YAP_Term term) { write_term_to_stream(const int fd,const YAP_Term term) {
RESET_BUFFER; RESET_BUFFER();
printf("BUFFER_PTR=%p\n", BUFFER_PTR); printf("BUFFER_PTR=%p\n", BUFFER_PTR);
p2c_putt(term); p2c_putt(term);
if (write(fd,(void*)BUFFER_PTR,BUFFER_LEN) < 0) { // write term if (write(fd,(void*)BUFFER_PTR,BUFFER_LEN) < 0) { // write term
@ -154,7 +166,7 @@ YAP_Term
read_term_from_stream(const int fd) { read_term_from_stream(const int fd) {
size_t size; size_t size;
RESET_BUFFER; RESET_BUFFER();
if (!read(fd,(void*)&size,sizeof(size_t))) { // read the size of the term if (!read(fd,(void*)&size,sizeof(size_t))) { // read the size of the term
YAP_Error(0,0,"Prolog2Term: IO error in read.\n"); YAP_Error(0,0,"Prolog2Term: IO error in read.\n");
} }
@ -179,7 +191,7 @@ read_term_from_stream(const int fd) {
char* char*
term2string(char *const ptr, size_t *size, const YAP_Term t) { term2string(char *const ptr, size_t *size, const YAP_Term t) {
char *ret; char *ret;
RESET_BUFFER; RESET_BUFFER();
do { do {
if (*size == 0) { if (*size == 0) {

View File

@ -68,16 +68,17 @@ void write_msg(const char *fun,const char *file, int line,const char *format, ..
* Macros to manipulate the buffer * Macros to manipulate the buffer
*********************************************************************************************/ *********************************************************************************************/
extern int BLOCK_SIZE; extern size_t BLOCK_SIZE;
#define buffer (buffers[YAP_ThreadSelf()]) #define buffer (buffers[YAP_ThreadSelf()])
// deletes the buffer (all fields) but does not release the memory of the buffer.ptr // deletes the buffer (all fields) but does not release the memory of the buffer.ptr
#define DEL_BUFFER {buffer.ptr=NULL;buffer.size=0;buffer.len=0;buffer.pos=0;} #define DEL_BUFFER() {buffer.ptr=NULL;buffer.size=0;buffer.len=0;buffer.pos=0;}
// informs the prologterm2c module that the buffer is now used and should not be messed // informs the prologterm2c module that the buffer is now used and should not be messed
#define USED_BUFFER() DEL_BUFFER #define USED_BUFFER() DEL_BUFFER()
// initialize buffer // initialize buffer
#define RESET_BUFFER {buffer.len=0;change_buffer_size(BLOCK_SIZE);buffer.pos=0;} #define RESET_BUFFER() \
{buffer.len=0;change_buffer_size(BLOCK_SIZE);buffer.pos=0;}
#define BUFFER_PTR buffer.ptr #define BUFFER_PTR buffer.ptr
#define BUFFER_SIZE buffer.size #define BUFFER_SIZE buffer.size
#define BUFFER_LEN buffer.len #define BUFFER_LEN buffer.len

View File

@ -1,14 +1,14 @@
/* /*
Copyright (C) 2004,2005,2006 (Nuno A. Fonseca) <nuno.fonseca@gmail.com> Copyright (C) 2004,2005,2006 (Nuno A. Fonseca) <nuno.fonseca@gmail.com>
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version 2 of the License, or (at your option) any later
version. version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WxuARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
@ -69,7 +69,7 @@ typedef struct broadcast_req BroadcastRequest;
/******************************************************************** /********************************************************************
* Auxiliary data * Auxiliary data
********************************************************************/ ********************************************************************/
static int mpi_statuss[1024]; static YAP_Bool mpi_statuss[1024];
#define mpi_status (mpi_statuss[YAP_ThreadSelf()]) #define mpi_status (mpi_statuss[YAP_ThreadSelf()])
extern int GLOBAL_argc; extern int GLOBAL_argc;
@ -108,7 +108,7 @@ static double total_time_spent; // total time spend in communication code
#define CONT_TIMER() {tstart();} #define CONT_TIMER() {tstart();}
#define PAUSE_TIMER() {tend();total_time_spent+=tval();} #define PAUSE_TIMER() {tend();total_time_spent+=tval();}
#define RETURN(p) {PAUSE_TIMER();return (p);} #define return(p) {PAUSE_TIMER();return (p);}
static struct timeval _tstarts[1024], _tends[1024]; static struct timeval _tstarts[1024], _tends[1024];
@ -141,7 +141,7 @@ double tval(){
/* /*
* returns the statistics * returns the statistics
*/ */
static int mpi_stats(void){ static YAP_Bool mpi_stats(void){
fprintf(stderr,"%f %ld %ld %ld %ld %ld %ld\n",MPITIME,num_msgs_recv,bytes_recv,max_s_recv_msg,num_msgs_sent,bytes_sent,max_s_sent_msg); fprintf(stderr,"%f %ld %ld %ld %ld %ld %ld\n",MPITIME,num_msgs_recv,bytes_recv,max_s_recv_msg,num_msgs_sent,bytes_sent,max_s_sent_msg);
return (YAP_Unify(YAP_ARG1, YAP_MkFloatTerm((float)(MPITIME))) && return (YAP_Unify(YAP_ARG1, YAP_MkFloatTerm((float)(MPITIME))) &&
YAP_Unify(YAP_ARG2, YAP_MkIntTerm((long)num_msgs_recv)) && YAP_Unify(YAP_ARG2, YAP_MkIntTerm((long)num_msgs_recv)) &&
@ -155,7 +155,7 @@ static int mpi_stats(void){
/* /*
* *
*/ */
static int mpi_reset_stats(void) {RESET_STATS(); return (TRUE);} static YAP_Bool mpi_reset_stats(void) {RESET_STATS(); return true;}
#else #else
#define PAUSE_TIMER() #define PAUSE_TIMER()
@ -165,7 +165,7 @@ static int mpi_reset_stats(void) {RESET_STATS(); return (TRUE);}
#define RESET_STATS() #define RESET_STATS()
#define MSG_SENT(size) #define MSG_SENT(size)
#define MSG_RECV(size) #define MSG_RECV(size)
#define RETURN(p) {return (p);} #define return(p) {return (p);}
#endif #endif
/******************************************************************** /********************************************************************
@ -240,7 +240,7 @@ new_broadcast_request(BroadcastRequest* b,MPI_Request *handle,void* ptr) {
} }
/*********************************************************************/ /*********************************************************************/
static int mpi_error(int errcode){ static YAP_Bool mpi_error(int errcode){
char err_msg[MPI_MAX_ERROR_STRING]; char err_msg[MPI_MAX_ERROR_STRING];
int len; int len;
@ -258,7 +258,7 @@ static int mpi_error(int errcode){
* Sets up the mpi enviromment. This function should be called before any other MPI * Sets up the mpi enviromment. This function should be called before any other MPI
* function. * function.
*/ */
static int static YAP_Bool
mpi_init(void){ mpi_init(void){
int thread_level; int thread_level;
char ** my_argv; char ** my_argv;
@ -271,7 +271,7 @@ mpi_init(void){
#ifdef MPISTATS #ifdef MPISTATS
RESET_STATS(); RESET_STATS();
#endif #endif
return (TRUE); return true;
} }
#ifdef USE_THREADS #ifdef USE_THREADS
@ -280,7 +280,7 @@ mpi_init(void){
* function. * function.
* the argument is the name of the predicate that will be invoked when a message is received * the argument is the name of the predicate that will be invoked when a message is received
*/ */
static int static YAP_Bool
rcv_msg_thread(char *handle_pred) { rcv_msg_thread(char *handle_pred) {
YAP_Term pred=YAP_MkAtomTerm(YAP_LookupAtom(handle_pred)); YAP_Term pred=YAP_MkAtomTerm(YAP_LookupAtom(handle_pred));
MPI_Status status; MPI_Status status;
@ -299,7 +299,7 @@ rcv_msg_thread(char *handle_pred) {
/* /*
* *
*/ */
static int static YAP_Bool
mpi_init_rcv_thread(void){ mpi_init_rcv_thread(void){
int thread_level; int thread_level;
// MPI_Init(&GLOBAL_argc, &GLOBAL_argv); // MPI_Init(&GLOBAL_argc, &GLOBAL_argv);
@ -308,12 +308,12 @@ mpi_init_rcv_thread(void){
MPI_Init_thread(&GLOBAL_argc, &GLOBAL_argv,MPI_THREAD_SINGLE,&thread_level); MPI_Init_thread(&GLOBAL_argc, &GLOBAL_argv,MPI_THREAD_SINGLE,&thread_level);
if(pthread_create(&thread,NULL,(void*)&rcv_msg_thread,arg)) { if(pthread_create(&thread,NULL,(void*)&rcv_msg_thread,arg)) {
return (FALSE); return false;
} }
pthread_detach(thread); pthread_detach(thread);
write_msg(__FUNCTION__,__FILE__,__LINE__,"Thread level: %d\n",thread_level); write_msg(__FUNCTION__,__FILE__,__LINE__,"Thread level: %d\n",thread_level);
return (TRUE); return true;
} }
#endif #endif
@ -322,15 +322,15 @@ mpi_init_rcv_thread(void){
* exiting. * exiting.
* mpi_comm_finalize. * mpi_comm_finalize.
*/ */
static int static YAP_Bool
mpi_finalize(void){ mpi_finalize(void){
return (MPI_Finalize()==MPI_SUCCESS?TRUE:FALSE); return (MPI_Finalize()==MPI_SUCCESS?true:false);
} }
/* /*
* Returns the number of workers associated to the MPI_COMM_WORLD communicator. * Returns the number of workers associated to the MPI_COMM_WORLD communicator.
* mpi_comm_size(-Size). * mpi_comm_size(-Size).
*/ */
static int static YAP_Bool
mpi_comm_size(void){ mpi_comm_size(void){
int size; int size;
MPI_CALL(MPI_Comm_size(MPI_COMM_WORLD, &size)); MPI_CALL(MPI_Comm_size(MPI_COMM_WORLD, &size));
@ -340,7 +340,7 @@ mpi_comm_size(void){
* Returns the rank of the current process. * Returns the rank of the current process.
* mpi_comm_rank(-Rank). * mpi_comm_rank(-Rank).
*/ */
static int static YAP_Bool
mpi_comm_rank(void){ mpi_comm_rank(void){
int rank; int rank;
MPI_CALL(MPI_Comm_rank(MPI_COMM_WORLD, &rank)); MPI_CALL(MPI_Comm_rank(MPI_COMM_WORLD, &rank));
@ -350,7 +350,7 @@ mpi_comm_rank(void){
* Returns the major and minor version of MPI. * Returns the major and minor version of MPI.
* mpi_version(-Major,-Minor). * mpi_version(-Major,-Minor).
*/ */
static int static YAP_Bool
mpi_version(void){ mpi_version(void){
int major,minor; int major,minor;
@ -361,7 +361,7 @@ mpi_version(void){
* *
* *
*/ */
static int static YAP_Bool
mpi_get_processor_name(void) { mpi_get_processor_name(void) {
char name[MPI_MAX_PROCESSOR_NAME]; char name[MPI_MAX_PROCESSOR_NAME];
int length; int length;
@ -375,7 +375,7 @@ mpi_get_processor_name(void) {
* *
* mpi_isend(+Data, +Destination, +Tag, -Handle). * mpi_isend(+Data, +Destination, +Tag, -Handle).
*/ */
static int static YAP_Bool
mpi_isend(void) { mpi_isend(void) {
YAP_Term t1 = YAP_Deref(YAP_ARG1), YAP_Term t1 = YAP_Deref(YAP_ARG1),
t2 = YAP_Deref(YAP_ARG2), t2 = YAP_Deref(YAP_ARG2),
@ -387,11 +387,11 @@ mpi_isend(void) {
MPI_Request *handle=(MPI_Request*)malloc(sizeof(MPI_Request)); MPI_Request *handle=(MPI_Request*)malloc(sizeof(MPI_Request));
CONT_TIMER(); CONT_TIMER();
if ( handle==NULL ) return (FALSE); if ( handle==NULL ) return false;
if (YAP_IsVarTerm(t1) || !YAP_IsIntTerm(t2) || !YAP_IsIntTerm(t3) || !YAP_IsVarTerm(t4)) { if (YAP_IsVarTerm(t1) || !YAP_IsIntTerm(t2) || !YAP_IsIntTerm(t3) || !YAP_IsVarTerm(t4)) {
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(FALSE); return false;
} }
// //
dest = YAP_IntOfTerm(t2); dest = YAP_IntOfTerm(t2);
@ -402,7 +402,7 @@ mpi_isend(void) {
// send the data // send the data
if( MPI_CALL(MPI_Isend( str, len, MPI_CHAR, dest, tag, MPI_COMM_WORLD ,handle)) != MPI_SUCCESS ) { if( MPI_CALL(MPI_Isend( str, len, MPI_CHAR, dest, tag, MPI_COMM_WORLD ,handle)) != MPI_SUCCESS ) {
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(FALSE); return false;
} }
#ifdef DEBUG #ifdef DEBUG
@ -412,14 +412,14 @@ mpi_isend(void) {
// We must associate the string to each handle // We must associate the string to each handle
new_request(handle,str); new_request(handle,str);
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(YAP_Unify(YAP_ARG4,YAP_MkIntTerm(HANDLE2INT(handle))));// it should always succeed return(YAP_Unify(YAP_ARG4,YAP_MkIntTerm(HANDLE2INT(handle))));// it should always succeed
} }
/* /*
* Blocking communication function. The message is sent immediatly. * Blocking communication function. The message is sent immediatly.
* mpi_send(+Data, +Destination, +Tag). * mpi_send(+Data, +Destination, +Tag).
*/ */
static int static YAP_Bool
mpi_send(void) { mpi_send(void) {
YAP_Term t1 = YAP_Deref(YAP_ARG1), YAP_Term t1 = YAP_Deref(YAP_ARG1),
@ -430,7 +430,7 @@ mpi_send(void) {
size_t len=0; size_t len=0;
int val; int val;
if (YAP_IsVarTerm(t1) || !YAP_IsIntTerm(t2) || !YAP_IsIntTerm(t3)) { if (YAP_IsVarTerm(t1) || !YAP_IsIntTerm(t2) || !YAP_IsIntTerm(t3)) {
return (FALSE); return false;
} }
CONT_TIMER(); CONT_TIMER();
@ -439,20 +439,20 @@ mpi_send(void) {
tag = YAP_IntOfTerm(t3); tag = YAP_IntOfTerm(t3);
// the data is packaged as a string // the data is packaged as a string
str=term2string(NULL,&len,t1); str=term2string(NULL,&len,t1);
#ifdef DEBUG #if defined(DEBUG) && 0
write_msg(__FUNCTION__,__FILE__,__LINE__,"%s(%s,%u, MPI_CHAR,%d,%d)\n",__FUNCTION__,str,len,dest,tag); write_msg(__FUNCTION__,__FILE__,__LINE__,"%s(%s,%u, MPI_CHAR,%d,%d)\n",__FUNCTION__,str,len,dest,tag);
#endif #endif
// send the data // send the data
val=(MPI_CALL(MPI_Send( str, len, MPI_CHAR, dest, tag, MPI_COMM_WORLD))==MPI_SUCCESS?TRUE:FALSE); val=(MPI_CALL(MPI_Send( str, len, MPI_CHAR, dest, tag, MPI_COMM_WORLD))==MPI_SUCCESS?true:false);
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(val); return(val);
} }
/* /*
* Implements a blocking receive operation. * Implements a blocking receive operation.
* mpi_recv(?Source,?Tag,-Data). * mpi_recv(?Source,?Tag,-Data).
*/ */
static int static YAP_Bool
mpi_recv(void) { mpi_recv(void) {
YAP_Term t1 = YAP_Deref(YAP_ARG1), YAP_Term t1 = YAP_Deref(YAP_ARG1),
t2 = YAP_Deref(YAP_ARG2), t2 = YAP_Deref(YAP_ARG2),
@ -464,32 +464,32 @@ mpi_recv(void) {
//The third argument (data) must be unbound //The third argument (data) must be unbound
if(!YAP_IsVarTerm(t3)) { if(!YAP_IsVarTerm(t3)) {
return FALSE; return false;
} }
/* The first argument (Source) must be bound to an integer /* The first argument (Source) must be bound to an integer
(the rank of the source) or left unbound (i.e. any source (the rank of the source) or left unbound (i.e. any source
is OK) */ is OK) */
if (YAP_IsVarTerm(t1)) orig = MPI_ANY_SOURCE; if (YAP_IsVarTerm(t1)) orig = MPI_ANY_SOURCE;
else if( !YAP_IsIntTerm(t1) ) return (FALSE); else if( !YAP_IsIntTerm(t1) ) return false;
else orig = YAP_IntOfTerm(t1); else orig = YAP_IntOfTerm(t1);
/* The second argument must be bound to an integer (the tag) /* The second argument must be bound to an integer (the tag)
or left unbound (i.e. any tag is OK) */ or left unbound (i.e. any tag is OK) */
if (YAP_IsVarTerm(t2)) tag = MPI_ANY_TAG; if (YAP_IsVarTerm(t2)) tag = MPI_ANY_TAG;
else if( !YAP_IsIntTerm(t2) ) return (FALSE); else if( !YAP_IsIntTerm(t2) ) return false;
else tag = YAP_IntOfTerm( t2 ); else tag = YAP_IntOfTerm( t2 );
CONT_TIMER(); CONT_TIMER();
// probe for term' size // probe for term' size
if( MPI_CALL(MPI_Probe( orig, tag, MPI_COMM_WORLD, &status )) != MPI_SUCCESS) { if( MPI_CALL(MPI_Probe( orig, tag, MPI_COMM_WORLD, &status )) != MPI_SUCCESS) {
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(FALSE); return false;
} }
if( MPI_CALL(MPI_Get_count( &status, MPI_CHAR, &len )) != MPI_SUCCESS || if( MPI_CALL(MPI_Get_count( &status, MPI_CHAR, &len )) != MPI_SUCCESS ||
status.MPI_TAG==MPI_UNDEFINED || status.MPI_TAG==MPI_UNDEFINED ||
status.MPI_SOURCE==MPI_UNDEFINED) { status.MPI_SOURCE==MPI_UNDEFINED) {
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(FALSE); return false;
} }
//realloc memory buffer //realloc memory buffer
change_buffer_size((size_t)(len+1)); change_buffer_size((size_t)(len+1));
@ -499,7 +499,7 @@ mpi_recv(void) {
orig = status.MPI_SOURCE; orig = status.MPI_SOURCE;
if( !YAP_Unify(t1, YAP_MkIntTerm(orig))) { if( !YAP_Unify(t1, YAP_MkIntTerm(orig))) {
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(FALSE); return false;
} }
} }
// Already know the tag from MPI_Probe() // Already know the tag from MPI_Probe()
@ -507,7 +507,7 @@ mpi_recv(void) {
tag = status.MPI_TAG; tag = status.MPI_TAG;
if( !YAP_Unify(t2, YAP_MkIntTerm(status.MPI_TAG))) { if( !YAP_Unify(t2, YAP_MkIntTerm(status.MPI_TAG))) {
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(FALSE); return false;
} }
} }
// Receive the message as a string // Receive the message as a string
@ -517,7 +517,7 @@ mpi_recv(void) {
package (containing size) was sent properly, but there was a glitch with package (containing size) was sent properly, but there was a glitch with
the actual content! */ the actual content! */
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(FALSE); return false;
} }
#ifdef DEBUG #ifdef DEBUG
write_msg(__FUNCTION__,__FILE__,__LINE__,"%s(%s,%u, MPI_CHAR,%d,%d)\n",__FUNCTION__,BUFFER_PTR, BUFFER_LEN, orig, tag); write_msg(__FUNCTION__,__FILE__,__LINE__,"%s(%s,%u, MPI_CHAR,%d,%d)\n",__FUNCTION__,BUFFER_PTR, BUFFER_LEN, orig, tag);
@ -525,50 +525,50 @@ mpi_recv(void) {
MSG_RECV(BUFFER_LEN); MSG_RECV(BUFFER_LEN);
t4=string2term(BUFFER_PTR,&BUFFER_LEN); t4=string2term(BUFFER_PTR,&BUFFER_LEN);
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(YAP_Unify(YAP_ARG3,t4)); return(YAP_Unify(YAP_ARG3,t4));
} }
/* /*
* Implements a non-blocking receive operation. * Implements a non-blocking receive operation.
* mpi_irecv(?Source,?Tag,-Handle). * mpi_irecv(?Source,?Tag,-Handle).
*/ */
static int static YAP_Bool
mpi_irecv(void) { mpi_irecv(void) {
YAP_Term t1 = YAP_Deref(YAP_ARG1), YAP_Term t1 = YAP_Deref(YAP_ARG1),
t2 = YAP_Deref(YAP_ARG2), t2 = YAP_Deref(YAP_ARG2),
t3 = YAP_Deref(YAP_ARG3); t3 = YAP_Deref(YAP_ARG3);
int tag, orig; int tag, orig;
MPI_Request *handle=(MPI_Request*)malloc(sizeof(MPI_Request)); MPI_Request *mpi_req=(MPI_Request*)malloc(sizeof(MPI_Request));
// The third argument (data) must be unbound // The third argument (data) must be unbound
if(!YAP_IsVarTerm(t3)) { if(!YAP_IsVarTerm(t3)) {
//Yap_Error(INSTANTIATION_ERROR, t_data, "mpi_receive"); //Yap_Error(INSTANTIATION_ERROR, t_data, "mpi_receive");
return FALSE; return false;
} }
/* The first argument (Source) must be bound to an integer /* The first argument (Source) must be bound to an integer
(the rank of the source) or left unbound (i.e. any source (the rank of the source) or left unbound (i.e. any source
is OK) */ is OK) */
if (YAP_IsVarTerm(t1)) orig = MPI_ANY_SOURCE; if (YAP_IsVarTerm(t1)) orig = MPI_ANY_SOURCE;
else if( !YAP_IsIntTerm(t1) ) return (FALSE); else if( !YAP_IsIntTerm(t1) ) return false;
else orig = YAP_IntOfTerm(t1); else orig = YAP_IntOfTerm(t1);
/* The third argument must be bound to an integer (the tag) /* The third argument must be bound to an integer (the tag)
or left unbound (i.e. any tag is OK) */ or left unbound (i.e. any tag is OK) */
if (YAP_IsVarTerm(t2)) tag = MPI_ANY_TAG; if (YAP_IsVarTerm(t2)) tag = MPI_ANY_TAG;
else if( !YAP_IsIntTerm(t2) ) return (FALSE); else if( !YAP_IsIntTerm(t2) ) return false;
else tag = YAP_IntOfTerm( t2 ); else tag = YAP_IntOfTerm( t2 );
CONT_TIMER(); CONT_TIMER();
RESET_BUFFER; RESET_BUFFER();
if( MPI_CALL(MPI_Irecv( BUFFER_PTR, BLOCK_SIZE, MPI_CHAR, orig, tag, if( MPI_CALL(MPI_Irecv( BUFFER_PTR, BLOCK_SIZE, MPI_CHAR, orig, tag,
MPI_COMM_WORLD, handle )) != MPI_SUCCESS ) { MPI_COMM_WORLD, mpi_req )) != MPI_SUCCESS ) {
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(FALSE); return false;
} }
new_request(handle,BUFFER_PTR); new_request(mpi_req,BUFFER_PTR);
DEL_BUFFER; // force the realocation of a new memory block DEL_BUFFER();
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(YAP_Unify(t3,YAP_MkIntTerm(HANDLE2INT(handle)))); return YAP_Unify(t3,YAP_MkIntTerm(HANDLE2INT(mpi_req)));
} }
/* /*
@ -579,7 +579,7 @@ mpi_irecv(void) {
* buffer. * buffer.
* mpi_wait(+Handle,-Status). * mpi_wait(+Handle,-Status).
*/ */
static int static YAP_Bool
mpi_wait(void) { mpi_wait(void) {
YAP_Term t1 = YAP_Deref(YAP_ARG1), // Handle YAP_Term t1 = YAP_Deref(YAP_ARG1), // Handle
t2 = YAP_Deref(YAP_ARG2); // Status t2 = YAP_Deref(YAP_ARG2); // Status
@ -588,27 +588,29 @@ mpi_wait(void) {
// The first argument must be an integer (an handle) // The first argument must be an integer (an handle)
if(!YAP_IsIntTerm(t1)) { if(!YAP_IsIntTerm(t1)) {
return FALSE; return false;
} }
handle=INT2HANDLE(YAP_IntOfTerm(t1)); handle=INT2HANDLE(YAP_IntOfTerm(t1));
CONT_TIMER(); CONT_TIMER();
// probe for term' size // probe for term' size
if( MPI_CALL(MPI_Wait( handle , &status )) != MPI_SUCCESS ) { if( MPI_CALL(MPI_Wait( handle , &status )) != MPI_SUCCESS ) {
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(FALSE); return false;
} }
free_request(handle); free_request(handle);
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(YAP_Unify(t2,YAP_MkIntTerm(status.MPI_ERROR))); return(YAP_Unify(t2,YAP_MkIntTerm(status.MPI_ERROR)));
} }
/* /*
* mpi_test(+Handle,-Status)
*
* Provides information regarding a handle, ie. if a communication operation has been completed. * Provides information regarding a handle, ie. if a communication operation has been completed.
* If the operation has been completed the predicate succeeds with the completion status, * If the operation has been completed the predicate succeeds with the completion status,
* otherwise it fails. * otherwise it fails.
* mpi_test(+Handle,-Status). * ).
*/ */
static int static YAP_Bool
mpi_test(void) { mpi_test(void) {
YAP_Term t1 = YAP_Deref(YAP_ARG1), // Handle YAP_Term t1 = YAP_Deref(YAP_ARG1), // Handle
t2 = YAP_Deref(YAP_ARG2); // Status t2 = YAP_Deref(YAP_ARG2); // Status
@ -618,31 +620,32 @@ mpi_test(void) {
// The first argument (handle) must be an integer // The first argument (handle) must be an integer
if(!YAP_IsIntTerm(t1)) { if(!YAP_IsIntTerm(t1)) {
return FALSE; return false;
} }
CONT_TIMER(); CONT_TIMER();
handle=INT2HANDLE(YAP_IntOfTerm(t1)); handle=INT2HANDLE(YAP_IntOfTerm(t1));
// //
MPI_CALL(MPI_Test( handle , &flag, &status )); MPI_CALL(MPI_Test( handle , &flag, &status ));
if( flag != TRUE ) { if( flag != true ) {
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(FALSE); return false;
} }
free_request(handle); free_request(handle);
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(YAP_Unify(t2,YAP_MkIntTerm(status.MPI_ERROR))); return(YAP_Unify(t2,YAP_MkIntTerm(status.MPI_ERROR)));
} }
/* /** mpi_wait(+Handle,-Status,-Data
*
* Completes a non-blocking operation. IF the operation was a send, the * Completes a non-blocking operation. IF the operation was a send, the
* function waits until the message is buffered or sent by the runtime * function waits until the message is buffered or sent by the runtime
* system. At this point the send buffer is released. If the operation * system. At this point the send buffer is released. If the operation
* was a receive, it waits until the message is copied to the receive * was a receive, it waits until the message is copied to the receive
* buffer. * buffer.
* mpi_wait(+Handle,-Status,-Data). * .
*/ */
static int static YAP_Bool
mpi_wait_recv(void) { mpi_wait_recv(void) {
YAP_Term t1 = YAP_Deref(YAP_ARG1); // data YAP_Term t1 = YAP_Deref(YAP_ARG1); // data
MPI_Status status; MPI_Status status;
@ -653,7 +656,7 @@ mpi_wait_recv(void) {
// The first argument (handle) must be an integer // The first argument (handle) must be an integer
if(!YAP_IsIntTerm(t1)) { if(!YAP_IsIntTerm(t1)) {
return FALSE; return false;
} }
CONT_TIMER(); CONT_TIMER();
@ -662,7 +665,7 @@ mpi_wait_recv(void) {
// wait for communication completion // wait for communication completion
if( MPI_CALL(MPI_Wait( handle , &status )) != MPI_SUCCESS) { if( MPI_CALL(MPI_Wait( handle , &status )) != MPI_SUCCESS) {
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(FALSE); return false;
} }
len=YAP_SizeOfExportedTerm(s); len=YAP_SizeOfExportedTerm(s);
// make sure we only fetch ARG3 after constructing the term // make sure we only fetch ARG3 after constructing the term
@ -671,7 +674,7 @@ mpi_wait_recv(void) {
free_request(handle); free_request(handle);
PAUSE_TIMER(); PAUSE_TIMER();
ret=YAP_Unify(YAP_ARG3,out); ret=YAP_Unify(YAP_ARG3,out);
RETURN(ret & YAP_Unify(YAP_ARG2,YAP_MkIntTerm(status.MPI_ERROR))); return(ret & YAP_Unify(YAP_ARG2,YAP_MkIntTerm(status.MPI_ERROR)));
} }
/* /*
@ -681,7 +684,7 @@ mpi_wait_recv(void) {
* *
* mpi_test(+Handle,-Status,-Data). * mpi_test(+Handle,-Status,-Data).
*/ */
static int static YAP_Bool
mpi_test_recv(void) { mpi_test_recv(void) {
YAP_Term t1 = YAP_Deref(YAP_ARG1); // data YAP_Term t1 = YAP_Deref(YAP_ARG1); // data
@ -693,7 +696,7 @@ mpi_test_recv(void) {
// The first argument (handle) must be an integer // The first argument (handle) must be an integer
if(!YAP_IsIntTerm(t1)) { if(!YAP_IsIntTerm(t1)) {
return FALSE; return false;
} }
CONT_TIMER(); CONT_TIMER();
@ -701,7 +704,7 @@ mpi_test_recv(void) {
// //
if( MPI_CALL(MPI_Test( handle , &flag, &status ))!=MPI_SUCCESS) { if( MPI_CALL(MPI_Test( handle , &flag, &status ))!=MPI_SUCCESS) {
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(FALSE); return false;
} }
s=(char*)get_request(handle); s=(char*)get_request(handle);
len=strlen(s); len=strlen(s);
@ -710,19 +713,19 @@ mpi_test_recv(void) {
ret=YAP_Unify(YAP_ARG3,out); ret=YAP_Unify(YAP_ARG3,out);
free_request(handle); free_request(handle);
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(ret & YAP_Unify(YAP_ARG2,YAP_MkIntTerm(status.MPI_ERROR))); return(ret & YAP_Unify(YAP_ARG2,YAP_MkIntTerm(status.MPI_ERROR)));
} }
/* /*
* Collective communication function that performs a barrier synchronization among all processes. * Collective communication function that performs a barrier synchronization among all processes.
* mpi_barrier * mpi_barrier
*/ */
static int static YAP_Bool
mpi_barrier(void) { mpi_barrier(void) {
CONT_TIMER(); CONT_TIMER();
int ret=MPI_CALL(MPI_Barrier(MPI_COMM_WORLD)); int ret=MPI_CALL(MPI_Barrier(MPI_COMM_WORLD));
PAUSE_TIMER(); PAUSE_TIMER();
return (ret==MPI_SUCCESS?TRUE:FALSE); return (ret==MPI_SUCCESS?true:false);
} }
/*********************************** /***********************************
* Broadcast * Broadcast
@ -735,7 +738,7 @@ mpi_barrier(void) {
* *
* mpi_bcast(+Root,+Data). * mpi_bcast(+Root,+Data).
*/ */
static int static YAP_Bool
mpi_bcast(void) { mpi_bcast(void) {
YAP_Term t1 = YAP_Deref(YAP_ARG1), YAP_Term t1 = YAP_Deref(YAP_ARG1),
t2 = YAP_Deref(YAP_ARG2); t2 = YAP_Deref(YAP_ARG2);
@ -745,7 +748,7 @@ mpi_bcast(void) {
int rank; int rank;
//The arguments should be bound //The arguments should be bound
if(!YAP_IsIntTerm(t1)) { if(!YAP_IsIntTerm(t1)) {
return FALSE; return false;
} }
MPI_CALL(MPI_Comm_rank(MPI_COMM_WORLD, &rank)); MPI_CALL(MPI_Comm_rank(MPI_COMM_WORLD, &rank));
@ -757,12 +760,12 @@ mpi_bcast(void) {
write_msg(__FUNCTION__,__FILE__,__LINE__,"mpi_bcast(%s,%u, MPI_CHAR,%d)\n",str,len,root); write_msg(__FUNCTION__,__FILE__,__LINE__,"mpi_bcast(%s,%u, MPI_CHAR,%d)\n",str,len,root);
#endif #endif
} else { } else {
RESET_BUFFER; RESET_BUFFER();
str = BUFFER_PTR; str = BUFFER_PTR;
len = BLOCK_SIZE; len = BLOCK_SIZE;
} }
// send the data // send the data
val=(MPI_CALL(MPI_Bcast( str, len, MPI_CHAR, root, MPI_COMM_WORLD))==MPI_SUCCESS?TRUE:FALSE); val=(MPI_CALL(MPI_Bcast( str, len, MPI_CHAR, root, MPI_COMM_WORLD))==MPI_SUCCESS?true:false);
#ifdef MPISTATS #ifdef MPISTATS
@ -780,9 +783,9 @@ mpi_bcast(void) {
out = string2term(str,(size_t*)&len); out = string2term(str,(size_t*)&len);
MSG_RECV(len); MSG_RECV(len);
if (!YAP_Unify(YAP_ARG2, out)) if (!YAP_Unify(YAP_ARG2, out))
return FALSE; return false;
} }
RETURN(val); return(val);
} }
/* /*
@ -792,7 +795,7 @@ mpi_bcast(void) {
* To be able to use a regular MPI_Recv to recv the messages, one should use mpi_bcast2 * To be able to use a regular MPI_Recv to recv the messages, one should use mpi_bcast2
* mpi_bcast_int(+Root,+Data,+Tag). * mpi_bcast_int(+Root,+Data,+Tag).
*/ */
static int static YAP_Bool
my_bcast(YAP_Term t1,YAP_Term t2, YAP_Term t3) { my_bcast(YAP_Term t1,YAP_Term t2, YAP_Term t3) {
int root; int root;
int k,worldsize; int k,worldsize;
@ -802,7 +805,7 @@ my_bcast(YAP_Term t1,YAP_Term t2, YAP_Term t3) {
//The arguments should be bound //The arguments should be bound
if(YAP_IsVarTerm(t2) || !YAP_IsIntTerm(t1) || !YAP_IsIntTerm(t3)) { if(YAP_IsVarTerm(t2) || !YAP_IsIntTerm(t1) || !YAP_IsIntTerm(t3)) {
return FALSE; return false;
} }
CONT_TIMER(); CONT_TIMER();
@ -819,19 +822,19 @@ my_bcast(YAP_Term t1,YAP_Term t2, YAP_Term t3) {
MSG_SENT(len); MSG_SENT(len);
if(MPI_CALL(MPI_Send( str, len, MPI_CHAR, k, tag, MPI_COMM_WORLD))!=MPI_SUCCESS) { if(MPI_CALL(MPI_Send( str, len, MPI_CHAR, k, tag, MPI_COMM_WORLD))!=MPI_SUCCESS) {
PAUSE_TIMER(); PAUSE_TIMER();
return(FALSE); return false;
} }
#ifdef DEBUG #ifdef DEBUG
write_msg(__FUNCTION__,__FILE__,__LINE__,"bcast2(%s,%u, MPI_CHAR,%d,%d)\n",str,len,k,tag); write_msg(__FUNCTION__,__FILE__,__LINE__,"bcast2(%s,%u, MPI_CHAR,%d,%d)\n",str,len,k,tag);
#endif #endif
} }
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(TRUE); return true;
} }
/* /*
* mpi_bcast(+Root,+Data). * mpi_bcast(+Root,+Data).
*/ */
static int static YAP_Bool
mpi_bcast2(void) { mpi_bcast2(void) {
return my_bcast(YAP_ARG1,YAP_ARG2,YAP_MkIntTerm(0)); return my_bcast(YAP_ARG1,YAP_ARG2,YAP_MkIntTerm(0));
} }
@ -843,7 +846,7 @@ mpi_bcast2(void) {
* *
* mpi_bcast(+Root,+Data,+Tag). * mpi_bcast(+Root,+Data,+Tag).
*/ */
static int static YAP_Bool
mpi_bcast3(void) { mpi_bcast3(void) {
return my_bcast(YAP_ARG1,YAP_ARG2,YAP_ARG3); return my_bcast(YAP_ARG1,YAP_ARG2,YAP_ARG3);
} }
@ -852,7 +855,7 @@ mpi_bcast3(void) {
* all other processes of the group. * all other processes of the group.
* mpi_ibcast(+Root,+Data,+Tag). * mpi_ibcast(+Root,+Data,+Tag).
*/ */
static int static YAP_Bool
my_ibcast(YAP_Term t1,YAP_Term t2, YAP_Term t3) { my_ibcast(YAP_Term t1,YAP_Term t2, YAP_Term t3) {
int root; int root;
int k,worldsize; int k,worldsize;
@ -864,7 +867,7 @@ my_ibcast(YAP_Term t1,YAP_Term t2, YAP_Term t3) {
//fprintf(stderr,"ibcast1"); //fprintf(stderr,"ibcast1");
//The arguments should be bound //The arguments should be bound
if(YAP_IsVarTerm(t2) || !YAP_IsIntTerm(t1) || !YAP_IsIntTerm(t3)) { if(YAP_IsVarTerm(t2) || !YAP_IsIntTerm(t1) || !YAP_IsIntTerm(t3)) {
return FALSE; return false;
} }
CONT_TIMER(); CONT_TIMER();
@ -878,7 +881,7 @@ my_ibcast(YAP_Term t1,YAP_Term t2, YAP_Term t3) {
b=new_broadcast(); b=new_broadcast();
if ( b==NULL ) { if ( b==NULL ) {
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(FALSE); return false;
} }
//fprintf(stderr,"ibcast3"); //fprintf(stderr,"ibcast3");
for(k=0;k<=worldsize-1;++k) { for(k=0;k<=worldsize-1;++k) {
@ -889,7 +892,7 @@ my_ibcast(YAP_Term t1,YAP_Term t2, YAP_Term t3) {
if(MPI_CALL(MPI_Isend(str, len, MPI_CHAR, k, tag, MPI_COMM_WORLD,handle))!=MPI_SUCCESS) { if(MPI_CALL(MPI_Isend(str, len, MPI_CHAR, k, tag, MPI_COMM_WORLD,handle))!=MPI_SUCCESS) {
free(handle); free(handle);
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(FALSE); return false;
} }
new_broadcast_request(b,handle,str); new_broadcast_request(b,handle,str);
//new_request(handle,str); //new_request(handle,str);
@ -899,7 +902,7 @@ my_ibcast(YAP_Term t1,YAP_Term t2, YAP_Term t3) {
if(!b->nreq)//release b if no messages were sent (worldsize==1) if(!b->nreq)//release b if no messages were sent (worldsize==1)
free(b); free(b);
#ifdef DEBUG #if defined(DEBUG) && defined(MALLINFO)
{ {
struct mallinfo s = mallinfo(); struct mallinfo s = mallinfo();
printf("%d: %d=%d/%d\n",getpid(),s.arena,s.uordblks,s.fordblks); //vsc printf("%d: %d=%d/%d\n",getpid(),s.arena,s.uordblks,s.fordblks); //vsc
@ -907,7 +910,7 @@ my_ibcast(YAP_Term t1,YAP_Term t2, YAP_Term t3) {
#endif #endif
PAUSE_TIMER(); PAUSE_TIMER();
//fprintf(stderr,"ibcast4"); //fprintf(stderr,"ibcast4");
RETURN(TRUE); return true;
} }
/* /*
* Broadcasts a message from the process with rank "root" to * Broadcasts a message from the process with rank "root" to
@ -916,14 +919,14 @@ my_ibcast(YAP_Term t1,YAP_Term t2, YAP_Term t3) {
* The message is sent using MPI_Isend * The message is sent using MPI_Isend
* mpi_ibcast(+Root,+Data,+Tag). * mpi_ibcast(+Root,+Data,+Tag).
*/ */
static int static YAP_Bool
mpi_ibcast3(void) { mpi_ibcast3(void) {
return my_ibcast(YAP_ARG1,YAP_ARG2,YAP_ARG3); return my_ibcast(YAP_ARG1,YAP_ARG2,YAP_ARG3);
} }
/* /*
* mpi_ibcast(+Root,+Data). * mpi_ibcast(+Root,+Data).
*/ */
static int static YAP_Bool
mpi_ibcast2(void) { mpi_ibcast2(void) {
return my_ibcast(YAP_ARG1,YAP_ARG2,YAP_MkIntTerm(0)); return my_ibcast(YAP_ARG1,YAP_ARG2,YAP_MkIntTerm(0));
} }
@ -947,7 +950,7 @@ gc(hashtable ht) {
handle=INT2HANDLE(node->value); handle=INT2HANDLE(node->value);
MPI_CALL(MPI_Test( handle , &flag, &status )); MPI_CALL(MPI_Test( handle , &flag, &status ));
if ( flag==TRUE) { if ( flag==true) {
MPI_CALL(MPI_Wait(handle,&status)); MPI_CALL(MPI_Wait(handle,&status));
#ifdef DEBUG #ifdef DEBUG
write_msg(__FUNCTION__,__FILE__,__LINE__,"Released handle...%s\n",(char*)node->obj); write_msg(__FUNCTION__,__FILE__,__LINE__,"Released handle...%s\n",(char*)node->obj);
@ -961,7 +964,7 @@ gc(hashtable ht) {
/* /*
* *
*/ */
static int static YAP_Bool
mpi_gc(void) { mpi_gc(void) {
//write_msg(__FUNCTION__,__FILE__,__LINE__,"MPI_gc>: requests=%d\n",requests->n_entries); //write_msg(__FUNCTION__,__FILE__,__LINE__,"MPI_gc>: requests=%d\n",requests->n_entries);
CONT_TIMER(); CONT_TIMER();
@ -971,28 +974,30 @@ mpi_gc(void) {
gc(broadcasts); gc(broadcasts);
//write_msg(__FUNCTION__,__FILE__,__LINE__,"MPI_gc<: requests=%d\n",requests->n_entries); //write_msg(__FUNCTION__,__FILE__,__LINE__,"MPI_gc<: requests=%d\n",requests->n_entries);
PAUSE_TIMER(); PAUSE_TIMER();
RETURN(TRUE); return true;
} }
size_t BLOCK_SIZE=4*1024; size_t BLOCK_SIZE=4*1024;
static int static YAP_Bool
mpi_default_buffer_size(void) mpi_default_buffer_size(void)
{ {
YAP_Term t2; YAP_Term t2;
intptr_t IBLOCK_SIZE;
if (!YAP_Unify(YAP_ARG1,YAP_MkIntTerm(BLOCK_SIZE))) if (!YAP_Unify(YAP_ARG1,YAP_MkIntTerm(BLOCK_SIZE)))
return FALSE; return false;
t2 = YAP_ARG2; t2 = YAP_ARG2;
if (YAP_IsVarTerm(t2)) if (YAP_IsVarTerm(t2))
return TRUE; return true;
if (!YAP_IsIntTerm(t2)) if (!YAP_IsIntTerm(t2))
return FALSE; return false;
BLOCK_SIZE= YAP_IntOfTerm(t2); IBLOCK_SIZE= YAP_IntOfTerm(t2);
if (BLOCK_SIZE < 0) { if (IBLOCK_SIZE < 0) {
BLOCK_SIZE=4*1024; IBLOCK_SIZE=4*1024;
return FALSE; return false;
} }
return TRUE; BLOCK_SIZE = IBLOCK_SIZE;
return true;
} }
/******************************************************************** /********************************************************************
@ -1003,7 +1008,7 @@ init_mpi(void) {
requests=new_hashtable(HASHSIZE); requests=new_hashtable(HASHSIZE);
broadcasts=new_hashtable(HASHSIZE); broadcasts=new_hashtable(HASHSIZE);
DEL_BUFFER; DEL_BUFFER();
YAP_UserCPredicate( "mpi_init", mpi_init,0); // mpi_init/0 YAP_UserCPredicate( "mpi_init", mpi_init,0); // mpi_init/0
#ifdef USE_THREADS #ifdef USE_THREADS
YAP_UserCPredicate( "mpi_init_rcv_thread", mpi_init_rcv_thread,1); // mpi_init_rcv_thread(+HandleMsgGoal/1) YAP_UserCPredicate( "mpi_init_rcv_thread", mpi_init_rcv_thread,1); // mpi_init_rcv_thread(+HandleMsgGoal/1)

View File

@ -53,6 +53,7 @@ macro_log_feature (SQLITE3_FOUND "SQLite3"
"http://www.sqlite3.org" FALSE) "http://www.sqlite3.org" FALSE)
if (ODBC_FOUND OR MYSQL_FOUND OR SQLITE3_FOUND) if (ODBC_FOUND OR MYSQL_FOUND OR SQLITE3_FOUND)
add_definitions (-DUSE_MYDDAS=1)
add_library (myddas SHARED ${MYDDAS_SOURCES}) add_library (myddas SHARED ${MYDDAS_SOURCES})
target_link_libraries(myddas libYap) target_link_libraries(myddas libYap)
if (ODBC_FOUND) if (ODBC_FOUND)

View File

@ -48,7 +48,7 @@ MYDDAS_SOURCES= \
myddas_mysql.c \ myddas_mysql.c \
myddas_odbc.c \ myddas_odbc.c \
myddas_sqlite3.c \ myddas_sqlite3.c \
myddas_util.c \ myddas_util.c \
myddas_initialization.c \ myddas_initialization.c \
myddas_shared.c \ myddas_shared.c \
myddas_statistics.c \ myddas_statistics.c \
@ -93,8 +93,8 @@ install_myddas:
if [ $$count -ne 0 ]; then \ if [ $$count -ne 0 ]; then \
mkdir -p $(DESTDIR)$(SHAREDIR); \ mkdir -p $(DESTDIR)$(SHAREDIR); \
for p in $(MYDDAS_PROLOG); \ for p in $(MYDDAS_PROLOG); \
do name=`basename $$p .ypp`; echo $$name;\ do name=`basename $$p .ypp`; echo $$name;\
cpp $(YAP_EXTRAS) -P -E -w $$p > $(DESTDIR)$(SHAREDIR)/$$name.yap; \ cpp $(YAP_EXTRAS) -P -E -w $$p > $(DESTDIR)$(SHAREDIR)/$$name.yap; \
done; \ done; \
fi fi

View File

@ -1,6 +1,6 @@
/* MYDDAS */ /* MYDDAS */
#if defined MYDDAS_MYSQL || defined MYDDAS_ODCB || defined MYDDAS_SQLITE3 #ifdef USE_MYDDAS
/* myddas_initialization.c */ /* myddas_initialization.c */
MYDDAS_GLOBAL myddas_init_initialize_myddas(void); MYDDAS_GLOBAL myddas_init_initialize_myddas(void);
@ -77,4 +77,3 @@ void Yap_InitBackMYDDAS_SharedPreds(void);
#if defined MYDDAS_TOP_LEVEL && defined MYDDAS_MYSQL //&& defined HAVE_LIBREADLINE #if defined MYDDAS_TOP_LEVEL && defined MYDDAS_MYSQL //&& defined HAVE_LIBREADLINE
void Yap_InitMYDDAS_TopLevelPreds(void); void Yap_InitMYDDAS_TopLevelPreds(void);
#endif #endif

View File

@ -14,8 +14,8 @@ AC_ARG_ENABLE(myddas,
else else
yap_cv_myddas=$withval yap_cv_myddas=$withval
LDFLAGS="$LDFLAGS -L${yap_cv_myddas}/lib " LDFLAGS="$LDFLAGS -L${yap_cv_myddas}/lib "
CPPFLAGS="$CPPFLAGS -I${yap_cv_myddas}/include " CPPFLAGS="$CPPFLAGS -I${yap_cv_myddas}/include "
MYDDAS_CPPFLAGS="$MYDDAS_CPPFLAGS -I${yap_cv_myddas}/include " MYDDAS_CPPFLAGS="$MYDDAS_CPPFLAGS -I${yap_cv_myddas}/include "
fi, fi,
[yap_cv_myddas=/usr]) [yap_cv_myddas=/usr])
@ -28,7 +28,7 @@ AC_ARG_WITH(mysql,
else else
yap_cv_mysql=$withval yap_cv_mysql=$withval
LDFLAGS="$LDFLAGS -L${yap_cv_mysql}/lib " LDFLAGS="$LDFLAGS -L${yap_cv_mysql}/lib "
CPPFLAGS="$CPPFLAGS -I${yap_cv_mysql}/include " CPPFLAGS="$CPPFLAGS -I${yap_cv_mysql}/include "
MYDDAS_CPPFLAGS="$MYDDAS_CPPFLAGS -I${yap_cv_mysql}/include " MYDDAS_CPPFLAGS="$MYDDAS_CPPFLAGS -I${yap_cv_mysql}/include "
fi, fi,
[yap_cv_mysql=/usr]) [yap_cv_mysql=/usr])
@ -42,7 +42,7 @@ AC_ARG_WITH(odbc,
else else
yap_cv_odbc=$withval yap_cv_odbc=$withval
LDFLAGS="$LDFLAGS -L${yap_cv_odbc}/lib " LDFLAGS="$LDFLAGS -L${yap_cv_odbc}/lib "
CPPFLAGS="$CPPFLAGS -I${yap_cv_odbc}/include " CPPFLAGS="$CPPFLAGS -I${yap_cv_odbc}/include "
MYDDAS_CPPFLAGS="$MYDDAS_CPPFLAGS -I${yap_cv_odbc}/include " MYDDAS_CPPFLAGS="$MYDDAS_CPPFLAGS -I${yap_cv_odbc}/include "
fi, fi,
[yap_cv_odbc=/usr]) [yap_cv_odbc=/usr])
@ -56,8 +56,8 @@ AC_ARG_WITH(sqlite3,
else else
yap_cv_sqlite3=$withval yap_cv_sqlite3=$withval
LDFLAGS="$LDFLAGS -L${yap_cv_sqlite3}/lib " LDFLAGS="$LDFLAGS -L${yap_cv_sqlite3}/lib "
CPPFLAGS="$CPPFLAGS -I${yap_cv_sqlite3}/include " CPPFLAGS="$CPPFLAGS -I${yap_cv_sqlite3}/include "
MYDDAS_CPPFLAGS="$MYDDAS_CPPFLAGS -I${yap_cv_sqlite3}/include " MYDDAS_CPPFLAGS="$MYDDAS_CPPFLAGS -I${yap_cv_sqlite3}/include "
fi, fi,
[yap_cv_sqlite3=/usr]) [yap_cv_sqlite3=/usr])
@ -83,17 +83,18 @@ then
dnl check for mysql dnl check for mysql
AC_SEARCH_LIBS(mysql_init, [mysqlclient], [yap_cv_mysql="yes" MYDDAS_LIBS="-lmysqlclient $MYDDAS_LIBS"], [yap_cv_mysql="no"]) AC_SEARCH_LIBS(mysql_init, [mysqlclient], [yap_cv_mysql="yes" MYDDAS_LIBS="-lmysqlclient $MYDDAS_LIBS"], [yap_cv_mysql="no"])
AC_CHECK_HEADERS(mysql/mysql.h, [], [yap_cv_mysql="no"]) AC_CHECK_HEADERS(mysql/mysql.h, [], [yap_cv_mysql="no"])
if test "$yap_cv_mysql" = yes if test "$yap_cv_mysql" = yes
then then
YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_MYSQL" use_myddas=true
YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_MYSQL"
fi fi
dnl check for odbc dnl check for odbc
case "$target_os" in case "$target_os" in
*darwin*) *darwin*)
LIBS="$LIBS -framework CoreFoundation" LIBS="$LIBS -framework CoreFoundation"
;; ;;
**) **)
;; ;;
esac esac
AC_SEARCH_LIBS(SQLAllocHandle, [odbc], [yap_cv_odbc="yes"], [yap_cv_odbc="no"]) AC_SEARCH_LIBS(SQLAllocHandle, [odbc], [yap_cv_odbc="yes"], [yap_cv_odbc="no"])
@ -116,11 +117,12 @@ then
#from SWI ODBC library. #from SWI ODBC library.
AC_CHECK_HEADERS(windef.h) AC_CHECK_HEADERS(windef.h)
AC_CHECK_HEADERS(sql.h, [yap_cv_odbc="yes" ], [yap_cv_odbc="no"]) AC_CHECK_HEADERS(sql.h, [yap_cv_odbc="yes" ], [yap_cv_odbc="no"])
if test "$yap_cv_odbc" != no if test "$yap_cv_odbc" != no
then then
use_myddas=true
YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_ODBC" YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_ODBC"
fi fi
#from SWI PROSQLITE library. #from SWI PROSQLITE library.
AC_CHECK_LIB(sqlite3, sqlite3_open, AC_CHECK_LIB(sqlite3, sqlite3_open,
LIBS="-lsqlite3 $LIBS" LIBS="-lsqlite3 $LIBS"
@ -128,8 +130,9 @@ then
AC_CHECK_HEADERS(sqlite3.h, [], [yap_cv_sqlite3="no"]) AC_CHECK_HEADERS(sqlite3.h, [], [yap_cv_sqlite3="no"])
if test "$yap_cv_sqlite3" != no if test "$yap_cv_sqlite3" != no
then then
use_myddas=true
YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_SQLITE3" YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_SQLITE3"
fi fi
@ -143,15 +146,18 @@ then
YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_TOP_LEVEL" YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_TOP_LEVEL"
fi fi
if test "$use_myddas" = true; then
YAP_EXTRAS="$YAP_EXTRAS -DUSE_MYDDAS=1"
fi
MYDDAS_LIBS="$LIBS" MYDDAS_LIBS="$LIBS"
LIBS="$OLD_LIBS" LIBS="$OLD_LIBS"
CPPFLAGS="$OLD_CPPFLAGS" CPPFLAGS="$OLD_CPPFLAGS"
else else
ENABLE_MYDDAS="" ENABLE_MYDDAS=""
fi fi
AC_SUBST(PKG_MYDDAS) AC_SUBST(PKG_MYDDAS)
AC_SUBST(MYDDAS_CPPFLAGS) AC_SUBST(MYDDAS_CPPFLAGS)
AC_SUBST(MYDDAS_LIBS) AC_SUBST(MYDDAS_LIBS)

View File

@ -1,4 +1,4 @@
#if defined MYDDAS_ODBC || defined MYDDAS_MYSQL || defined MYDDAS_SQLITE3 #ifdef USE_MYDDAS
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -15,13 +15,13 @@
MYDDAS_GLOBAL MYDDAS_GLOBAL
myddas_init_initialize_myddas(void){ myddas_init_initialize_myddas(void){
MYDDAS_GLOBAL global = NULL; MYDDAS_GLOBAL global = NULL;
/* We cannot call MYDDAS_MALLOC were because the global /* We cannot call MYDDAS_MALLOC were because the global
register isn't yet initialized */ register isn't yet initialized */
global = (MYDDAS_GLOBAL) malloc (sizeof(struct myddas_global)); global = (MYDDAS_GLOBAL) malloc (sizeof(struct myddas_global));
#ifdef DEBUG #ifdef DEBUG
printf ("MALLOC %p %s %d\n",global,__FILE__,__LINE__); printf ("MALLOC %p %s %d\n",global,__FILE__,__LINE__);
#endif #endif
global->myddas_top_connections = NULL; global->myddas_top_connections = NULL;
#ifdef MYDDAS_TOP_LEVEL #ifdef MYDDAS_TOP_LEVEL
global->myddas_top_level_connection = NULL; global->myddas_top_level_connection = NULL;
@ -30,7 +30,7 @@ myddas_init_initialize_myddas(void){
global->myddas_statistics = (MYDDAS_GLOBAL_STATS) malloc (sizeof(struct myddas_global_stats)); global->myddas_statistics = (MYDDAS_GLOBAL_STATS) malloc (sizeof(struct myddas_global_stats));
#ifdef DEBUG #ifdef DEBUG
printf ("MALLOC %p %s %d\n",global->myddas_statistics,__FILE__,__LINE__); printf ("MALLOC %p %s %d\n",global->myddas_statistics,__FILE__,__LINE__);
#endif #endif
global->myddas_statistics->stats = NULL; global->myddas_statistics->stats = NULL;
#endif #endif
@ -46,18 +46,18 @@ myddas_init_initialize_myddas(void){
global->free_called = 0; global->free_called = 0;
global->memory_freed = 0; global->memory_freed = 0;
#endif #endif
return global; return global;
} }
/* Inserts the new node on the front of the list */ /* Inserts the new node on the front of the list */
MYDDAS_UTIL_CONNECTION MYDDAS_UTIL_CONNECTION
myddas_init_initialize_connection(void *conn,void *enviromment, myddas_init_initialize_connection(void *conn,void *enviromment,
MYDDAS_UTIL_CONNECTION next){ MYDDAS_UTIL_CONNECTION next){
CACHE_REGS CACHE_REGS
MYDDAS_UTIL_CONNECTION new = NULL; MYDDAS_UTIL_CONNECTION new = NULL;
MYDDAS_MALLOC(new,struct myddas_list_connection); MYDDAS_MALLOC(new,struct myddas_list_connection);
if (new == NULL) if (new == NULL)
{ {
return NULL; return NULL;
@ -74,11 +74,11 @@ myddas_init_initialize_connection(void *conn,void *enviromment,
/* List integrity */ /* List integrity */
new->next=next; new->next=next;
new->previous=NULL; new->previous=NULL;
/* If there's already at least one node /* If there's already at least one node
on the list */ on the list */
if (next != NULL) if (next != NULL)
next->previous=new; next->previous=new;
#ifdef MYDDAS_STATS #ifdef MYDDAS_STATS
new->stats = NULL; new->stats = NULL;
new->stats = myddas_stats_initialize_connection_stats(); new->stats = myddas_stats_initialize_connection_stats();
@ -86,30 +86,30 @@ myddas_init_initialize_connection(void *conn,void *enviromment,
return new; return new;
} }
MYDDAS_UTIL_PREDICATE MYDDAS_UTIL_PREDICATE
myddas_init_initialize_predicate(char *pred_name, int pred_arity, myddas_init_initialize_predicate(char *pred_name, int pred_arity,
char *pred_module, MYDDAS_UTIL_PREDICATE next){ char *pred_module, MYDDAS_UTIL_PREDICATE next){
CACHE_REGS CACHE_REGS
MYDDAS_UTIL_PREDICATE new = NULL; MYDDAS_UTIL_PREDICATE new = NULL;
MYDDAS_MALLOC(new,struct myddas_list_preds); MYDDAS_MALLOC(new,struct myddas_list_preds);
if (new == NULL) if (new == NULL)
{ {
return NULL; return NULL;
} }
new->pred_name=pred_name; new->pred_name=pred_name;
new->pred_arity=pred_arity; new->pred_arity=pred_arity;
new->pred_module=pred_module; new->pred_module=pred_module;
/* List integrity */ /* List integrity */
new->next=next; new->next=next;
new->previous=NULL; new->previous=NULL;
/* If there's already at least one node /* If there's already at least one node
on the list */ on the list */
if (next != NULL) if (next != NULL)
next->previous=new; next->previous=new;
return new; return new;
} }
#endif #endif

View File

@ -15,7 +15,7 @@
* * * *
*************************************************************************/ *************************************************************************/
#if defined MYDDAS_MYSQL || defined MYDDAS_ODBC #ifdef USE_MYDDAS
#include "Yap.h" #include "Yap.h"
#include "Yatom.h" #include "Yatom.h"
@ -44,7 +44,7 @@ static Int c_db_stats( USES_REGS1 );
static Int c_db_stats_walltime( USES_REGS1 ); static Int c_db_stats_walltime( USES_REGS1 );
static Int c_db_stats_translate( USES_REGS1 ); static Int c_db_stats_translate( USES_REGS1 );
static Int c_db_stats_time( USES_REGS1 ); static Int c_db_stats_time( USES_REGS1 );
#endif #endif
#ifdef DEBUG #ifdef DEBUG
static Int c_db_check( USES_REGS1 ); static Int c_db_check( USES_REGS1 );
#endif #endif
@ -53,7 +53,7 @@ void Yap_InitMYDDAS_SharedPreds(void)
{ {
/* c_db_initialize_myddas */ /* c_db_initialize_myddas */
Yap_InitCPred("c_db_initialize_myddas",0,c_db_initialize_myddas, 0); Yap_InitCPred("c_db_initialize_myddas",0,c_db_initialize_myddas, 0);
/* c_db_connection_type: Connection x Type */ /* c_db_connection_type: Connection x Type */
Yap_InitCPred("c_db_connection_type",2,c_db_connection_type, 0); Yap_InitCPred("c_db_connection_type",2,c_db_connection_type, 0);
@ -62,7 +62,7 @@ void Yap_InitMYDDAS_SharedPreds(void)
/* c_db_check_if_exists_pred : PredName * Arity * Connection */ /* c_db_check_if_exists_pred : PredName * Arity * Connection */
Yap_InitCPred("c_db_check_if_exists_pred",3,c_db_check_if_exists_pred, 0); Yap_InitCPred("c_db_check_if_exists_pred",3,c_db_check_if_exists_pred, 0);
/* c_db_delete_pred : Module * PredName * Arity */ /* c_db_delete_pred : Module * PredName * Arity */
Yap_InitCPred("c_db_delete_predicate",3,c_db_delete_predicate, 0); Yap_InitCPred("c_db_delete_predicate",3,c_db_delete_predicate, 0);
@ -92,20 +92,20 @@ void Yap_InitBackMYDDAS_SharedPreds(void)
{ {
/* Gives all the predicates associated to a given connection */ /* Gives all the predicates associated to a given connection */
Yap_InitCPredBack("c_db_preds_conn", 4, sizeof(Int), Yap_InitCPredBack("c_db_preds_conn", 4, sizeof(Int),
c_db_preds_conn_start, c_db_preds_conn_start,
c_db_preds_conn_continue, 0); c_db_preds_conn_continue, 0);
/* Gives all the connections stored on the MYDDAS Structure*/ /* Gives all the connections stored on the MYDDAS Structure*/
Yap_InitCPredBack("c_db_connection", 1, sizeof(Int), Yap_InitCPredBack("c_db_connection", 1, sizeof(Int),
c_db_connection_start, c_db_connection_start,
c_db_connection_continue, 0); c_db_connection_continue, 0);
} }
/* Initialize all of the MYDDAS global structures */ /* Initialize all of the MYDDAS global structures */
static Int static Int
c_db_initialize_myddas( USES_REGS1 ){ c_db_initialize_myddas( USES_REGS1 ){
Yap_REGS.MYDDAS_GLOBAL_POINTER = myddas_init_initialize_myddas(); Yap_REGS.MYDDAS_GLOBAL_POINTER = myddas_init_initialize_myddas();
#ifdef MYDDAS_STATS #ifdef MYDDAS_STATS
Yap_REGS.MYDDAS_GLOBAL_POINTER = myddas_stats_initialize_global_stats(Yap_REGS.MYDDAS_GLOBAL_POINTER); Yap_REGS.MYDDAS_GLOBAL_POINTER = myddas_stats_initialize_global_stats(Yap_REGS.MYDDAS_GLOBAL_POINTER);
#endif /* MYDDAS_STATS */ #endif /* MYDDAS_STATS */
@ -113,40 +113,40 @@ c_db_initialize_myddas( USES_REGS1 ){
} }
/* Gives the type of a given connection, /* Gives the type of a given connection,
in other words, type will be mysql or odbc in other words, type will be mysql or odbc
NOTE: In order to use this predicate, the connection*/ NOTE: In order to use this predicate, the connection*/
/* c_db_connection_type: +Connection * ?Type */ /* c_db_connection_type: +Connection * ?Type */
static Int static Int
c_db_connection_type ( USES_REGS1 ){ c_db_connection_type ( USES_REGS1 ){
Term arg_con = Deref(ARG1); Term arg_con = Deref(ARG1);
Term arg_type = Deref(ARG2); Term arg_type = Deref(ARG2);
Int *con = (Int *) IntegerOfTerm(arg_con); Int *con = (Int *) IntegerOfTerm(arg_con);
Int type = myddas_util_connection_type(con); Int type = myddas_util_connection_type(con);
if (type == 1) /* MYSQL Connection */ if (type == 1) /* MYSQL Connection */
Yap_unify(arg_type, MkAtomTerm(Yap_LookupAtom("mysql"))); Yap_unify(arg_type, MkAtomTerm(Yap_LookupAtom("mysql")));
else if (type ==2) /* ODBC Connection */ else if (type ==2) /* ODBC Connection */
Yap_unify(arg_type, MkAtomTerm(Yap_LookupAtom("odbc"))); Yap_unify(arg_type, MkAtomTerm(Yap_LookupAtom("odbc")));
else /* Not a valid connection*/ else /* Not a valid connection*/
return FALSE; return FALSE;
return TRUE; return TRUE;
} }
/* db_add_preds: PredName * Arity * Module * Connection*/ /* db_add_preds: PredName * Arity * Module * Connection*/
static Int static Int
c_db_add_preds ( USES_REGS1 ){ c_db_add_preds ( USES_REGS1 ){
Term arg_nome = Deref(ARG1); Term arg_nome = Deref(ARG1);
Term arg_aridade = Deref(ARG2); Term arg_aridade = Deref(ARG2);
Term arg_module = Deref(ARG3); Term arg_module = Deref(ARG3);
Term arg_conn = Deref(ARG4); Term arg_conn = Deref(ARG4);
/* PredEntry *pe; */ /* PredEntry *pe; */
/* pe = RepPredProp(PredPropByFunc(FunctorOfTerm(arg_pred),arg_module)); */ /* pe = RepPredProp(PredPropByFunc(FunctorOfTerm(arg_pred),arg_module)); */
char *nome = AtomName(AtomOfTerm(arg_nome)); char *nome = AtomName(AtomOfTerm(arg_nome));
char *module = AtomName(AtomOfTerm(arg_module)); char *module = AtomName(AtomOfTerm(arg_module));
@ -160,22 +160,22 @@ c_db_add_preds ( USES_REGS1 ){
#endif #endif
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
static Int static Int
c_db_check_if_exists_pred ( USES_REGS1 ){ c_db_check_if_exists_pred ( USES_REGS1 ){
Term arg_nome = Deref(ARG1); Term arg_nome = Deref(ARG1);
Term arg_aridade = Deref(ARG2); Term arg_aridade = Deref(ARG2);
Term arg_module = Deref(ARG3); Term arg_module = Deref(ARG3);
char *nome = AtomName(AtomOfTerm(arg_nome)); char *nome = AtomName(AtomOfTerm(arg_nome));
char *module = AtomName(AtomOfTerm(arg_module)); char *module = AtomName(AtomOfTerm(arg_module));
Int aridade = IntegerOfTerm(arg_aridade); Int aridade = IntegerOfTerm(arg_aridade);
if (myddas_util_search_predicate(nome,aridade,module) == NULL) if (myddas_util_search_predicate(nome,aridade,module) == NULL)
return FALSE; return FALSE;
else else
@ -183,17 +183,17 @@ c_db_check_if_exists_pred ( USES_REGS1 ){
} }
static Int static Int
c_db_delete_predicate( USES_REGS1 ){ c_db_delete_predicate( USES_REGS1 ){
Term arg_module = Deref(ARG1); Term arg_module = Deref(ARG1);
Term arg_name = Deref(ARG2); Term arg_name = Deref(ARG2);
Term arg_arity = Deref(ARG3); Term arg_arity = Deref(ARG3);
char *module = AtomName(AtomOfTerm(arg_module)); char *module = AtomName(AtomOfTerm(arg_module));
char *name = AtomName(AtomOfTerm(arg_name)); char *name = AtomName(AtomOfTerm(arg_name));
Int arity = IntegerOfTerm(arg_arity); Int arity = IntegerOfTerm(arg_arity);
MYDDAS_UTIL_PREDICATE predicate = MYDDAS_UTIL_PREDICATE predicate =
myddas_util_search_predicate(name,arity,module); myddas_util_search_predicate(name,arity,module);
if (predicate == NULL) if (predicate == NULL)
return FALSE; return FALSE;
@ -204,29 +204,29 @@ c_db_delete_predicate( USES_REGS1 ){
} }
static Int static Int
c_db_multi_queries_number( USES_REGS1 ){ c_db_multi_queries_number( USES_REGS1 ){
Term arg_conn = Deref(ARG1); Term arg_conn = Deref(ARG1);
Term arg_number = Deref(ARG2); Term arg_number = Deref(ARG2);
Int *conn = (Int *) IntegerOfTerm(arg_conn); Int *conn = (Int *) IntegerOfTerm(arg_conn);
MYDDAS_UTIL_CONNECTION node = MYDDAS_UTIL_CONNECTION node =
myddas_util_search_connection(conn); myddas_util_search_connection(conn);
if (node == NULL) if (node == NULL)
return FALSE; return FALSE;
if (IsVarTerm(arg_number)){ if (IsVarTerm(arg_number)){
Yap_unify(arg_number,MkIntegerTerm(((Int)myddas_util_get_total_multi_queries_number(node))+1)); Yap_unify(arg_number,MkIntegerTerm(((Int)myddas_util_get_total_multi_queries_number(node))+1));
} }
else { else {
Int number = IntegerOfTerm(arg_number); Int number = IntegerOfTerm(arg_number);
number--; number--;
myddas_util_set_total_multi_queries_number(node,number); myddas_util_set_total_multi_queries_number(node,number);
} }
return TRUE; return TRUE;
} }
static Int static Int
@ -236,17 +236,17 @@ c_db_connection_start( USES_REGS1 ){
Yap_REGS.MYDDAS_GLOBAL_POINTER->myddas_top_connections; Yap_REGS.MYDDAS_GLOBAL_POINTER->myddas_top_connections;
EXTRA_CBACK_ARG(1,1)=(CELL) MkIntegerTerm((Int)node); EXTRA_CBACK_ARG(1,1)=(CELL) MkIntegerTerm((Int)node);
return (c_db_connection_continue( PASS_REGS1 )); return (c_db_connection_continue( PASS_REGS1 ));
} }
static Int static Int
c_db_connection_continue( USES_REGS1 ){ c_db_connection_continue( USES_REGS1 ){
Term arg_conn = Deref(ARG1); Term arg_conn = Deref(ARG1);
MYDDAS_UTIL_CONNECTION node; MYDDAS_UTIL_CONNECTION node;
node = (MYDDAS_UTIL_CONNECTION) IntegerOfTerm(EXTRA_CBACK_ARG(1,1)); node = (MYDDAS_UTIL_CONNECTION) IntegerOfTerm(EXTRA_CBACK_ARG(1,1));
/* There is no connections */ /* There is no connections */
if (node == NULL) if (node == NULL)
{ {
@ -256,35 +256,35 @@ c_db_connection_continue( USES_REGS1 ){
Yap_unify(arg_conn, MkIntegerTerm((Int)(node->connection))); Yap_unify(arg_conn, MkIntegerTerm((Int)(node->connection)));
EXTRA_CBACK_ARG(1,1)=(CELL) MkIntegerTerm((Int)(node->next)); EXTRA_CBACK_ARG(1,1)=(CELL) MkIntegerTerm((Int)(node->next));
return TRUE; return TRUE;
} }
/* db_preds_conn : Connection(+) * Pred_name(-) * Pred_arity */ /* db_preds_conn : Connection(+) * Pred_name(-) * Pred_arity */
static Int static Int
c_db_preds_conn_start ( USES_REGS1 ){ c_db_preds_conn_start ( USES_REGS1 ){
Term arg_conn = Deref(ARG1); Term arg_conn = Deref(ARG1);
Int *conn = (Int *) IntegerOfTerm(arg_conn); Int *conn = (Int *) IntegerOfTerm(arg_conn);
MYDDAS_UTIL_CONNECTION node = MYDDAS_UTIL_CONNECTION node =
myddas_util_search_connection(conn); myddas_util_search_connection(conn);
/* Caso a ligacao já tenha sido apagada*/ /* Caso a ligacao já tenha sido apagada*/
if (node == NULL) if (node == NULL)
{ {
cut_fail(); cut_fail();
return FALSE; return FALSE;
} }
void *pointer = myddas_util_get_list_pred(node); void *pointer = myddas_util_get_list_pred(node);
EXTRA_CBACK_ARG(4,1)=(CELL) MkIntegerTerm((Int)pointer); EXTRA_CBACK_ARG(4,1)=(CELL) MkIntegerTerm((Int)pointer);
return (c_db_preds_conn_continue( PASS_REGS1 )); return (c_db_preds_conn_continue( PASS_REGS1 ));
} }
/* db_preds_conn : Connection(+) * Pred_name(-) * Pred_arity*/ /* db_preds_conn : Connection(+) * Pred_name(-) * Pred_arity*/
static Int static Int
c_db_preds_conn_continue ( USES_REGS1 ){ c_db_preds_conn_continue ( USES_REGS1 ){
Term module = Deref(ARG2); Term module = Deref(ARG2);
Term name = Deref(ARG3); Term name = Deref(ARG3);
@ -292,11 +292,11 @@ c_db_preds_conn_continue ( USES_REGS1 ){
void *pointer; void *pointer;
pointer = (void *) IntegerOfTerm(EXTRA_CBACK_ARG(4,1)); pointer = (void *) IntegerOfTerm(EXTRA_CBACK_ARG(4,1));
if (pointer != NULL) if (pointer != NULL)
{ {
EXTRA_CBACK_ARG(4,1)=(CELL) MkIntegerTerm((Int)myddas_util_get_pred_next(pointer)); EXTRA_CBACK_ARG(4,1)=(CELL) MkIntegerTerm((Int)myddas_util_get_pred_next(pointer));
if (!Yap_unify(module, MkAtomTerm(Yap_LookupAtom(myddas_util_get_pred_module(pointer))))){ if (!Yap_unify(module, MkAtomTerm(Yap_LookupAtom(myddas_util_get_pred_module(pointer))))){
return FALSE; return FALSE;
} }
@ -318,7 +318,7 @@ c_db_preds_conn_continue ( USES_REGS1 ){
#ifdef DEBUG #ifdef DEBUG
static Int static Int
c_db_check( USES_REGS1 ){ c_db_check( USES_REGS1 ){
check_int(); check_int();
return TRUE; return TRUE;
@ -352,7 +352,7 @@ c_db_stats_translate( USES_REGS1 ){
MYDDAS_STATS_TIME start; MYDDAS_STATS_TIME start;
MYDDAS_STATS_TIME end; MYDDAS_STATS_TIME end;
MYDDAS_STATS_TIME total_time,diff; MYDDAS_STATS_TIME total_time,diff;
#ifdef DEBUG #ifdef DEBUG
@ -363,20 +363,20 @@ c_db_stats_translate( USES_REGS1 ){
end = (MYDDAS_STATS_TIME) IntegerOfTerm(arg_end); end = (MYDDAS_STATS_TIME) IntegerOfTerm(arg_end);
MYDDAS_STATS_GET_TRANSLATE(total_time); MYDDAS_STATS_GET_TRANSLATE(total_time);
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(diff,time_copy); MYDDAS_STATS_INITIALIZE_TIME_STRUCT(diff,time_copy);
myddas_stats_subtract_time(diff,end,start); myddas_stats_subtract_time(diff,end,start);
diff = myddas_stats_time_copy_to_final(diff); diff = myddas_stats_time_copy_to_final(diff);
myddas_stats_add_time(total_time,diff,total_time); myddas_stats_add_time(total_time,diff,total_time);
MyddasULInt count; MyddasULInt count;
MYDDAS_STATS_GET_TRANSLATE_COUNT(count); MYDDAS_STATS_GET_TRANSLATE_COUNT(count);
MYDDAS_STATS_SET_TRANSLATE_COUNT(++count); MYDDAS_STATS_SET_TRANSLATE_COUNT(++count);
MYDDAS_FREE(diff,struct myddas_stats_time_struct); MYDDAS_FREE(diff,struct myddas_stats_time_struct);
MYDDAS_FREE(start, struct myddas_stats_time_struct); MYDDAS_FREE(start, struct myddas_stats_time_struct);
MYDDAS_FREE(end, struct myddas_stats_time_struct); MYDDAS_FREE(end, struct myddas_stats_time_struct);
return TRUE; return TRUE;
#ifdef DEBUG #ifdef DEBUG
} }
@ -391,9 +391,9 @@ static Int
c_db_stats_time( USES_REGS1 ){ c_db_stats_time( USES_REGS1 ){
Term arg_reference = Deref(ARG1); Term arg_reference = Deref(ARG1);
Term arg_time = Deref(ARG2); Term arg_time = Deref(ARG2);
Term final_term; Term final_term;
MYDDAS_STATS_STRUCT struc = (MYDDAS_STATS_STRUCT)IntegerOfTerm(arg_reference); MYDDAS_STATS_STRUCT struc = (MYDDAS_STATS_STRUCT)IntegerOfTerm(arg_reference);
Functor functor_count = Yap_MkFunctor(Yap_LookupAtom("count"),1); Functor functor_count = Yap_MkFunctor(Yap_LookupAtom("count"),1);
Term count_number[1]; Term count_number[1];
@ -401,7 +401,7 @@ c_db_stats_time( USES_REGS1 ){
Term number[1]; Term number[1];
switch(struc->type){ switch(struc->type){
case integer: case integer:
{ {
Functor functor = Yap_MkFunctor(Yap_LookupAtom("myddas_integer"),2); Functor functor = Yap_MkFunctor(Yap_LookupAtom("myddas_integer"),2);
@ -412,26 +412,26 @@ c_db_stats_time( USES_REGS1 ){
integer = struc->u.integer.integer; integer = struc->u.integer.integer;
number[0] = MkIntegerTerm(integer); number[0] = MkIntegerTerm(integer);
integer_number[0] = Yap_MkApplTerm(unit,1,number);; integer_number[0] = Yap_MkApplTerm(unit,1,number);;
count_number[0] = MkIntegerTerm(struc->count); count_number[0] = MkIntegerTerm(struc->count);
integer_number[1] = Yap_MkApplTerm(functor_count,1,count_number); integer_number[1] = Yap_MkApplTerm(functor_count,1,count_number);
final_term = Yap_MkApplTerm(functor,2,integer_number); final_term = Yap_MkApplTerm(functor,2,integer_number);
break; break;
} }
case time_str: case time_str:
{ {
MYDDAS_STATS_TIME time = struc->u.time_str.time_str; MYDDAS_STATS_TIME time = struc->u.time_str.time_str;
Functor functor = Yap_MkFunctor(Yap_LookupAtom("myddas_time"),6); Functor functor = Yap_MkFunctor(Yap_LookupAtom("myddas_time"),6);
Term time_numbers[6]; Term time_numbers[6];
MyddasUInt time_number; MyddasUInt time_number;
unit = Yap_MkFunctor(Yap_LookupAtom("hours"),1); unit = Yap_MkFunctor(Yap_LookupAtom("hours"),1);
time_number = MYDDAS_STATS_TIME_HOURS(time); time_number = MYDDAS_STATS_TIME_HOURS(time);
number[0] = MkIntegerTerm(time_number); number[0] = MkIntegerTerm(time_number);
time_numbers[0] = Yap_MkApplTerm(unit,1,number);; time_numbers[0] = Yap_MkApplTerm(unit,1,number);;
unit = Yap_MkFunctor(Yap_LookupAtom("minutes"),1); unit = Yap_MkFunctor(Yap_LookupAtom("minutes"),1);
time_number = MYDDAS_STATS_TIME_MINUTES(time); time_number = MYDDAS_STATS_TIME_MINUTES(time);
number[0] = MkIntegerTerm(time_number); number[0] = MkIntegerTerm(time_number);
@ -441,23 +441,23 @@ c_db_stats_time( USES_REGS1 ){
time_number = MYDDAS_STATS_TIME_SECONDS(time); time_number = MYDDAS_STATS_TIME_SECONDS(time);
number[0] = MkIntegerTerm(time_number); number[0] = MkIntegerTerm(time_number);
time_numbers[2] = Yap_MkApplTerm(unit,1,number);; time_numbers[2] = Yap_MkApplTerm(unit,1,number);;
unit = Yap_MkFunctor(Yap_LookupAtom("miliseconds"),1); unit = Yap_MkFunctor(Yap_LookupAtom("miliseconds"),1);
time_number = MYDDAS_STATS_TIME_MILISECONDS(time); time_number = MYDDAS_STATS_TIME_MILISECONDS(time);
number[0] = MkIntegerTerm(time_number); number[0] = MkIntegerTerm(time_number);
time_numbers[3] = Yap_MkApplTerm(unit,1,number);; time_numbers[3] = Yap_MkApplTerm(unit,1,number);;
unit = Yap_MkFunctor(Yap_LookupAtom("microseconds"),1); unit = Yap_MkFunctor(Yap_LookupAtom("microseconds"),1);
time_number = MYDDAS_STATS_TIME_MICROSECONDS(time); time_number = MYDDAS_STATS_TIME_MICROSECONDS(time);
number[0] = MkIntegerTerm(time_number); number[0] = MkIntegerTerm(time_number);
time_numbers[4] = Yap_MkApplTerm(unit,1,number);; time_numbers[4] = Yap_MkApplTerm(unit,1,number);;
count_number[0] = MkIntegerTerm(struc->count); count_number[0] = MkIntegerTerm(struc->count);
time_numbers[5] = Yap_MkApplTerm(functor_count,1,count_number); time_numbers[5] = Yap_MkApplTerm(functor_count,1,count_number);
final_term = Yap_MkApplTerm(functor,6,time_numbers); final_term = Yap_MkApplTerm(functor,6,time_numbers);
break; break;
} }
default: default:
#ifdef DEBUG #ifdef DEBUG
printf ("ERROR: c_db_stats_time unknow option\n"); printf ("ERROR: c_db_stats_time unknow option\n");
@ -465,7 +465,7 @@ c_db_stats_time( USES_REGS1 ){
return FALSE; return FALSE;
break; break;
} }
if (!Yap_unify(arg_time,final_term )){ if (!Yap_unify(arg_time,final_term )){
return FALSE; return FALSE;
} }
@ -474,20 +474,20 @@ c_db_stats_time( USES_REGS1 ){
} }
//Returns the stats of this module in a list //Returns the stats of this module in a list
static Int static Int
c_db_stats( USES_REGS1 ) { c_db_stats( USES_REGS1 ) {
Term arg_conn = Deref(ARG1); Term arg_conn = Deref(ARG1);
Term arg_list = Deref(ARG2); Term arg_list = Deref(ARG2);
MyddasPointer *conn = (MyddasPointer *) (IntegerOfTerm(arg_conn)); MyddasPointer *conn = (MyddasPointer *) (IntegerOfTerm(arg_conn));
// TODO // TODO
if (get_myddas_top() == 0 ){ /* We want all the statistics */ if (get_myddas_top() == 0 ){ /* We want all the statistics */
return FALSE; return FALSE;
} }
MYDDAS_STATS_STRUCT str; MYDDAS_STATS_STRUCT str;
MYDDAS_UTIL_CONNECTION MYDDAS_UTIL_CONNECTION
node = myddas_util_search_connection(conn); node = myddas_util_search_connection(conn);
Term head, list; Term head, list;
list = arg_list; list = arg_list;
@ -514,7 +514,7 @@ c_db_stats( USES_REGS1 ) {
// processing all the SQL Querys // processing all the SQL Querys
head = HeadOfTerm(list); head = HeadOfTerm(list);
list = TailOfTerm(list); list = TailOfTerm(list);
str = myddas_stats_get_stat(node->stats,1); str = myddas_stats_get_stat(node->stats,1);
Yap_unify(head, MkIntegerTerm((MyddasInt)str)); Yap_unify(head, MkIntegerTerm((MyddasInt)str));
#ifdef DEBUG #ifdef DEBUG
@ -522,13 +522,13 @@ c_db_stats( USES_REGS1 ) {
printf ("Reference to time Spent by the Server, on all the SQL Querys\n"); printf ("Reference to time Spent by the Server, on all the SQL Querys\n");
MYDDAS_STATS_PRINT_TIME_STRUCT(time); MYDDAS_STATS_PRINT_TIME_STRUCT(time);
printf ("\n\n"); printf ("\n\n");
#endif #endif
//[Index 3] -> Total of Time Spent by the DB Server //[Index 3] -> Total of Time Spent by the DB Server
// processing a the last SQL Query // processing a the last SQL Query
head = HeadOfTerm(list); head = HeadOfTerm(list);
list = TailOfTerm(list); list = TailOfTerm(list);
str = myddas_stats_get_stat(node->stats,2); str = myddas_stats_get_stat(node->stats,2);
Yap_unify(head, MkIntegerTerm((MyddasInt)str)); Yap_unify(head, MkIntegerTerm((MyddasInt)str));
#ifdef DEBUG #ifdef DEBUG
@ -537,12 +537,12 @@ c_db_stats( USES_REGS1 ) {
MYDDAS_STATS_PRINT_TIME_STRUCT(time); MYDDAS_STATS_PRINT_TIME_STRUCT(time);
printf ("\n\n"); printf ("\n\n");
#endif #endif
//[Index 4] -> Total of Time Spent by the DB Server //[Index 4] -> Total of Time Spent by the DB Server
// transfering all the results of the SQL Querys // transfering all the results of the SQL Querys
head = HeadOfTerm(list); head = HeadOfTerm(list);
list = TailOfTerm(list); list = TailOfTerm(list);
str = myddas_stats_get_stat(node->stats,3); str = myddas_stats_get_stat(node->stats,3);
Yap_unify(head, MkIntegerTerm((MyddasInt)str)); Yap_unify(head, MkIntegerTerm((MyddasInt)str));
#ifdef DEBUG #ifdef DEBUG
@ -551,12 +551,12 @@ c_db_stats( USES_REGS1 ) {
MYDDAS_STATS_PRINT_TIME_STRUCT(time); MYDDAS_STATS_PRINT_TIME_STRUCT(time);
printf ("\n\n"); printf ("\n\n");
#endif #endif
//[Index 5] -> Total of Time Spent by the DB Server //[Index 5] -> Total of Time Spent by the DB Server
// transfering the result of the last SQL Query // transfering the result of the last SQL Query
head = HeadOfTerm(list); head = HeadOfTerm(list);
list = TailOfTerm(list); list = TailOfTerm(list);
str = myddas_stats_get_stat(node->stats,4); str = myddas_stats_get_stat(node->stats,4);
Yap_unify(head, MkIntegerTerm((MyddasInt)str)); Yap_unify(head, MkIntegerTerm((MyddasInt)str));
#ifdef DEBUG #ifdef DEBUG
@ -565,14 +565,14 @@ c_db_stats( USES_REGS1 ) {
MYDDAS_STATS_PRINT_TIME_STRUCT(time); MYDDAS_STATS_PRINT_TIME_STRUCT(time);
printf ("\n\n"); printf ("\n\n");
#endif #endif
//[Index 6] -> Total of Time Spent by the //[Index 6] -> Total of Time Spent by the
// db_row_function // db_row_function
head = HeadOfTerm(list); head = HeadOfTerm(list);
list = TailOfTerm(list); list = TailOfTerm(list);
str = myddas_stats_get_stat(Yap_REGS.MYDDAS_GLOBAL_POINTER->myddas_statistics->stats,1); str = myddas_stats_get_stat(Yap_REGS.MYDDAS_GLOBAL_POINTER->myddas_statistics->stats,1);
Yap_unify(head, MkIntegerTerm((MyddasInt)str)); Yap_unify(head, MkIntegerTerm((MyddasInt)str));
#ifdef DEBUG #ifdef DEBUG
MYDDAS_STATS_GET_DB_ROW_FUNCTION(time); MYDDAS_STATS_GET_DB_ROW_FUNCTION(time);
@ -580,8 +580,8 @@ c_db_stats( USES_REGS1 ) {
MYDDAS_STATS_PRINT_TIME_STRUCT(time); MYDDAS_STATS_PRINT_TIME_STRUCT(time);
printf ("\n\n"); printf ("\n\n");
#endif #endif
//[Index 7] -> Total of Bytes Transfered by the //[Index 7] -> Total of Bytes Transfered by the
// DB Server on all SQL Querys // DB Server on all SQL Querys
head = HeadOfTerm(list); head = HeadOfTerm(list);
list = TailOfTerm(list); list = TailOfTerm(list);
@ -593,12 +593,12 @@ c_db_stats( USES_REGS1 ) {
printf ("Bytes Transfered by the DB Server from all querys\n"); printf ("Bytes Transfered by the DB Server from all querys\n");
printf ("%llu\n\n",(MyddasULInt)number); printf ("%llu\n\n",(MyddasULInt)number);
#endif #endif
//[Index 8] -> Total of Bytes Transfered by the //[Index 8] -> Total of Bytes Transfered by the
// DB Server on the last SQL Query // DB Server on the last SQL Query
head = HeadOfTerm(list); head = HeadOfTerm(list);
list = TailOfTerm(list); list = TailOfTerm(list);
str = myddas_stats_get_stat(node->stats,7); str = myddas_stats_get_stat(node->stats,7);
Yap_unify(head, MkIntegerTerm((MyddasPointer)str)); Yap_unify(head, MkIntegerTerm((MyddasPointer)str));
#ifdef DEBUG #ifdef DEBUG
@ -618,7 +618,7 @@ c_db_stats( USES_REGS1 ) {
printf ("%llu\n\n",(MyddasULInt)number); printf ("%llu\n\n",(MyddasULInt)number);
#endif #endif
//[Index 10] -> Total of Time Spent by the //[Index 10] -> Total of Time Spent by the
// translate predicate // translate predicate
head = HeadOfTerm(list); head = HeadOfTerm(list);
list = TailOfTerm(list); list = TailOfTerm(list);
@ -640,13 +640,13 @@ c_db_stats( USES_REGS1 ) {
printf ("Number of times malloc was called in MYDDAS: %lu \n",nr); printf ("Number of times malloc was called in MYDDAS: %lu \n",nr);
MYDDAS_MEMORY_FREE_NR(nr); MYDDAS_MEMORY_FREE_NR(nr);
printf ("Number of times free was called in MYDDAS : %lu \n",nr); printf ("Number of times free was called in MYDDAS : %lu \n",nr);
MYDDAS_MEMORY_MALLOC_SIZE(nr); MYDDAS_MEMORY_MALLOC_SIZE(nr);
printf ("Total memory allocated in MYDDAS: %lu \n",nr); printf ("Total memory allocated in MYDDAS: %lu \n",nr);
MYDDAS_MEMORY_FREE_SIZE(nr); MYDDAS_MEMORY_FREE_SIZE(nr);
printf ("Total memory freed in MYDDAS : %lu \n",nr); printf ("Total memory freed in MYDDAS : %lu \n",nr);
#endif #endif
return TRUE; return TRUE;
} }
@ -660,7 +660,7 @@ void Yap_MYDDAS_delete_all_myddas_structs(void)
CACHE_REGS CACHE_REGS
/* NAO ESQUECER DE FAZER ISTO TB PARA O DB_CLOSE*/ /* NAO ESQUECER DE FAZER ISTO TB PARA O DB_CLOSE*/
MYDDAS_GLOBAL global = MYDDAS_GLOBAL global =
Yap_REGS.MYDDAS_GLOBAL_POINTER; Yap_REGS.MYDDAS_GLOBAL_POINTER;
/* In case that the MYDDAS module isn't loaded */ /* In case that the MYDDAS module isn't loaded */
@ -669,11 +669,11 @@ void Yap_MYDDAS_delete_all_myddas_structs(void)
MYDDAS_UTIL_CONNECTION connections = MYDDAS_UTIL_CONNECTION connections =
global->myddas_top_connections; global->myddas_top_connections;
/* Delete all connections */ /* Delete all connections */
for(;connections!=NULL;connections=connections->next) for(;connections!=NULL;connections=connections->next)
myddas_util_delete_connection(connections->connection); myddas_util_delete_connection(connections->connection);
#ifdef MYDDAS_STATS #ifdef MYDDAS_STATS
myddas_stats_delete_stats_list(global->myddas_statistics->stats); myddas_stats_delete_stats_list(global->myddas_statistics->stats);
MYDDAS_FREE(global->myddas_statistics,struct myddas_global_stats); MYDDAS_FREE(global->myddas_statistics,struct myddas_global_stats);
@ -687,13 +687,13 @@ void Yap_MYDDAS_delete_all_myddas_structs(void)
printf ("Number of times malloc was called in MYDDAS: " UInt_FORMAT " \n",(UInt)nr); printf ("Number of times malloc was called in MYDDAS: " UInt_FORMAT " \n",(UInt)nr);
MYDDAS_MEMORY_FREE_NR(nr); MYDDAS_MEMORY_FREE_NR(nr);
printf ("Number of times free was called in MYDDAS : " UInt_FORMAT " \n",(UInt)nr); printf ("Number of times free was called in MYDDAS : " UInt_FORMAT " \n",(UInt)nr);
MYDDAS_MEMORY_MALLOC_SIZE(nr); MYDDAS_MEMORY_MALLOC_SIZE(nr);
printf ("Total memory allocated in MYDDAS: " UInt_FORMAT " \n",(UInt)nr); printf ("Total memory allocated in MYDDAS: " UInt_FORMAT " \n",(UInt)nr);
MYDDAS_MEMORY_FREE_SIZE(nr); MYDDAS_MEMORY_FREE_SIZE(nr);
printf ("Total memory freed in MYDDAS : " UInt_FORMAT " \n",(UInt)nr); printf ("Total memory freed in MYDDAS : " UInt_FORMAT " \n",(UInt)nr);
#endif #endif
} }
@ -731,11 +731,11 @@ init_myddas(void)
#ifdef MYDDAS_MYSQL_INIT #ifdef MYDDAS_MYSQL_INIT
if (yap_init->myddas) { if (yap_init->myddas) {
Yap_PutValue(AtomMyddasGoal,MkIntegerTerm(yap_init->myddas)); Yap_PutValue(AtomMyddasGoal,MkIntegerTerm(yap_init->myddas));
/* Mandatory Fields */ /* Mandatory Fields */
Yap_PutValue(AtomMyddasUser,MkAtomTerm(Yap_LookupAtom(yap_init->myddas_user))); Yap_PutValue(AtomMyddasUser,MkAtomTerm(Yap_LookupAtom(yap_init->myddas_user)));
Yap_PutValue(AtomMyddasDB,MkAtomTerm(Yap_LookupAtom(yap_init->myddas_db))); Yap_PutValue(AtomMyddasDB,MkAtomTerm(Yap_LookupAtom(yap_init->myddas_db)));
/* Non-Mandatory Fields */ /* Non-Mandatory Fields */
if (yap_init->myddas_pass != NULL) if (yap_init->myddas_pass != NULL)
Yap_PutValue(AtomMyddasPass,MkAtomTerm(Yap_LookupAtom(yap_init->myddas_pass))); Yap_PutValue(AtomMyddasPass,MkAtomTerm(Yap_LookupAtom(yap_init->myddas_pass)));
@ -762,7 +762,7 @@ int WINAPI PROTO(win_myddas, (HANDLE, DWORD, LPVOID));
int WINAPI win_myddas(HANDLE hinst, DWORD reason, LPVOID reserved) int WINAPI win_myddas(HANDLE hinst, DWORD reason, LPVOID reserved)
{ {
switch (reason) switch (reason)
{ {
case DLL_PROCESS_ATTACH: case DLL_PROCESS_ATTACH:
break; break;