2002-02-22 14:31:45 +00:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright S. Konstantopoulos and Universidade do Porto 2002 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: mpe.c *
|
2003-07-03 16:46:10 +01:00
|
|
|
* Last rev: $Date: 2003-07-03 15:46:10 $ *
|
2002-02-22 14:31:45 +00:00
|
|
|
* mods: *
|
|
|
|
* comments: Interface to an MPE library *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#ifndef lint
|
2015-01-05 16:06:32 +00:00
|
|
|
// static char *rcsid = "$Header: /Users/vitor/Yap/yap-cvsbackup/library/mpi/mpe.c,v 1.6 2003-07-03 15:46:10 stasinos Exp $";
|
2002-02-22 14:31:45 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Yap.h"
|
|
|
|
|
2014-02-18 07:59:47 +00:00
|
|
|
/* Should we use MPI ? */
|
|
|
|
#if defined(HAVE_MPI_H) && (defined(HAVE_LIBMPI) || defined(HAVE_LIBMPICH))
|
|
|
|
#define HAVE_MPI 1
|
|
|
|
#else
|
|
|
|
#define HAVE_MPI 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Should we use MPE ? */
|
|
|
|
#if defined(HAVE_MPI_H) && HAVE_LIBMPE && HAVE_MPI
|
|
|
|
#define HAVE_MPE 1
|
|
|
|
#else
|
|
|
|
#define HAVE_MPE 0
|
|
|
|
#endif
|
|
|
|
|
2002-02-22 14:31:45 +00:00
|
|
|
#if HAVE_MPE
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* for AtomEof */
|
|
|
|
#include "Heap.h"
|
|
|
|
|
|
|
|
#include "yapio.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Yatom.h"
|
|
|
|
#include <mpe.h>
|
|
|
|
|
2014-09-16 19:15:56 +01:00
|
|
|
static Int p_init(void);
|
|
|
|
static Int p_start(void);
|
|
|
|
static Int p_close(void);
|
|
|
|
static Int p_create_event(void);
|
|
|
|
static Int p_create_state(void);
|
|
|
|
static Int p_log(void);
|
2002-02-22 14:31:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Auxiliary Data and Functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* C Predicates
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_init() /* mpe_open */
|
|
|
|
{
|
2002-02-26 15:33:16 +00:00
|
|
|
return (MPE_Init_log() == 0);
|
2002-02-22 14:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
|
|
|
p_start() /* mpe_start */
|
|
|
|
{
|
2002-02-26 15:33:16 +00:00
|
|
|
return (MPE_Start_log() == 0);
|
2002-02-22 14:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Int /* mpe_close(+FileName) */
|
|
|
|
p_close()
|
|
|
|
{
|
2002-02-26 15:33:16 +00:00
|
|
|
Term t_str = Deref(ARG1);
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
/* The arg must be bound to an atom. */
|
|
|
|
if (IsVarTerm(t_str)) {
|
2003-07-03 16:46:10 +01:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t_str, "mpe_close");
|
2002-02-26 15:33:16 +00:00
|
|
|
return (FALSE);
|
|
|
|
} else if( !IsAtomTerm(t_str) ) {
|
2003-07-03 16:46:10 +01:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t_str, "mpe_close");
|
2002-02-26 15:33:16 +00:00
|
|
|
return (FALSE);
|
|
|
|
} else {
|
|
|
|
str = RepAtom(AtomOfTerm(t_str))->StrOfAE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (MPE_Finish_log(str) == 0);
|
2002-02-22 14:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-26 15:33:16 +00:00
|
|
|
static Int /* mpe_create_event(?Event) */
|
2002-02-22 14:31:45 +00:00
|
|
|
p_create_event()
|
|
|
|
{
|
|
|
|
Int event_id;
|
|
|
|
|
|
|
|
event_id = MPE_Log_get_event_number();
|
2003-07-03 16:46:10 +01:00
|
|
|
return Yap_unify(ARG1, MkIntegerTerm(event_id));
|
2002-02-22 14:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int /* mpe_create_state(+Event,+Event,+Text,+Colour) */
|
|
|
|
p_create_state()
|
|
|
|
{
|
2002-02-27 13:41:24 +00:00
|
|
|
Term t_start = Deref(ARG1), t_end = Deref(ARG2),
|
|
|
|
t_descr = Deref(ARG3), t_colour = Deref(ARG4);
|
2002-02-22 14:31:45 +00:00
|
|
|
Int start_id, end_id;
|
|
|
|
char *descr, *colour;
|
2002-02-26 15:33:16 +00:00
|
|
|
int retv;
|
2002-02-22 14:31:45 +00:00
|
|
|
|
2002-02-26 15:33:16 +00:00
|
|
|
/* The first and second args must be bount to integer event IDs. */
|
2002-02-27 13:41:24 +00:00
|
|
|
if (IsVarTerm(t_start)) {
|
2003-07-03 16:46:10 +01:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t_start, "mpe_create_state");
|
2002-02-26 15:33:16 +00:00
|
|
|
return (FALSE);
|
2002-02-27 13:41:24 +00:00
|
|
|
} else if( !IsIntegerTerm(t_start) ) {
|
2003-07-03 16:46:10 +01:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, t_start, "mpe_create_state");
|
2002-02-26 15:33:16 +00:00
|
|
|
return (FALSE);
|
|
|
|
} else {
|
2002-02-27 13:41:24 +00:00
|
|
|
start_id = IntOfTerm(t_start);
|
2002-02-26 15:33:16 +00:00
|
|
|
}
|
2002-02-27 13:41:24 +00:00
|
|
|
if (IsVarTerm(t_end)) {
|
2003-07-03 16:46:10 +01:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t_end, "mpe_create_state");
|
2002-02-26 15:33:16 +00:00
|
|
|
return (FALSE);
|
2002-02-27 13:41:24 +00:00
|
|
|
} else if( !IsIntegerTerm(t_end) ) {
|
2003-07-03 16:46:10 +01:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, t_end, "mpe_create_state");
|
2002-02-26 15:33:16 +00:00
|
|
|
return (FALSE);
|
|
|
|
} else {
|
2002-02-27 13:41:24 +00:00
|
|
|
end_id = IntOfTerm(t_end);
|
2002-02-26 15:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The third and fourth args must be bound to atoms. */
|
2002-02-27 13:41:24 +00:00
|
|
|
if (IsVarTerm(t_descr)) {
|
2003-07-03 16:46:10 +01:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t_descr, "mpe_create_state");
|
2002-02-26 15:33:16 +00:00
|
|
|
return (FALSE);
|
2002-02-27 13:41:24 +00:00
|
|
|
} else if( !IsAtomTerm(t_descr) ) {
|
2003-07-03 16:46:10 +01:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t_descr, "mpe_create_state");
|
2002-02-26 15:33:16 +00:00
|
|
|
return (FALSE);
|
|
|
|
} else {
|
2002-02-27 13:41:24 +00:00
|
|
|
descr = RepAtom(AtomOfTerm(t_descr))->StrOfAE;
|
2002-02-26 15:33:16 +00:00
|
|
|
}
|
2002-02-27 13:41:24 +00:00
|
|
|
if (IsVarTerm(t_colour)) {
|
2003-07-03 16:46:10 +01:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t_colour, "mpe_create_state");
|
2002-02-26 15:33:16 +00:00
|
|
|
return (FALSE);
|
2002-02-27 13:41:24 +00:00
|
|
|
} else if( !IsAtomTerm(t_colour) ) {
|
2003-07-03 16:46:10 +01:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t_colour, "mpe_create_state");
|
2002-02-26 15:33:16 +00:00
|
|
|
return (FALSE);
|
|
|
|
} else {
|
2002-02-27 13:41:24 +00:00
|
|
|
colour = RepAtom(AtomOfTerm(t_colour))->StrOfAE;
|
2002-02-26 15:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
retv = MPE_Describe_state( (int)start_id, (int)end_id, descr, colour );
|
|
|
|
|
|
|
|
return (retv == 0);
|
2002-02-22 14:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Int
|
2002-02-26 15:33:16 +00:00
|
|
|
p_log() /* mpe_log(+EventType, +EventNum, +EventStr) */
|
2002-02-22 14:31:45 +00:00
|
|
|
{
|
2002-02-26 15:33:16 +00:00
|
|
|
Term t_type = Deref(ARG1), t_num = Deref(ARG2), t_str = Deref(ARG3);
|
|
|
|
Int event_id, event;
|
|
|
|
char *descr;
|
|
|
|
|
|
|
|
/* The first arg must be bount to integer event type ID. */
|
|
|
|
if (IsVarTerm(t_type)) {
|
2003-07-03 16:46:10 +01:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t_type, "mpe_log");
|
2002-02-26 15:33:16 +00:00
|
|
|
return (FALSE);
|
|
|
|
} else if( !IsIntegerTerm(t_type) ) {
|
2003-07-03 16:46:10 +01:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, t_type, "mpe_log");
|
2002-02-26 15:33:16 +00:00
|
|
|
return (FALSE);
|
|
|
|
} else {
|
|
|
|
event_id = IntOfTerm(t_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The second arg must be bount to integer event number. */
|
|
|
|
if (IsVarTerm(t_num)) {
|
2003-07-03 16:46:10 +01:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t_num, "mpe_log");
|
2002-02-26 15:33:16 +00:00
|
|
|
return (FALSE);
|
|
|
|
} else if( !IsIntegerTerm(t_num) ) {
|
2003-07-03 16:46:10 +01:00
|
|
|
Yap_Error(TYPE_ERROR_INTEGER, t_num, "mpe_log");
|
2002-02-26 15:33:16 +00:00
|
|
|
return (FALSE);
|
|
|
|
} else {
|
|
|
|
event = IntOfTerm(t_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The third arg must be bound to an atom. */
|
|
|
|
if (IsVarTerm(t_str)) {
|
2003-07-03 16:46:10 +01:00
|
|
|
Yap_Error(INSTANTIATION_ERROR, t_str, "mpe_log");
|
2002-02-26 15:33:16 +00:00
|
|
|
return (FALSE);
|
|
|
|
} else if( !IsAtomTerm(t_str) ) {
|
2003-07-03 16:46:10 +01:00
|
|
|
Yap_Error(TYPE_ERROR_ATOM, t_str, "mpe_log");
|
2002-02-26 15:33:16 +00:00
|
|
|
return (FALSE);
|
|
|
|
} else {
|
|
|
|
descr = RepAtom(AtomOfTerm(t_str))->StrOfAE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ( MPE_Log_event((int)event_id, (int)event, descr) == 0 );
|
2002-02-22 14:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Init
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitMPE(void)
|
2002-02-22 14:31:45 +00:00
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPred( "mpe_open", 0, p_init, SafePredFlag );
|
|
|
|
Yap_InitCPred( "mpe_start", 0, p_start, SafePredFlag );
|
|
|
|
Yap_InitCPred( "mpe_close", 1, p_close, SafePredFlag );
|
|
|
|
Yap_InitCPred( "mpe_create_event", 1, p_create_event, SafePredFlag );
|
|
|
|
Yap_InitCPred( "mpe_create_state", 4, p_create_state, SafePredFlag );
|
|
|
|
Yap_InitCPred( "mpe_log", 3, p_log, SafePredFlag );
|
2002-02-22 14:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_MPE */
|