/************************************************************************* * * * YAP Prolog * * * * Yap Prolog was developed at NCCUP - Universidade do Porto * * * * Copyright S. Konstantopoulos and Universidade do Porto 2002 * * * ************************************************************************** * * * File: mpi.c * * Last rev: $Date: 2002-02-11 20:40:09 $ * * mods: * * comments: Interface to an MPI library * * * *************************************************************************/ #ifndef lint static char *rcsid = "$Header: /Users/vitor/Yap/yap-cvsbackup/library/mpi/mpi.c,v 1.1 2002-02-11 20:40:09 stasinos Exp $"; #endif #include "Yap.h" #include "Yatom.h" #include "yapio.h" /* for AtomEof */ #include "Heap.h" #if HAVE_MPI #include #include #include STATIC_PROTO (Int p_mpi_open, (void)); STATIC_PROTO (Int p_mpi_close, (void)); STATIC_PROTO (Int p_mpi_send, (void)); STATIC_PROTO (Int p_mpi_receive, (void)); /* * Auxiliary Data and Functions */ static Int rank, numprocs, namelen; static char processor_name[MPI_MAX_PROCESSOR_NAME]; /* mini-stream */ static char buf[255]; static int bufptr, buflen; static int mpi_putc(Int stream, Int ch) { if( ch > 0 ) buf[bufptr++] = ch; return ch; } static Int mpi_getc(Int stream) { return buf[bufptr++]; } static Int mpi_eob(void) { return (bufptrTok != Ord (eot_tok)) { /* we got the end of file from an abort */ if (ErrorMessage == "Abort") { TR = old_TR; return(FALSE); } /* we need to force the next reading to also give end of file.*/ buf[bufptr] = EOF; ErrorMessage = "[ Error: end of file found before end of term ]"; } else { /* restore TR */ TR = old_TR; return (unify_constant (ARG2, MkAtomTerm (AtomEof))); } } repeat_cycle: if (ErrorMessage || (t = Parse ()) == 0) { if (ErrorMessage && (strcmp(ErrorMessage,"Stack Overflow") == 0)) { /* ignore term we just built */ H = old_H; if (growstack_in_parser(&old_TR, &tokstart, &VarTable)) { tokptr = toktide = tokstart; ErrorMessage = NULL; goto repeat_cycle; } } TR = old_TR; if (ErrorMessage) YP_fprintf (YP_stderr, "%s", ErrorMessage); else syntax_error (tokstart); YP_fprintf (YP_stderr, " ]\n"); Error(SYSTEM_ERROR,TermNil,NULL); return(FALSE); } else { /* parsing succeeded */ break; } } while (TRUE) { CELL *old_H = H; if (setjmp(IOBotch) == 0) { v = VarNames(VarTable, TermNil); TR = old_TR; break; } else { /* don't need to recheck tokens */ tokstart = NULL; /* restart global */ H = old_H; growstack_in_parser(&old_TR, &tokstart, &VarTable); old_H = H; } } } return unify(t, ARG1); } /* * Init */ void InitMPI(void) { int i,j; Int mpi_argc; char **mpi_argv; mpi_argv = malloc( yap_argc * sizeof(char *) ); mpi_argv[0] = strdup( yap_args[0] ); for( i=1; i