예제 #1
0
파일: seq.c 프로젝트: kbaptista/multicoeur
float *compute_seq(unsigned iterations){
  if(!is_end){
    return DYNAMIC_COLORING;
  }
  is_end = 0;

  for (unsigned i = 0; i < iterations; i++){
    for (int x = 1; x < DIM-1; x=x+2){
      for (int y = 1; y < DIM-1; y++){
        if(ocean[y][x][table] >= MAX_HEIGHT)
        {
            traitement(x,y);
        }
      } 
    }

    for (int x = 2; x < DIM-1; x=x+2){
      for (int y = DIM-2; y > 0; y--){
        if(ocean[y][x][table] >= MAX_HEIGHT)
        {
            traitement(x,y);
        }
      }
    }

    #pragma omp barrier
    table = 1 - table;
    if(is_end){
      copy(table);
    }
  }
  return DYNAMIC_COLORING;
}
예제 #2
0
파일: get_next_line.c 프로젝트: YliesC/42sh
char		*get_next_line(const int fd)
{
  static t_get	*g;
  static int	k = 0;

  if (k == 0)
    {
      CHECK_RETURN(g = malloc(sizeof(t_get)), NULL, NULL);
      g->j = 0;
      g->len = 0;
    }
  k = 1;
  g->count = 0;
  g->i = 0;
  if (++(g->j) >= g->len)
    {
      CHECK_RETURN(g->len = read(fd, g->buff, READ), 0, NULL);
      g->j = 0;
    }
  if (g->len  <= 0 || READ <= 0)
    return (NULL);
  CHECK_RETURN(g->str = malloc(sizeof(char) * READ + 1), NULL, NULL);
  g->str[0] = '\0';
  g->buff[g->len] = '\0';
  CHECK_RETURN(traitement(g, fd), NULL, NULL);
  tronque(g->buff, 1, g->len - (g->i - 2));
  return (g->str);
}
예제 #3
0
/**
Représente un tour de boucle, ici ce trouve
toutes la gestion du jeu
@return true si pas de collision
*/
bool Game::gameLoop(sf::Clock & clock)
{
	affichage();

	sf::Event event;
	recuperationEntree(event);

	//valeur qui sera retrournée a la fin de la GameLoop
	bool etat = m_map.collisionBloc(m_vaisseauJoueur, m_tirs, m_distanceParcouru);

	actualisationInfoJoueur();

	//actualisation du temps
	m_tempsPasse = clock.getElapsedTime().asMicroseconds() / 20000.;
	clock.restart().asMicroseconds();
	m_tempsPasse /= m_coefRalentissement;

	//calcul de la trajectoire puis la vitesse sera calculé a part
	traitement(event, m_tempsPasse);

	gestionScrolling(m_tempsPasse);

	//deplacement des tirs
	gererTirs(m_tempsPasse);

	rechargeDesVaisseaux(m_tempsPasse);

	actualiserAnimation(m_tempsPasse);

	//comp 1
	float tempsMaxComp = m_vaisseauJoueur.getCompetence(2)->getTempsDeRechargeMax();
	float tempsActuelComp = m_vaisseauJoueur.getCompetence(2)->getTempsDeRechargeActuel();
	float rapportComp1 = 1;

	if (tempsActuelComp != tempsMaxComp)
		rapportComp1 = ((tempsMaxComp - tempsActuelComp) / tempsMaxComp);

	//comp 2
	tempsMaxComp = m_vaisseauJoueur.getCompetence(3)->getTempsDeRechargeMax();
	tempsActuelComp = m_vaisseauJoueur.getCompetence(3)->getTempsDeRechargeActuel();
	float rapportComp2 = tempsActuelComp / tempsMaxComp;

	//comp 3
	tempsMaxComp = m_vaisseauJoueur.getCompetence(1)->getTempsDeRechargeMax();
	tempsActuelComp = m_vaisseauJoueur.getCompetence(1)->getTempsDeRechargeActuel();
	float rapportComp3 = 1;
	if (m_vaisseauJoueur.getCompetence(1)->estActive())
	{
		rapportComp3 = tempsActuelComp / tempsMaxComp;
	}
	else if (tempsActuelComp != tempsMaxComp)
	{
		rapportComp3 = (tempsMaxComp - tempsActuelComp) / tempsMaxComp;
	}

	tableauDeBord.actualiserAnimationAvecCompetence(rapportComp1, rapportComp2, rapportComp3, m_vaisseauJoueur.getCompetence(1)->estActive());

	return etat;
}
예제 #4
0
void func() {
	// array we want to permute
	int array[SIZE];
	
	int alreadyPlaces[SIZED * SIZED]; // array n * n to see if a value as already been in a specific place. aka: alreadyPlaces[index + SIZE * position] = 1 if the value at the index index as already been permuted to the position position
	
	for(i = 0 ; i<SIZED * SIZED ; ++i) {
		alreadyPlaces[i] = 0;
	}
	
	// temporary array for operations
	int temp[SIZE];
	int i = 0;
	
	int nbPermutation = factoriel(SIZE);
	
	// For an array of a size SIZE there is SIZE! permutation
	for(i=0 ; i<nbPermutation ; ++i) {
		
		// We want to edit the temporary array
		for(int j = 0 ; j< SIZE ; ++j) {
			// what index do we take ?
			int index;
			for(int k = 0 ; k < SIZE ; ++k) {
				// We choose an index that hasn't already been placed at the specific position
				if(alreadyPlaces[k + j * SIZE] == 0) {
					// We verify that the value isn't already in temp
					int alreadyIntTemp = 0;
					for(int m = 0 ; m < j ; ++m) {
						if(temp[m] == array[k])
							alreadyInTemp = 1;
					}
					
					if(alreadyInTemp == 0) {
						index = k;
						break;
					} 
				}
			}
			temp[j] = array[index];
			alreadyPlaces[index + j * SIZE] = 1;
		}
		
		// On fait le traitement avec temp
		traitement(temp);
		
	}
	

}
예제 #5
0
파일: chat_server.c 프로젝트: naaf/Master
int main(int argc, char **argv) {
	struct myshm* p_shm;
	struct message* request;

	signal(SIGINT, handler);

	if (argc != 2) {
		printf("error syntaxe ex: %s /server_shm:0\n", argv[0]);
		exit(EXIT_FAILURE);
	}
	shmsrv_nom = argv[1];
	nb_users = 0;
	if ((shm_id = shm_open(shmsrv_nom, O_CREAT | O_EXCL | O_RDWR, 0600))
			== -1) {
		perror("shm_open");
		exit(-1);
	}
	if (ftruncate(shm_id, LENGTH_SHM) == -1) {
		perror("ftruncate");
		exit(-1);
	}

	if ((p_shm = (struct myshm*) mmap(NULL, LENGTH_SHM, PROT_READ | PROT_WRITE,
	MAP_SHARED, shm_id, 0)) == MAP_FAILED) {
		perror("mmap");
		exit(-1);
	}

	printf(" shm_id %d \n", shm_id);
	sem_init(&p_shm->sem, 1, 1);
	sem_init(&p_shm->sem_message, 1, 0);
	p_shm->nb = 0;
	printf("serveur %s demarré \n", argv[1]);

	while (1) {
		request = NULL;
		sem_wait(&p_shm->sem_message);
		sem_wait(&p_shm->sem);
		if (p_shm->nb) {
			p_shm->nb--;
			request = &(p_shm->messages[p_shm->nb]);
		}
		sem_post(&p_shm->sem);
		if (request) {
			traitement(request);
		}
	}

	return EXIT_SUCCESS;
}
예제 #6
0
void algo_principal(int parallelism, int *tableau, int taille, char *arg)
{
    void *args_algo;
    arguments_t args;

    (void) parallelism;
    args_algo = initialisation(0, tableau, taille, arg);
    args.num = 0;
    args.inf = 0;
    args.sup = taille-1;
    args.tableau = tableau;
    args.taille = taille;
    args.args_algo = args_algo;

    traitement(&args);

    traitement_resultats(0, &args); 
}
예제 #7
0
//gerer les fuites
int main()
{
  t_home  fourmilliere;
  //t_lst_chemins   *paths;
  if (acquisition(&fourmilliere) == -1)
  {
    printf("erreur lors de l'aquisition");
    return (0);
  }
  if (traitement(&fourmilliere) == -1)
  {
    printf("erreur lors du traitement");
    return (0);
  }
/*  if (impression(paths) == -1)
  {
    printf("erreur lors de l'impression");
    return (0);
  }*/
  return(0);
}
예제 #8
0
파일: main.c 프로젝트: naaf/Master
void *run_com(void *arg) {
	char response[512];
	char **tab = NULL;
	int size;

	memset(response, 0, 1024);

	fprintf(stderr, "thread com demarre :\n");

	/*--------------Blocquer les signaux------------------*/
	sigset_t mask;
	sigfillset(&mask);
	pthread_sigmask(SIG_SETMASK, &mask, NULL);

	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);

	while (TRUE) {
		read_response(sc, response);
		fprintf(stderr, "com: recu reponse len %zu : %s\n", strlen(response),
				response);

		if (0 == strlen(response)) {
			fprintf(stderr, "ERROR : Connection Socket");
			erreur("ERROR : Connection Socket", TRUE);
			break;
		}

		tab = string_to_arraystring(response, &size, '/');

		traitement(tab, size);

		/*free resources*/
		free_table(tab, size);
		memset(response, 0, sizeof(response));
	}
	pthread_cancel(thread_chat); //TODO
	return NULL;
}
예제 #9
0
파일: ecouteur.c 프로젝트: SUN-XIN/Projet
int main(){
	init();
	msg msgR;
	
	fd_set fd;
	struct timeval timeout;
	timeout.tv_sec=3;
	timeout.tv_usec=0;
	int s;
	printf("\nAttendre...\n");
	while(1) {
		FD_ZERO(&fd); 
		FD_SET(sock,&fd);
		s = select(sock+1, &fd, NULL, NULL, &timeout);
		if (s>0) {
			msgR.type=-1;strcpy(msgR.data,"");
			recvfrom(sock,&msgR,sizeof(msgR),0,(struct sockaddr *)&recu,&len);
			printf("Recu 1 msg ");
			traitement(msgR);
			printf("\nAttendre...\n");}
		else {}
	}
	return EXIT_SUCCESS;
}