void * thread_function (void *arg) { int my_number = (long) arg; int *myp = (int *) &counters[my_number]; static volatile int t; /* Don't run forever. Run just short of it :) */ while (*myp > 0) { t = break_here_before_inc (); int y = inc_x (my_number); if (y >= 0) { (*myp) ++; usleep (1); /* Loop increment. */ if (my_number == 0) break_here (); } else { usleep (1); } } pthread_exit (NULL); }
void le_step_x(le_task *t) { assert(t->stype == ST_AOS); // this is array of structere /* * Due to our system of pde is linear, we can use some simple way to solve it. * du/dt + A * du/dx = 0. * Vector u = {vx, vy, sxx, sxy, syy}. * Matrix A could be represent in form OmegaL * Lambda * OmegaR, * where Lambda - diagonal matrix of eigen values of matrix A. * In our case Lambda = diag{c1, -c1, c2, -c2, 0}. * OmegaR and OmegaL - metrices from eigen vectors of matrix A, * OmegaR * OmegaL = E, where E = diag{1, 1, 1, 1, 1}. * * We can rewrite out system in form: * du/dt + OmegaL * Lambda * OmegaR du/dx = 0, multiply on matrix OmegaR: * * OmegaR * du/dt + OmegaR * OmegaL * Lambda * OmegaR du/dx = 0. * * Introduce new variables (http://en.wikipedia.org/wiki/Riemann_invariant): * w = {w1, w2, w3, w4, w5}, * w = OmegaR * u, then we got: * * dw/dt + Lambda * dw/dx = 0. * And we get system of independent advection equations, that we can solve separatly. * * So we get next algorithm: * 1. Introduce new variables w = OmegaR * u; * 2. Solve 5 equations of linear advection (in real we solve only 4, because of in fifth equation speed is 0); * 3. Make inverse transformation u = OmegaL * w. */ int i, j; // Courant number (http://en.wikipedia.org/wiki/Courant%E2%80%93Friedrichs%E2%80%93Lewy_condition). const real k1 = t->dt * t->mat.c1 / t->h.x; const real k2 = t->dt * t->mat.c2 / t->h.x; int num_of_threads = omp_get_num_threads(); #pragma omp parallel for shared(t) private(i,j) for (j = 0; j < t->n.y; j++) { /* * Riemann invariants for 5-point sctencil difference scheme. */ le_w w_2, w_1, w, w1, w2; omega_x(&t->mat, &gind(0, j), &w); omega_x(&t->mat, &gind(1, j), &w1); omega_x(&t->mat, &gind(2, j), &w2); w_2 = w_1 = w; // In linear case we can do this. for (i = 0; i < t->n.x; i++) { le_w d; reconstruct(w_2, w_1, w, w1, w2, k1, k2, &d); inc_x(&t->mat, &gind(i, j), &d); w_2 = w_1; w_1 = w; w = w1; w1 = w2; if (i < t->n.x - 3) omega_x(&t->mat, &gind(i + 3, j), &w2); } } }