SCore-D Runtime Development

This document describes skeleton code to develop a SCore-D runtime library.

User-defined functions

All runtime libraries should implement the following two functions:

int score_runtime_resource(void);
void score_runtime_usage(void);

score_runtime_resource() is a callback function that must be implemented by a user program or runtime library. It is used to check user-specified resources of scrun(1) SCore options.
score_runtime_usage() is a callback function that must be implemented to print the usage of the runtime.

Initialization

Firstly scrun(1) invokes the user program specified on its command line on the host where scrun was executed, in order to parse a user-specified resource request and to check if the request is valid or not. This is performed in the score_initialize() function where the score_runtime_resource() function (written by the programmer) is called so the runtime can check the resource request. If the function returns a non-zero value, then user program invocation is aborted, otherwise scrun attempts to login to SCore-D.

After successfully logging in to SCore-D, SCore-D forks and execs the user program on the allocated cluster node(s). Here, score_initialize() is called again on each node. All runtime libraries must call the score_initialize() function prior to accessing variables defined in <score.h> and to communicate via the PM library. Inside score_initialize(), all necessary information passed by SCore-D is retrieved and initialized in PM contexts, so that a user program can communicate with other nodes.

#include <score.h>
void my_runtime_initialize(int argc, char **argv) {
  score_initialize(argc, argv);
  /* score_initialize() does not return, when this program is 
     invoked on a local host. */
  /* When a user program is invoked on one or more cluster nodes,
     the program can reach this point, and the runtime can
     initialize itself. */
}

Resource Checking

A runtime library may check a user-specified resource request before execution of the user program on a cluster. The user-specified resource request can be obtained by calling the score_get_resource_request() function:
#include <score_resource.h>
int score_runtime_resource(void) {
  scoreResourceRequest *rsrc = score_get_resource_request();
	:
  return( 0 );
}
Also, there is a set of resource macros to constrain the resource request.

Setting Idle Flag

The score_become_idle() and score_become_busy() functions let SCore-D know the running state of a user process. If a user process becomes idle, even if the program is actually waiting in a busy-wait loop, it is preferable to call score_become_idle(), and score_become_busy() when the process is about to become busy. By reporting the status of a user process correctly, SCore-D can detect the global state of user parallel processes, and SCore-D tries to de-schedule a process if the process is in global idle, or tries to kill the process if it is assumed to be globally terminated, possibly because of deadlock. The timing of message consumption by the pmReleaseReceiveBuffer() and the calling of those functions is very important.
void idle_loop( void ) {
  caddr_t buf;
  size_t size
  while( pmReceive( score_pmnet[0], &buf, &size ) == ENOBUF ) {
    score_become_idle();
  }
  score_become_busy();
  process_received_message( buf, size );
  pmReleaseReceiveBuffer( score_pmnet[0] );
  return;
}
As in the above example, the score_become_busy() function must be called before the consumption of the received message by calling pmReleaseReceiveBuffer(). If violated, a user parallel process can be de-scheduled or killed by SCore-D erroneously.

Usage

#include <score_usage.h>
void score_runtime_usage(void) {
  score_separate_usage("My-Runtime");
  score_print_usage("magic", "NN", "magic number");
	:
}
This sample code for displaying language runtime usage produces the following message:

-- My-Runtime --
  magic=NN  magic number

See Also

scrun(1), score_initialize(3), score_runtime_resource(3), score_become_idle(3), score_become_busy(3), resource macros


$Id: sample-runtime.html,v 1.2 2002/02/22 06:27:56 koba Exp $