Example #1
0
Automata::Automata(Log *l){
    if(DEBUG){
        std::cout << "\tDebug: Starting automata...\n";
    }
    this->logger = l;
    this->state = NOPE;
    initAutomata();
}
Example #2
0
/* Returns NULL if the process must be killed (it has nothing to compute. */
Process initProcess(int myid, int nbproc, int width, int height, double p, int nbIter) {
    Process process = (Process) malloc(sizeof(struct process)) ;
    assert(process) ;
    int cellsWidth, cellsHeight, cellsWidthOffset, cellsHeightOffset ;
    process->myid = myid ;
    process->nbproc = nbproc ;
    int a = (int) floor(sqrt((double)(process->nbproc))), b ;
    /* Compute the width and the height of the grid of processes. */
    while(process->nbproc % a != 0)
        a-- ;
    b = process->nbproc/a ;
    if(width > height) {
        process->gridWidth = max(a,b) ;
        process->gridHeight = min(a,b) ;
    }
    else {
        process->gridWidth = min(a,b) ;
        process->gridHeight = max(a,b) ;
    }
    /* Informations about positionning in the grid of processes. */
    process->nbIter = nbIter ;
    process->currentIter = 0 ;
    /* Default size of the handled automata. */
    cellsWidth = (int)ceil((double)width/(double)process->gridWidth) ;
    cellsHeight = (int)ceil((double)height/(double)process->gridHeight) ;
    /* Redimmensionning of the grid of processes (removing idle processes). */
    while((process->gridWidth-1)*cellsWidth >= width)
        process->gridWidth -- ;
    while((process->gridHeight-1)*cellsHeight >= height)
        process->gridHeight -- ;
    process->nbproc = process->gridWidth*process->gridHeight ;
    if(process->myid >= process->nbproc) { /* will be killed */
        free(process) ;
        return NULL ;
    }
    process->myrow = process->myid/process->gridWidth ;
    process->mycol = process->myid%process->gridWidth ;
    /* Left, right, top and down processes. */
    process->left = coord_to_id(process->myrow,modulo(process->mycol-1,process->gridWidth),process->gridWidth) ;
    process->right = coord_to_id(process->myrow,modulo(process->mycol+1,process->gridWidth),process->gridWidth) ;
    process->down = coord_to_id(modulo(process->myrow+1,process->gridHeight),process->mycol,process->gridWidth) ;
    process->up = coord_to_id(modulo(process->myrow-1,process->gridHeight),process->mycol,process->gridWidth) ;
    /* Informations about the part of the automata to handle. */
    cellsWidthOffset = cellsWidth*process->mycol ;
    cellsHeightOffset = cellsHeight*process->myrow ;
    cellsWidth = max(0,min(cellsWidth,width-cellsWidthOffset)) ;
    cellsHeight = max(0,min(cellsHeight,height-cellsHeightOffset)) ;
    process->automata = initAutomata(cellsWidth,cellsHeight,cellsWidthOffset,cellsHeightOffset,p) ;
    return process ;
}
Example #3
0
File: seis.c Project: mangel45/esc
void automataFromFichero(const char *fich, int *p, int *c)
{
    char str[MAX_SIZE];
    FILE *fichero = fopen(fich, "r");

    if(fichero == NULL)
    {
        perror("Error [Fichero]");
        exit(-1);
    }

    fgets(str, MAX_SIZE, fichero);
    initAutomata(str, p, c);

    fclose(fichero);
}
Example #4
0
File: seis.c Project: mangel45/esc
void automataFromCadena(const char *cad, int *p, int *c)
{
    initAutomata(cad, p, c);
}
Example #5
0
void automataFromCadena(char *cad, int *p)
{
	initAutomata(cad, p);
}