Skip to content
Snippets Groups Projects
Commit 5ed4bea4 authored by Emile Guillaume's avatar Emile Guillaume
Browse files

add central demon (need to be tested) + add random unsafe node (need to be test)

parent 36c59070
No related branches found
No related tags found
No related merge requests found
/* This file was generated by lv6 version v6.106.1. */
/* lv6 utils.lus -n random -2c -exec -dir Random */
/* on PC-Travail the 18/07/2022 at 15:00:26 */
#include "lustre_consts.h"
\ No newline at end of file
/* This file was generated by lv6 version v6.106.1. */
/* lv6 utils.lus -n random -2c -exec -dir Random */
/* on PC-Travail the 18/07/2022 at 15:00:26 */
#include "lustre_types.h"
\ No newline at end of file
/* This file was generated by lv6 version v6.106.1. */
/* lv6 utils.lus -n random -2c -exec -dir Random */
/* on PC-Travail the 18/07/2022 at 15:00:26 */
#ifndef _SOC2C_PREDEF_TYPES
#define _SOC2C_PREDEF_TYPES
typedef int _boolean;
typedef int _integer;
typedef char* _string;
typedef double _real;
typedef double _double;
typedef float _float;
#define _false 0
#define _true 1
#endif
// end of _SOC2C_PREDEF_TYPES
\ No newline at end of file
File added
if [ -z ${C_COMPILER} ]; then C_COMPILER=gcc; fi
$C_COMPILER -o random.exec \
Random/utils_random_ext.c Random/lustre_consts.c Random/utils_random.c Random/utils_random_loop.c
if [ -z ${C_COMPILER} ]; then C_COMPILER=gcc; fi
$C_COMPILER -o random.exec \
Random/utils_random_ext.c Random/lustre_consts.c Random/utils_random.c Random/utils_random_loop.c
/* This file was generated by lv6 version v6.106.1. */
/* lv6 utils.lus -n random -2c -exec -dir Random */
/* on PC-Travail the 18/07/2022 at 15:00:26 */
#include "utils_random.h"
//// Defining step functions
// Step function(s) for utils_c_rand_ctx
// Step function(s) for utils_random_ctx
void utils_random_step(_integer x,_integer *res){
utils_c_rand_step(x,res);
} // End of utils_random_step
/* This file was generated by lv6 version v6.106.1. */
/* lv6 utils.lus -n random -2c -exec -dir Random */
/* on PC-Travail the 18/07/2022 at 15:00:26 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lustre_consts.h"
// User typedef
#ifndef _utils_random_TYPES
#define _utils_random_TYPES
// Memoryless soc ctx typedef
// Memoryfull soc ctx typedef
#endif // end of _utils_random_TYPES
#ifndef _utils_random_H_FILE
#include "utils_random_ext.h"
#define _utils_random_H_FILE
#endif // _utils_random_H_FILE
void utils_random_step(_integer ,_integer *);
/////////////////////////////////////////////////
#include "utils_random.h"
#include <assert.h>
void utils_c_rand_step(_integer x,_integer *res){
assert (0 < x );
*res = (rand() % x);
}
#include "utils_random.h"
void utils_c_rand_step(_integer x,_integer *res){
assert (0 < x );
*res = (rand() % x);
}
void utils_c_rand_step(_integer ,_integer *);
/* This file was generated by lv6 version v6.106.1. */
/* lv6 utils.lus -n random -2c -exec -dir Random */
/* on PC-Travail the 18/07/2022 at 15:00:26 */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "utils_random.h"
/* Print a promt ? ************************/
static int ISATTY;
/* MACROS DEFINITIONS ****************/
#ifndef TT
#define TT "1"
#endif
#ifndef FF
#define FF "0"
#endif
#ifndef BB
#define BB "bottom"
#endif
#ifdef CKCHECK
/* set this macro for testing output clocks */
#endif
void _read_pragma(char b[]) {
if (!strcmp(b,"#quit")) exit(0);
if (!strcmp(b,"#q")) exit(0);
}
char* _get_string(char* n){
static char b[10] = "dummy";
return b;
}
/* Standard Input procedures **************/
_boolean _get_bool(char* n){
char b[512];
char c;
_boolean r = 0;
int s = 1;
do {
if(ISATTY) {
if((s != 1)||(r == -1)) printf("\a");
// printf("%s (1,t,T/0,f,F) ? ", n);
}
if(scanf("%s", b)==EOF) exit(0);
r = -1;
c=b[0];
if(c == 'q') exit(0);
if(c == '#') _read_pragma(b);
if((c == '0') || (c == 'f') || (c == 'F')) r = 0;
if((c == '1') || (c == 't') || (c == 'T')) r = 1;
} while((s != 1) || (r == -1));
return r;
}
_integer _get_int(char* n){
char b[512];
_integer r;
int s = 1;
do {
if(ISATTY) {
if(s != 1) printf("\a");
//printf("%s (integer) ? ", n);
}
if(scanf("%s", b)==EOF) exit(0);
if(*b == 'q') exit(0);
if(*b == '#') {
_read_pragma(b);
} else {
s = sscanf(b, "%d", &r);
}
} while(s != 1);
return r;
}
#define REALFORMAT ((sizeof(_real)==8)?"%lf":"%f")
_real _get_real(char* n){
char b[512];
_real r;
int s = 1;
do {
if(ISATTY) {
if(s != 1) printf("\a");
//printf("%s (real) ? ", n);
}
if(scanf("%s", b)==EOF) exit(0);
if(*b == 'q') exit(0);
if(*b == '#') {
_read_pragma(b);
} else {
s = sscanf(b, REALFORMAT, &r);
}
} while(s != 1);
return r;
}
/* Standard Output procedures **************/
void _put_bottom(char* n){
if(ISATTY) printf("%s = ", n);
printf("%s ", BB);
if(ISATTY) printf("\n");
}
void _put_bool(char* n, _boolean _V){
if(ISATTY) printf("%s = ", n);
printf("%s ", (_V)? TT : FF);
if(ISATTY) printf("\n");
}
void _put_int(char* n, _integer _V){
if(ISATTY) printf("%s = ", n);
printf("%d ", _V);
if(ISATTY) printf("\n");
}
void _put_real(char* n, _real _V){
if(ISATTY) printf("%s = ", n);
printf("%f ", _V);
if(ISATTY) printf("\n");
}
void _put_string(char* n, char* _V){
if(ISATTY) printf("%s = ", n);
printf("%s ", _V);
if(ISATTY) printf("\n");
}
/* Output procedures **********************/
#ifdef CKCHECK
void %s_BOT_n(void* cdata){
_put_bottom("n");
}
#endif
/* Main procedure *************************/
int main(){
int _s = 0;
_integer x;
_integer res;
printf("#inputs \"x\":int\n");
printf("#outputs \"res\":int\n");
/* Main loop */
ISATTY = isatty(0);
while(1){
if (ISATTY) printf("#step %d \n", _s+1);
else if(_s) printf("\n");
fflush(stdout);
++_s;
x = _get_int("x");
utils_random_step(x,&res);
// printf("%d #outs %d\n",x,res);
printf("%d\n",res);
}
return 1;
}
......@@ -37,6 +37,10 @@ let
and (silent<<an,pn>>(enab) or boolred<<1,pn,pn>>(map<<boolany<<an>>, pn>>(acti)));
tel;
(*function distributed<<const an:int; const pn:int>>(enab : bool^an^pn)
returns (acti : bool^an^pn);
var
nb_enab,rng:int;*)
-- Exactly one node is activated.
node daemon_is_central<<const an:int; const pn:int>>(acti, enab : bool^an^pn)
returns (y : bool);
......@@ -46,6 +50,31 @@ let
tel;
function make_activ_tab<<const an:int>>(ain:int; elem:bool^an)
returns(aout:int; res:bool^an);
var
elem_is_true:bool;
let
elem_is_true = boolany<<an>>(elem);
res= if elem_is_true and (ain=0) then elem else false^an;
aout = if elem_is_true then ain-1 else ain;
tel;
function if_true_add_1<<const an:int>>(ain: int; elem: bool^an)
returns(aout : int);
let
aout= if boolany<<an>>(elem) then ain+1 else ain;
tel;
unsafe function central<<const an:int; const pn:int>>(enab : bool^an^pn)
returns (acti : bool^an^pn);
var
nb_enab,rng,temp:int;
let
nb_enab = red<<if_true_add_1<<an>>,pn>>(0,enab);
rng = random(nb_enab);
temp,acti = fillred<<make_activ_tab<<an>>,pn>>(rng,enab);
tel;
-- No two neighboring nodes are active at once.
node daemon_is_locally_central<<const an:int; const pn:int>>(
......
--Make a random function for Lustre by using C function:
unsafe extern function c_rand(x:int) returns (res:int);
\ No newline at end of file
include "use_random.lus"
--Random (unsafe extern function):
unsafe function random(x:int) returns (res:int);
let
res = c_rand(x);
tel
-- Generates an array of indexes: [0, 1, ..., N-1]
function range<<const N:int>>(_ : bool) returns (r : int^N);
let
......@@ -80,4 +88,4 @@ function weight (e:neigh)
returns(res : int);
let
res = e.weight;
tel;
tel;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment