The C-with-Ease implementation can be easily ported to various parallel architectures by providing an appropriate host interface. The host model is described in section 5.1.
The host interface handles all of the low level access to the host, including thread creation and switching, semaphore and mutex functionality and message sending and receiving.
Typically, a host interface consists of a small header file containing definitions of the host characteristics for the Ease library, and another defining the necessary functions. The header file specifies whether it has multiple cells, whether the host has threads, and if those threads are preemptive. It also defines the types for a cell identifier and a thread identifier.
The following functions should be supplied:
_ec_main(argc, argv)
_ec_main. Another part of the Ease
library
supplies a main appropriate for the language compiled. (The
main for a C++ program must be compiled with the correct
compiler to allow for correct handling of global and static
constructors and destructors).
double _getTime()
fatal(msg)
A host interface must either define the macro NTHREAD (for no threads) or supply the following functions and types:
_ec_thread
_createThread(function, void *data, size)
_threadsEqual(a, b)
_initThread(main, argc, argv)
initProcess function of the Ease
scheduler (section
5.5.3). This function allows for splitting the host
interface into two parts: a threads component (shared memory)
and a message passing component (distributed memory).
A message passing library (such as
PVM) and
a selection of threads libraries may be available
depending on the host type.
If the macro EXT_THREADS is defined, then both distributed
and shared memory systems are being used. The threads library should
not supply the functions listed under the basic interface
in section 5.7.1.
The interface specifies that threads are preemptive by defining the
macro PREEMPT. For non-preemptive threads, the following function
must be supplied:
_runThread(thread)
For preemptive threads, the following types and functions must be supplied:
_ec_sem
_createSem(value)
_deleteSem(semaphore)
_waitSem(semaphore)
_signalSem(semaphore)
_ec_mutex
_createMutex()
_deleteMutex(mutex)
_lockMutex(mutex)
_unlockMutex(mutex)
_ec_thread _currentTid()
_setThreadPtr(void *ptr)
void *_getThreadPtr()
_setThreadPtr().
_yieldThread()
A host type that uses message passing should define the macro
_EASE_MULTI. It should supply the following types and functions:
_ec_cellId
_sendMessage(Message)
_localCell()
_isLocal(cell)
_isLocalCtx(context)
_receiveMessages()
TYPE_LAST_TYPE for
its own purposes (such as load balancing and cell allocation).
_receiveMessages() should call the scheduler function
_handleMessage() (section 5.5.3) for messages it
can not handle itself (ie. all message before TYPE_LAST_TYPE).
int _waitMessages(time)
time seconds have elapsed. If a message arrives, then handle
all messages possible (other messages may arrive while
handling the first) and return 0. If the function returns due to timeout,
return 1. If time is negative, then wait indefinitely. Note that
an implementation need never return due to timeout since there is
no minimum time to return.
_selectProcessor()
_freeThread()
selectProcessor to allow for allocation of processes to cells
where there are existing but unused threads.