10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-11-03 12:43:52 +01:00
quantum_package/promela/integrals.pml

273 lines
5.7 KiB
Promela
Raw Normal View History

2017-03-27 13:20:01 +02:00
#define NPROC 1
2017-03-26 23:43:48 +02:00
#define BUFSIZE 2
2017-03-27 13:20:01 +02:00
#define NTASKS 3
2017-03-26 23:43:48 +02:00
mtype = { NONE, OK, WRONG_STATE, TERMINATE, GETPSI, PUTPSI, NEWJOB, ENDJOB, SETRUNNING,
SETWAITING, SETSTOPPED, CONNECT, DISCONNECT, ADDTASK, DELTASK, TASKDONE, GETTASK,
2017-03-27 13:20:01 +02:00
PSI, TASK, PUTPSI_REPLY, WAITING, RUNNING, STOPPED
2017-03-26 23:43:48 +02:00
}
typedef rep_message {
mtype m = NONE;
byte value = 0;
}
typedef req_message {
mtype m = NONE;
2017-03-27 13:20:01 +02:00
byte state = 0;
2017-03-26 23:43:48 +02:00
byte value = 0;
chan reply = [BUFSIZE] of { rep_message };
}
2017-03-27 13:20:01 +02:00
#define send_req( MESSAGE, VALUE ) msg.m=MESSAGE ; msg.value=VALUE ; msg.state=state; rep_socket ! msg; msg.reply ? reply
2017-03-26 23:43:48 +02:00
chan rep_socket = [NPROC] of { req_message };
chan pull_socket = [NPROC] of { byte };
chan pair_socket = [NPROC] of { req_message };
chan task_queue = [NTASKS+2] of { byte };
2017-03-27 13:20:01 +02:00
chan pub_socket = [NTASKS+2] of { mtype };
2017-03-26 23:43:48 +02:00
2017-03-27 13:20:01 +02:00
bit socket_up = 0;
mtype global_state; /* Sent by pub */
2017-03-26 23:43:48 +02:00
active proctype qp_run() {
bit psi = 0;
2017-03-27 13:20:01 +02:00
bit address_tcp = 0;
bit address_inproc = 0;
bit running = 0;
byte status = 0;
byte state = 0;
2017-03-26 23:43:48 +02:00
byte ntasks = 0;
req_message msg;
rep_message reply;
byte nclients = 0;
byte task;
2017-03-27 13:20:01 +02:00
socket_up = 1;
running = 1;
2017-03-26 23:43:48 +02:00
do
2017-03-27 13:20:01 +02:00
// :: ( (running == 0) && (nclients == 0) && (ntasks == 0) ) -> break
:: ( running == 0 ) -> break
2017-03-26 23:43:48 +02:00
:: else ->
rep_socket ? msg;
printf("req: "); printm(msg.m); printf("\t%d\n",msg.value);
if
:: ( msg.m == TERMINATE ) ->
assert (state != 0);
2017-03-27 13:20:01 +02:00
assert (msg.state == state);
running = 0;
2017-03-26 23:43:48 +02:00
reply.m = OK;
:: ( msg.m == PUTPSI ) ->
assert (state != 0);
2017-03-27 13:20:01 +02:00
assert (msg.state == state);
2017-03-26 23:43:48 +02:00
assert (psi == 0);
psi = 1;
2017-03-27 13:20:01 +02:00
reply.m = PUTPSI_REPLY;
2017-03-26 23:43:48 +02:00
:: ( msg.m == GETPSI ) ->
assert (state != 0);
2017-03-27 13:20:01 +02:00
assert (msg.state == state);
2017-03-26 23:43:48 +02:00
assert (psi == 1);
reply.m = PSI;
:: ( msg.m == NEWJOB ) ->
2017-03-27 13:20:01 +02:00
assert (state == 0);
state = msg.value;
pair_socket ! WAITING;
reply.m = OK;
reply.value = state;
:: ( msg.m == ENDJOB ) ->
assert (state != 0);
assert (msg.state == state);
state = 0;
pair_socket ! WAITING;
2017-03-26 23:43:48 +02:00
reply.m = OK;
:: ( msg.m == ADDTASK ) ->
assert (state != 0);
2017-03-27 13:20:01 +02:00
assert (msg.state == state);
2017-03-26 23:43:48 +02:00
task_queue ! msg.value;
ntasks++;
reply.m = OK;
:: ( msg.m == GETTASK ) ->
assert (nclients > 0);
assert (state != 0);
2017-03-27 13:20:01 +02:00
assert (msg.state == state);
2017-03-26 23:43:48 +02:00
if
:: ( task_queue ?[task] ) ->
2017-03-27 13:20:01 +02:00
pair_socket ! WAITING;
2017-03-26 23:43:48 +02:00
reply.m = TASK;
task_queue ? reply.value
:: else ->
2017-03-27 13:20:01 +02:00
pair_socket ! RUNNING;
2017-03-26 23:43:48 +02:00
reply.m = NONE;
reply.value = 255;
fi;
:: ( msg.m == TASKDONE) ->
assert (state != 0);
2017-03-27 13:20:01 +02:00
assert (msg.state == state);
2017-03-26 23:43:48 +02:00
assert (nclients > 0);
assert (ntasks > 0);
reply.m = OK;
:: ( msg.m == DELTASK ) ->
assert (state != 0);
2017-03-27 13:20:01 +02:00
assert (msg.state == state);
2017-03-26 23:43:48 +02:00
ntasks--;
if
:: (ntasks > 0) -> reply.value = 1;
:: else -> reply.value = 0;
fi;
reply.m = OK;
:: ( msg.m == CONNECT ) ->
2017-03-27 13:20:01 +02:00
assert ( state != 0 )
2017-03-26 23:43:48 +02:00
nclients++;
reply.m = OK;
2017-03-27 13:20:01 +02:00
reply.value = state;
2017-03-26 23:43:48 +02:00
:: ( msg.m == DISCONNECT ) ->
2017-03-27 13:20:01 +02:00
assert ( msg.state == state )
2017-03-26 23:43:48 +02:00
nclients--;
reply.m = OK;
2017-03-27 13:20:01 +02:00
:: ( msg.m == STOPPED ) ->
pair_socket ! STOPPED;
reply.m = OK;
:: ( msg.m == WAITING ) ->
pair_socket ! WAITING;
reply.m = OK;
:: ( msg.m == RUNNING ) ->
assert ( state != 0 );
pair_socket ! RUNNING;
reply.m = OK;
2017-03-26 23:43:48 +02:00
fi
msg.reply ! reply
od
2017-03-27 13:20:01 +02:00
pair_socket ! STOPPED;
socket_up = 0;
2017-03-26 23:43:48 +02:00
}
active proctype master() {
req_message msg;
rep_message reply;
2017-03-27 13:20:01 +02:00
byte state = 0;
2017-03-26 23:43:48 +02:00
byte count;
2017-03-27 13:20:01 +02:00
run pub_thread();
2017-03-26 23:43:48 +02:00
/* New parallel job */
2017-03-27 13:20:01 +02:00
state=1;
send_req( NEWJOB, state );
2017-03-26 23:43:48 +02:00
assert (reply.m == OK);
/* Add tasks */
count = 0;
do
:: (count == NTASKS) -> break;
:: else ->
count++;
send_req( ADDTASK, count );
assert (reply.m == OK);
od
/* Run collector */
2017-03-27 13:20:01 +02:00
run collector(state);
2017-03-26 23:43:48 +02:00
/* Run slaves */
count = 0;
do
:: (count == NPROC) -> break;
:: else -> count++; run slave();
od
}
proctype slave() {
req_message msg;
rep_message reply;
byte task;
2017-03-27 13:20:01 +02:00
byte state;
2017-03-26 23:43:48 +02:00
2017-03-27 13:20:01 +02:00
msg.m=CONNECT;
msg.state = 0;
if
:: (!socket_up) -> goto exit;
:: else -> skip;
fi
rep_socket ! msg;
if
:: (!socket_up) -> goto exit;
:: else -> skip;
fi
msg.reply ? reply;
state = reply.value;
2017-03-26 23:43:48 +02:00
task = 1;
do
:: (task == 255) -> break;
:: else ->
send_req( GETTASK, 0);
if
:: (reply.m == NONE) ->
task = 255;
:: (reply.m == TASK) ->
/* Compute task */
task = reply.value;
send_req( TASKDONE, task);
assert (reply.m == OK);
pull_socket ! task;
fi
od
send_req( DISCONNECT, 0);
assert (reply.m == OK);
2017-03-27 13:20:01 +02:00
exit: skip;
2017-03-26 23:43:48 +02:00
}
2017-03-27 13:20:01 +02:00
proctype collector(byte state) {
2017-03-26 23:43:48 +02:00
byte task;
req_message msg;
rep_message reply;
bit loop = 1;
do
:: (loop == 0) -> break
:: else ->
pull_socket ? task;
/* Handle result */
send_req(DELTASK, task);
assert (reply.m == OK);
loop = reply.value;
od
send_req( TERMINATE, 0);
assert (reply.m == OK);
}
2017-03-27 13:20:01 +02:00
proctype pub_thread() {
mtype state = WAITING;
do
:: (state == STOPPED) -> break;
:: (pair_socket ? [state]) ->
pair_socket ? state;
global_state = state;
od
}