Skip to content
Snippets Groups Projects
Commit bde5be39 authored by Jazil Saadana's avatar Jazil Saadana
Browse files

2eme depot le 22

parent 66cb4e4b
Branches
No related tags found
No related merge requests found
......@@ -28,7 +28,7 @@ void grid_collide( grid_t *g ) {
else { node_fluid( &g->nodes[i][j] ); }
}
}
grid_propage(g);
grid_mod(g);
printf("fini le calul\n");
}
......
#include <stdlib.h>
#include "stdio.h"
#include "stdlib.h"
#include "grid.h"
#include "mask.h"
#include "node.h"
......@@ -8,15 +9,15 @@
grid_t g;
SDL_Keycode escape = 0;
//pathread_barrier_t b;
pthread_barrier_t b;
int n_thread = 0;
sem_t lock;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutexcalc = PTHREAD_MUTEX_INITIALIZER;
struct gfx_context_t *ctxt;
void *keyboad_control()
{
void *keyboad_control(){
pthread_mutex_lock(&mutex);
while(1){
escape = gfx_keypressed();
if (escape == SDLK_ESCAPE)
{
......@@ -24,37 +25,49 @@ void *keyboad_control()
exit(0);
}
pthread_mutex_unlock(&mutex);
sem_post(&lock);
}
}
void *Calculate()
{
pthread_mutex_lock(&mutex);
while (1)
{
grid_collide(&g);
sem_post(&lock);
pthread_mutex_unlock(&mutex);
pthread_barrier_wait(&b);
grid_propage(&g);
pthread_barrier_wait(&b);
}
}
void *Display(){
pthread_mutex_lock(&mutex);
sem_wait(&lock);
while (1)
{
gfx_present(ctxt);
}
sem_post(&lock);
pthread_mutex_unlock(&mutex);
}
int main(int argc, char *argv[])
{
/*je trouve la barriere!!!! */
// pthread_barrier_init(&b);
int x = atoi(argv[1]), y = atoi(argv[2]);
TAU = atof(argv[3]);
G = atof(argv[4]);
double Gy = atof(argv[5]);
const double rho = 1.0;
int n_thread = atoi(argv[6]);
n_thread = atoi(argv[6]);
pthread_barrier_init(&b, NULL,n_thread);
int nthread_calcul = n_thread - 2;
int rest, portion;
pthread_t t_keyboard, t_display, t_calulator;
......@@ -69,8 +82,7 @@ int main(int argc, char *argv[])
}
portion = atoi(argv[1])/nthread_calcul;
rest = atoi(argv[1])%nthread_calcul;
while (1)
{
SDL_PumpEvents();
SDL_ShowCursor(SDL_ENABLE);
......@@ -79,17 +91,17 @@ int main(int argc, char *argv[])
g.y = portion;
for (int i = 0; i < nthread_calcul; i++)
{
if (i == nthread_calcul -1)
if (i <= rest)
{
g.x += rest;
g.y += rest;
g.x = g.x + 1;
g.y = g.y + 1;
}
pthread_mutex_lock(&mutex);
pthread_create(&t_calulator, NULL, Calculate, NULL);
sem_wait(&lock);
pthread_mutex_unlock(&mutex);
g.x += portion;
g.y += portion;
}
......@@ -99,7 +111,7 @@ int main(int argc, char *argv[])
perror("pthread_create");
return EXIT_FAILURE;
}
sem_wait(&lock);
g.x = x;
g.y = y;
render(ctxt, &g);
......@@ -108,22 +120,24 @@ int main(int argc, char *argv[])
perror("pthread_create");
return EXIT_FAILURE;
}
sem_wait(&lock);
gfx_left_right_mouse_pressed(&g);
for (int i = 0; i < nthread_calcul; i++)
{
pthread_join(t_calulator, NULL);
}
sem_destroy(&lock);
}
pthread_join(t_display, NULL);
pthread_join(t_keyboard, NULL);
sem_destroy(&lock);
pthread_barrier_destroy(&b);
gfx_destroy(ctxt);
grid_destroy(g);
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment