MAOS
Multithreaded Adaptive Optics Simulator
Loading...
Searching...
No Matches
scheduler_client.h File Reference

Data Structures

struct  status_t

Macros

#define scheduler_version   54

Enumerations

enum  {
  CMD_START =1 , CMD_FINISH , CMD_STATUS , CMD_CRASH ,
  CMD_MONITOR , CMD_PATH , CMD_KILL , CMD_TRACE ,
  CMD_PROBE , CMD_DRAWCLI , CMD_REMOVE , CMD_DRAWSER ,
  CMD_MAOSCLI , CMD_MAOSSER , CMD_RESTART , CMD_KILLED ,
  CMD_DUMMY , CMD_LAUNCH , CMD_AUTH
}
enum  {
  MAOS_SERVER =1 , MAOS_DRAW =10 , MAOS_VAR =20 , MAOS_PAUSE ,
  MAOS_ASSIGN_WFS =100 , MAOS_ASSIGN_EVL , MAOS_ASSIGN_RECON , MAOS_ASSIGN_DONE =199
}
enum  {
  MON_CMD =1 , MON_DRAWDAEMON =2 , MON_STATUS =3 , MON_PATH =6 ,
  MON_CLEARJOB =7 , MON_KILLJOB =8 , MON_SAVEJOB =9 , MON_VERSION =13 ,
  MON_LOAD =14 , MON_ADDHOST =17
}
enum  {
  S_RUNNING =1 , S_WAIT , S_START , S_QUEUED ,
  S_UNKNOWN , S_FINISH =11 , S_CRASH , S_TOKILL ,
  S_REMOVE , S_KILLED , S_NONEXIST
}
enum  {
  DRAW_START =0 , DRAW_DATA , DRAW_HEARTBEAT , DRAW_POINTS ,
  DRAW_STYLE , DRAW_CIRCLE , DRAW_LIMIT , DRAW_FIG ,
  DRAW_NAME , DRAW_TITLE , DRAW_XLABEL , DRAW_YLABEL ,
  DRAW_ZLIM , DRAW_LEGEND , DRAW_XYLOG , DRAW_FIGFN ,
  DRAW_PAUSE , DRAW_RESUME , DRAW_FINAL , DRAW_FLOAT ,
  DRAW_FRAME , DRAW_SINGLE , DRAW_UDPPORT , DRAW_INIT ,
  DRAW_PID , DRAW_ZLOG , DRAW_PATH , DRAW_EXENAME ,
  DRAW_DX , DRAW_END =100 , DRAW_ENTRY =9999
}
enum  { DRAW_ID_MAOS =1 , DRAW_ID_RES , DRAW_ID_BIN , DRAW_ID_TOT }

Functions

void parse_host (const char *line)
void free_hosts ()
void init_hosts ()
const char * lookup_hostaddr (const char *hostname)
const char * lookup_hostname (const char *hostaddr)
char * scheduler_password (int create)
int scheduler_auth (int sock)
int scheduler_connect (const char *hostname)
int scheduler_connect_self (int block)
pthread_t scheduler_listen (thread_fun fun)
void scheduler_report_path (const char *path)
void scheduler_start (int nthread, int ngpu, int waiting)
void scheduler_finish (int status)
void scheduler_report (status_t *status)
int scheduler_launch_exe (char *hostarr, int argc, const char *argv[])
int scheduler_socket (int dir, int *sfd, int id)
int call_addr2line (char *ans, int nans, const char *cmd)
int print_backtrace_symbol (void *const *buffer, int size)
void print_backtrace ()

Detailed Description

Contains routines that will be used to talk to the scheduler.


Data Structure Documentation

◆ status_t

struct status_t

Status about each process. Timing, wavefront error, etc.

Collaboration diagram for status_t:
Data Fields
double wfs
double recon
double other
double eval
double tot
double scale
double mean
long rest
long laps
int iseed
int nseed
int nthread
int isim
int simstart
int simend
char done
char warning
char unused1
char unused2
double clerrlo
double clerrhi
int info
time_t timstart
time_t timlast

Function Documentation

◆ parse_host()

void parse_host ( const char * line)

Parse and add host info to hosts[] and hostaddr[]. hosts contains the shortcut name, without dot and hostaddr contains the FQDN and optionally the port

Parameters
[in]lineContains hostname[=hostaddr:port]. Empty lines and lines starting with # are ignored.

◆ free_hosts()

void free_hosts ( )

free hosts[] and hostsaddr[]

◆ init_hosts()

void init_hosts ( )

Initialize hosts and associate an id number

◆ lookup_hostaddr()

const char * lookup_hostaddr ( const char * hostname)

Translate hostname to address based on ~/.aos/hosts

Parameters
[in]hostnameThe host name.
Returns
The host address (internal data; do not free), or hostname itself if not found.

◆ lookup_hostname()

const char * lookup_hostname ( const char * hostaddr)

Translate address to hostname based on ~/.aos/hosts

Parameters
[in]hostaddrThe host address.
Returns
The host name (internal data; do not free), or hostaddr itself if not found.

◆ scheduler_password()

char * scheduler_password ( int create)

Read the password that authenticates TCP connections to the scheduler, including the browser monitor, from the first line of ~/.aos/htpasswd.

Parameters
[in]createIf the file does not exist, create it with a random password.
Returns
Newly allocated password; the caller frees it. NULL if not available.

◆ scheduler_auth()

int scheduler_auth ( int sock)

Authenticate a TCP connection to the scheduler. The scheduler sends a random nonce and the client replies with base64(sha1(nonce+password)), so that the password is not sent over the network.

Parameters
[in]sockSocket connected to the scheduler.
Returns
0 on success, -1 on failure.

◆ scheduler_connect()

int scheduler_connect ( const char * hostname)

Connect to the scheduler at hostname using PORT and authenticate. Returns the socket or -1 if failed or the scheduler is disabled.

Parameters
[in]hostnameHost name or address of the scheduler.
Returns
The socket, or -1 on failure.

◆ scheduler_connect_self()

int scheduler_connect_self ( int block)

To open a port and connect to scheduler in the local host. Launches the scheduler if it is not running.

Parameters
[in]blockNonzero to retry up to 100 times; otherwise retry twice.
Returns
The socket, or -1 on failure.

◆ scheduler_listen()

pthread_t scheduler_listen ( thread_fun fun)

Started by maos to listen to the sock which connects to the scheduler for commands. It reuses existing connection.

Parameters
[in]funThread function that is called with the socket as its argument.
Returns
The thread, or 0 on failure.

◆ scheduler_report_path()

void scheduler_report_path ( const char * path)

Report the job path (command line) to the scheduler via a persistent connection. The path is saved so that it can be resent with path=NULL after reconnection.

Parameters
[in]pathThe job path. NULL to resend the saved path.

◆ scheduler_start()

void scheduler_start ( int nthread,
int ngpu,
int waiting )

Called by maos to report a job start to scheduler and wait for signal before proceeding if waiting is set.

Parameters
[in]nthreadNumber of threads the job uses.
[in]ngpuNumber of GPUs the job uses.
[in]waitingNonzero to wait for the scheduler (or for idle CPUs if the scheduler is unavailable) before returning.

◆ scheduler_finish()

void scheduler_finish ( int status)

Called by maos to notify scheduler the completion of a job

Parameters
[in]status0 for success; a crash signal reports a crash; otherwise the job is reported as killed.

◆ scheduler_report()

void scheduler_report ( status_t * status)

called by sim.c to report job status. Do not try to reconnect. If not connected, a thread is launched to connect in the background.

Parameters
[in]statusThe job status.

◆ scheduler_launch_exe()

int scheduler_launch_exe ( char * hostarr,
int argc,
const char * argv[] )

Ask scheduler (maybe in another machine) to launch executable. Host may be null or contain coma separated hosts

Parameters
[in,out]hostarrComa separated host names; NULL means localhost. Temporarily modified but restored.
[in]argcNumber of arguments.
[in]argvArguments. argv[0] is the executable.
Returns
0 if launched on at least one host, -1 otherwise.

◆ scheduler_socket()

int scheduler_socket ( int dir,
int * sfd,
int id )

send a drawing sock to the scheduler for caching (dir=1) or request an existing sock (dir=-1) or new sock (dir=0) for drawing. abs(id) should be between 1 and 9999. the id send to the scheduler has the following meaning: -10000<id<0: request existing socket (drawdaemon). preferably for the same id<-10000: request new socket (drawdaemon). id>0: save socket (drawdaemon) for reuse.

Parameters
[in]dir1: send sfd for caching; -1: request an existing socket; 0: request a new socket.
[in,out]sfdThe socket to send (dir=1) or the received socket (dir=0 or -1).
[in]idDrawing id (sign is ignored).
Returns
0 on success, nonzero on failure.

◆ call_addr2line()

int call_addr2line ( char * ans,
int nans,
const char * cmdstr )

Execute addr2line as specified in cmdstr and combine the answer into a string. If it fails, the program name and addresses are copied instead.

Parameters
[out]ansOutput string.
[in]nansSize of ans.
[in]cmdstrThe addr2line command.
Returns
0.

◆ print_backtrace_symbol()

int print_backtrace_symbol ( void *const * buffer,
int size )

Convert backtrace address to source line. Do not call routines that may call malloc as the mutex in malloc may already be locked.

Parameters
[in]bufferAddresses returned by backtrace().
[in]sizeNumber of addresses.
Returns
0 if success otherwise -1

◆ print_backtrace()

void print_backtrace ( )

Print the backtrace of the current call stack with symbol names.