filename
stringlengths
19
182
omp_pragma_line
stringlengths
24
416
context_chars
int64
100
100
text
stringlengths
152
177k
bsc-pm/mcxx/tests/07_phases_omp.dg/common/c/success_for_06.c
#pragma omp parallel for firstprivate(a, b) lastprivate(a, b)
100
e <stdio.h> int a; int b; int main(int argc, char *argv[]) { int i; a = -3; b = -4; <LOOP-START>for (i = 0; i < 100; i++) { if (a < 0) if (a != -3) abort(); if (b < 0) if (b != -4) abort(); a = i; b = i; }<LOOP-END> <OMP-START>#pragma omp parallel for firstprivate(a, b) lastprivate(a, b)<OMP-END>
bsc-pm/mcxx/tests/07_phases_omp.dg/common/c/success_vla_04.c
#pragma omp parallel for shared(v)
100
[j]: %d\n", v[i][j]); assert(v[i][j] == 0); v[i][j]++; } } <LOOP-START>for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { // printf("2. v[i][j]: %d\n", v[i][j]); assert(v[i][j] == 0); v[i][j]++; } }<LOOP-END> <OMP-START>#pragma omp parallel for shared(v)<OMP-END>
bsc-pm/mcxx/tests/07_phases_omp.dg/common/c/success_vla_04.c
#pragma omp parallel for firstprivate(v)
100
[j]: %d\n", v[i][j]); assert(v[i][j] == 0); v[i][j]++; } } <LOOP-START>for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { // printf("3. v[i][j]: %d\n", v[i][j]); assert(v[i][j] == 1); v[i][j]++; } }<LOOP-END> <OMP-START>#pragma omp parallel for firstprivate(v)<OMP-END>
bsc-pm/mcxx/tests/07_phases_omp.dg/common/c/success_collapse_01.c
#pragma omp parallel for collapse(2)
100
int main(int argc, char* argv[]) { int v[N][N]; int i, j; { init(v); <LOOP-START>for(i = 0; i < N; ++i) for(j = 0; j < N; ++j) v[i][j] += 1; check(v); } { init(v); #pragma omp parallel { #pragma omp for collapse(2) for(i = 0; i < N; ++i) for(j = 0; j < N; ++j) v[i][j] += 1; } check(v); }<LOOP-END> <OMP-START>#pragma omp parallel for collapse(2)<OMP-END>
bsc-pm/mcxx/tests/07_phases_omp.dg/common/c/success_parallel_for_03.c
#pragma omp parallel for reduction(+:s)
100
ude <stdio.h> #define NUM_ELEMS 100 int main(int argc, char *argv[]) { int i; int s = 0; <LOOP-START>for (i = 0; i < NUM_ELEMS; i++) { s = s + i; }<LOOP-END> <OMP-START>#pragma omp parallel for reduction(+:s)<OMP-END>
bsc-pm/mcxx/tests/07_phases_omp.dg/common/c/success_new_udr_06.c
#pragma omp parallel for reduction(mymin:x)
100
for ( i = 0; i < N ; i++ ) a[i] = i; #ifdef NANOX #pragma omp for reduction(mymin:x) #else <LOOP-START>for ( i = 0; i < N ; i++ ) { x = a[i] < x ? a[i] : x; }<LOOP-END> <OMP-START>#pragma omp parallel for reduction(mymin:x)<OMP-END>
bsc-pm/mcxx/tests/07_phases_omp.dg/common/c/success_parallel_for_02.c
#pragma omp parallel for private(x)
100
lude <stdio.h> #define NUM_ELEMS 1000 int main(int argc, char *argv[]) { int c[NUM_ELEMS], x; <LOOP-START>for (int i = 0; i < NUM_ELEMS; i++) { x = i; c[i] = i; }<LOOP-END> <OMP-START>#pragma omp parallel for private(x)<OMP-END>
bsc-pm/mcxx/tests/07_phases_omp.dg/common/c/success_task_03.c
#pragma omp parallel for
100
dlib.h> #define NUM_ELEMS 100 int main(int argc, char* argv[]) { int i; int c[NUM_ELEMS]; <LOOP-START>for (i = 0; i < NUM_ELEMS; i++) { int *p = &(c[i]); #pragma omp task firstprivate(p, i) { *p = i; } }<LOOP-END> <OMP-START>#pragma omp parallel for<OMP-END>
bsc-pm/mcxx/tests/07_phases_omp.dg/common/c/success_new_udr_08.c
#pragma omp parallel for reduction(complex_add:x) reduction(complex_mul:y)
100
) #define N 100 my_complex_t vector[N]; int foo(my_complex_t x, my_complex_t y) { int i; <LOOP-START>for ( i = 0; i < N ; i++ ) { x = complex_add(x,vector[i]); y = complex_mul(y,vector[i]); }<LOOP-END> <OMP-START>#pragma omp parallel for reduction(complex_add:x) reduction(complex_mul:y)<OMP-END>
bsc-pm/mcxx/tests/07_phases_omp.dg/common/c/success_for_16.c
#pragma omp parallel for default(none)
100
nt argc, char* argv[]) { int i; #pragma omp for default(none) for(i=0;i<8;i++) { } <LOOP-START>for(i=0;i<8;i++) { }<LOOP-END> <OMP-START>#pragma omp parallel for default(none)<OMP-END>
bsc-pm/mcxx/tests/07_phases_omp.dg/common/c/success_parallel_for_01.c
#pragma omp parallel for
100
#define NUM_ELEMS 1000 int main(int argc, char *argv[]) { int i = -1; int c[NUM_ELEMS]; <LOOP-START>for (i = 0; i < NUM_ELEMS; i++) { c[i] = i; }<LOOP-END> <OMP-START>#pragma omp parallel for<OMP-END>
bsc-pm/mcxx/tests/07_phases_ompss.dg/cxx/success_task_13.cpp
#pragma omp parallel for reduction(+:result)
100
6_imcxx=yes </testinfo> */ template < typename T> int foo(T* x, T* y, int n) { int result = 0; <LOOP-START>for (int i = 0; i < n; ++i) { result += x[i] + y[i]; }<LOOP-END> <OMP-START>#pragma omp parallel for reduction(+:result)<OMP-END>
bsc-pm/mcxx/tests/07_phases_ompss.dg/cxx/success_parallel_for_slicer_01.cpp
#pragma omp parallel for reduction(+:s)
100
nclude <stdio.h> #include <assert.h> int main(int argc, char *argv[]) { int i; int s = 0; <LOOP-START>for (i = 0; i < 100; i++) { s += i; }<LOOP-END> <OMP-START>#pragma omp parallel for reduction(+:s)<OMP-END>
bsc-pm/mcxx/tests/07_phases_ompss.dg/cxx/success_for_01.cpp
#pragma omp parallel for
100
fo> */ #include <assert.h> template <typename T> void f(T* t, T lower, T length, T val) { T i; <LOOP-START>for (i = lower; i < (lower + length); i++) { t[i] = val + i; }<LOOP-END> <OMP-START>#pragma omp parallel for<OMP-END>
bsc-pm/mcxx/tests/07_phases_ompss.dg/c/success_for_slicer_03.c
#pragma omp parallel for lastprivate(a, b)
100
<stdio.h> int a; int main(int argc, char *argv[]) { int b; int i; a = 3; b = 4; <LOOP-START>for (i = 0; i < 10; i++) { a = i; b = i + 1; }<LOOP-END> <OMP-START>#pragma omp parallel for lastprivate(a, b)<OMP-END>
bsc-pm/mcxx/tests/07_phases_ompss.dg/c/success_for_slicer_04.c
#pragma omp parallel for firstprivate(a, b) lastprivate(a, b)
100
e <stdio.h> int a; int b; int main(int argc, char *argv[]) { int i; a = -3; b = -4; <LOOP-START>for (i = 0; i < 100; i++) { if (a < 0) if (a != -3) abort(); if (b < 0) if (b != -4) abort(); a = i; b = i; }<LOOP-END> <OMP-START>#pragma omp parallel for firstprivate(a, b) lastprivate(a, b)<OMP-END>
bsc-pm/mcxx/tests/07_phases_ompss.dg/c/success_for_slicer_05.c
#pragma omp parallel for firstprivate(a, b) lastprivate(a, b)
100
char *argv[]) { int b[10]; int i; a[1] = 3; a[2] = 2; b[4] = 4; b[5] = 5; <LOOP-START>for (i = 0; i < 10; i++) { a[1] = a[2]; b[4] = b[5]; }<LOOP-END> <OMP-START>#pragma omp parallel for firstprivate(a, b) lastprivate(a, b)<OMP-END>
bsc-pm/mcxx/tests/07_phases_ompss.dg/c/success_array_reductions_01.c
#pragma omp parallel for firstprivate(a) reduction(+:[array_size]result)
100
y_size], int *result) { int i; for (i = 0; i < array_size; i++) { result[i] = 0; } <LOOP-START>for (i = 0; i < NUM_ITEMS; i++) { int j; for (j = 0; j < array_size; j++) { result[j] += a[i][j]; } }<LOOP-END> <OMP-START>#pragma omp parallel for firstprivate(a) reduction(+:[array_size]result)<OMP-END>
bsc-pm/mcxx/tests/07_phases_ompss.dg/c/success_parallel_for_slicer_01.c
#pragma omp parallel for reduction(+:s)
100
nclude <stdio.h> #include <assert.h> int main(int argc, char *argv[]) { int i; int s = 0; <LOOP-START>for (i = 0; i < 100; i++) { s += i; }<LOOP-END> <OMP-START>#pragma omp parallel for reduction(+:s)<OMP-END>
bsc-pm/mcxx/tests/02_typecalc_cxx.dg/success_650.cpp
#pragma omp parallel for
100
rator=config/mercurium test_CXXFLAGS="-fopenmp" </testinfo> */ #include <cstdio> void foo(int N) { <LOOP-START>for (int i = 0; i < N; i++) { printf("%d\n", i); }<LOOP-END> <OMP-START>#pragma omp parallel for<OMP-END>
bsc-pm/mcxx/tests/02_typecalc_cxx.dg/success_650.cpp
#pragma omp parallel for
100
id, but also checks that we convert 'int i(0)' into // 'int i = 0' in this case. void foo2(int N) { <LOOP-START>for (int i(0); i < N; i++) { printf("%d\n", i); }<LOOP-END> <OMP-START>#pragma omp parallel for<OMP-END>
ParRes/Kernels/C1z/nstream-ua-target.c
#pragma omp parallel for simd schedule(static)
100
loc(bytes, host); double * restrict C = omp_target_alloc(bytes, host); double scalar = 3.0; <LOOP-START>for (size_t i=0; i<length; i++) { A[i] = 0.0; B[i] = 2.0; C[i] = 2.0; }<LOOP-END> <OMP-START>#pragma omp parallel for simd schedule(static)<OMP-END>
ParRes/Kernels/C1z/nstream-ua-target.c
#pragma omp parallel for reduction(+:asum)
100
0; i<=iterations; i++) { ar += br + scalar * cr; } ar *= length; double asum = 0.0; <LOOP-START>for (size_t i=0; i<length; i++) { asum += fabs(A[i]); }<LOOP-END> <OMP-START>#pragma omp parallel for reduction(+:asum)<OMP-END>
ParRes/Kernels/C1z/nstream-target.c
#pragma omp parallel for simd
100
strict B = prk_malloc(bytes); double * restrict C = prk_malloc(bytes); double scalar = 3.0; <LOOP-START>for (size_t i=0; i<length; i++) { A[i] = 0.0; B[i] = 2.0; C[i] = 2.0; }<LOOP-END> <OMP-START>#pragma omp parallel for simd<OMP-END>
ParRes/Kernels/C1z/nstream-target.c
#pragma omp parallel for reduction(+:asum)
100
0; i<=iterations; i++) { ar += br + scalar * cr; } ar *= length; double asum = 0.0; <LOOP-START>for (size_t i=0; i<length; i++) { asum += fabs(A[i]); }<LOOP-END> <OMP-START>#pragma omp parallel for reduction(+:asum)<OMP-END>
ParRes/Kernels/C1z/nstream-memcpy-target.c
#pragma omp parallel for simd schedule(static)
100
c(bytes, host); double * restrict h_C = omp_target_alloc(bytes, host); double scalar = 3.0; <LOOP-START>for (size_t i=0; i<length; i++) { h_A[i] = 0.0; h_B[i] = 2.0; h_C[i] = 2.0; }<LOOP-END> <OMP-START>#pragma omp parallel for simd schedule(static)<OMP-END>
ParRes/Kernels/C1z/nstream-memcpy-target.c
#pragma omp parallel for reduction(+:asum)
100
0; i<=iterations; i++) { ar += br + scalar * cr; } ar *= length; double asum = 0.0; <LOOP-START>for (size_t i=0; i<length; i++) { asum += fabs(h_A[i]); }<LOOP-END> <OMP-START>#pragma omp parallel for reduction(+:asum)<OMP-END>
ParRes/Kernels/OPENMP/PIC/pic.c
#pragma omp parallel for private(i, p, fx, fy, ax, ay)
100
{ pic_time = wtime(); } /* Calculate forces on particles and update positions */ <LOOP-START>for (i=0; i<n; i++) { p = particles; fx = 0.0; fy = 0.0; computeTotalForce(p[i], L, Qgrid, &fx, &fy); ax = fx * MASS_INV; ay = fy * MASS_INV; /* Update particle positions, taking into account periodic boundaries */ p[i].x = fmod(p[i].x + p[i].v_x*DT + 0.5*ax*DT*DT + L, L); p[i].y = fmod(p[i].y + p[i].v_y*DT + 0.5*ay*DT*DT + L, L); /* Update velocities */ p[i].v_x += ax * DT; p[i].v_y += ay * DT; }<LOOP-END> <OMP-START>#pragma omp parallel for private(i, p, fx, fy, ax, ay)<OMP-END>
ParRes/Kernels/OPENMP/Transpose/transpose.c
#pragma omp parallel for reduction(+:abserr)
100
bserr=0.0; size_t i, j; double addit = ((double)(iterations+1) * (double) (iterations))/2.0; <LOOP-START>for (j=0;j<order;j++) { for (i=0;i<order; i++) { abserr += ABS(B(i,j) - ((i*order + j)*(iterations+1L)+addit)); } }<LOOP-END> <OMP-START>#pragma omp parallel for reduction(+:abserr)<OMP-END>
ParRes/Kernels/OPENMP/DGEMM/dgemm.c
#pragma omp parallel for private(i,j)
100
exit(EXIT_FAILURE); } ref_checksum = (0.25*forder*forder*forder*(forder-1.0)*(forder-1.0)); <LOOP-START>for(j = 0; j < order; j++) for(i = 0; i < order; i++) { A_arr(i,j) = B_arr(i,j) = (double) j; C_arr(i,j) = 0.0; }<LOOP-END> <OMP-START>#pragma omp parallel for private(i,j) <OMP-END>
ParRes/Kernels/OPENMP/Stencil/stencil.c
#pragma omp parallel for private(i)
100
/* intialize the input and output arrays */ #if PARALLELFOR <LOOP-START>#else #pragma omp for for (j=0; j<n; j++) for (i=0; i<n; i++) IN(i,j) = COEFX*i+COEFY*j; #if PARALLELFOR #pragma omp parallel for private(i) #else #pragma omp for for (j=RADIUS; j<n-RADIUS; j++) for (i=RADIUS; i<n-RADIUS; i++) OUT(i,j) = (DTYPE)0.0; for (iter = 0; iter<=iterations; iter++){ /* start timer after a warmup iteration */ if (iter == 1) { #if !PARALLELFOR #pragma omp barrier #pragma omp master { stencil_time = wtime(); } } #if PARALLELFOR #pragma omp parallel for private(i, ii, jj) #else #pragma omp for for (j=RADIUS; j<n-RADIUS; j++) { for (i=RADIUS; i<n-RADIUS; i++) { #if STAR #if LOOPGEN #include "loop_body_star.incl" #else for (jj=-RADIUS; jj<=RADIUS; jj++) OUT(i,j) += WEIGHT(0,jj)*IN(i,j+jj); for (ii=-RADIUS; ii<0; ii++) OUT(i,j) += WEIGHT(ii,0)*IN(i+ii,j); for (ii=1; ii<=RADIUS; ii++) OUT(i,j) += WEIGHT(ii,0)*IN(i+ii,j); #else #if LOOPGEN #include "loop_body_compact.incl" #else /* would like to be able to unroll this loop, but compiler will ignore */ for (jj=-RADIUS; jj<=RADIUS; jj++) for (ii=-RADIUS; ii<=RADIUS; ii++) OUT(i,j) += WEIGHT(ii,jj)*IN(i+ii,j+jj); } } /* add constant to solution to force refresh of neighbor data, if any */ #if PARALLELFOR #pragma omp parallel for private(i) #else #pragma omp for for (j=0; j<n; j++) for (i=0; i<n; i++) IN(i,j)+= 1.0; }<LOOP-END> <OMP-START>#pragma omp parallel for private(i)<OMP-END>
ParRes/Kernels/OPENMP/Stencil/stencil.c
#pragma omp parallel for private(i)
100
r #endif for (j=0; j<n; j++) for (i=0; i<n; i++) IN(i,j) = COEFX*i+COEFY*j; #if PARALLELFOR <LOOP-START>#else #pragma omp for for (j=RADIUS; j<n-RADIUS; j++) for (i=RADIUS; i<n-RADIUS; i++) OUT(i,j) = (DTYPE)0.0; for (iter = 0; iter<=iterations; iter++){ /* start timer after a warmup iteration */ if (iter == 1) { #if !PARALLELFOR #pragma omp barrier #pragma omp master { stencil_time = wtime(); } } #if PARALLELFOR #pragma omp parallel for private(i, ii, jj) #else #pragma omp for for (j=RADIUS; j<n-RADIUS; j++) { for (i=RADIUS; i<n-RADIUS; i++) { #if STAR #if LOOPGEN #include "loop_body_star.incl" #else for (jj=-RADIUS; jj<=RADIUS; jj++) OUT(i,j) += WEIGHT(0,jj)*IN(i,j+jj); for (ii=-RADIUS; ii<0; ii++) OUT(i,j) += WEIGHT(ii,0)*IN(i+ii,j); for (ii=1; ii<=RADIUS; ii++) OUT(i,j) += WEIGHT(ii,0)*IN(i+ii,j); #else #if LOOPGEN #include "loop_body_compact.incl" #else /* would like to be able to unroll this loop, but compiler will ignore */ for (jj=-RADIUS; jj<=RADIUS; jj++) for (ii=-RADIUS; ii<=RADIUS; ii++) OUT(i,j) += WEIGHT(ii,jj)*IN(i+ii,j+jj); } } /* add constant to solution to force refresh of neighbor data, if any */ #if PARALLELFOR #pragma omp parallel for private(i) #else #pragma omp for for (j=0; j<n; j++) for (i=0; i<n; i++) IN(i,j)+= 1.0; }<LOOP-END> <OMP-START>#pragma omp parallel for private(i)<OMP-END>
ParRes/Kernels/OPENMP/Stencil/stencil.c
#pragma omp parallel for private(i, ii, jj)
100
pragma omp master #endif { stencil_time = wtime(); } } #if PARALLELFOR <LOOP-START>#else #pragma omp for for (j=RADIUS; j<n-RADIUS; j++) { for (i=RADIUS; i<n-RADIUS; i++) { #if STAR #if LOOPGEN #include "loop_body_star.incl" #else for (jj=-RADIUS; jj<=RADIUS; jj++) OUT(i,j) += WEIGHT(0,jj)*IN(i,j+jj); for (ii=-RADIUS; ii<0; ii++) OUT(i,j) += WEIGHT(ii,0)*IN(i+ii,j); for (ii=1; ii<=RADIUS; ii++) OUT(i,j) += WEIGHT(ii,0)*IN(i+ii,j); #else #if LOOPGEN #include "loop_body_compact.incl" #else /* would like to be able to unroll this loop, but compiler will ignore */ for (jj=-RADIUS; jj<=RADIUS; jj++) for (ii=-RADIUS; ii<=RADIUS; ii++) OUT(i,j) += WEIGHT(ii,jj)*IN(i+ii,j+jj); } }<LOOP-END> <OMP-START>#pragma omp parallel for private(i, ii, jj)<OMP-END>
ParRes/Kernels/OPENMP/Stencil/stencil.c
#pragma omp parallel for private(i)
100
/* add constant to solution to force refresh of neighbor data, if any */ #if PARALLELFOR <LOOP-START>#else #pragma omp for for (j=0; j<n; j++) for (i=0; i<n; i++) IN(i,j)+= 1.0; } /* end of iterations */ #if !PARALLELFOR #pragma omp barrier #pragma omp master { stencil_time = wtime() - stencil_time; }<LOOP-END> <OMP-START>#pragma omp parallel for private(i)<OMP-END>
ParRes/Kernels/OPENMP/Stencil/stencil.c
#pragma omp parallel for reduction(+:norm), private (i)
100
/* compute L1 norm in parallel */ #if PARALLELFOR <LOOP-START>#else #pragma omp for reduction(+:norm) for (j=RADIUS; j<n-RADIUS; j++) for (i=RADIUS; i<n-RADIUS; i++) { norm += (DTYPE)ABS(OUT(i,j)); }<LOOP-END> <OMP-START>#pragma omp parallel for reduction(+:norm), private (i)<OMP-END>
ParRes/Kernels/Cxx11/sgemm-cblas.cc
#pragma omp parallel for schedule(dynamic) num_threads(nt)
100
const int n = order; const float alpha = 1.0; const float beta = 1.0; #ifdef _OPENMP <LOOP-START>for (int b=0; b<batches; ++b) { cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, n, n, n, alpha, A[b].data(), n, B[b].data(), n, beta, C[b].data(), n); }<LOOP-END> <OMP-START>#pragma omp parallel for schedule(dynamic) num_threads(nt)<OMP-END>
ParRes/Kernels/Cxx11/dgemm-cblas.cc
#pragma omp parallel for schedule(dynamic) num_threads(nt)
100
const int n = order; const double alpha = 1.0; const double beta = 1.0; #ifdef _OPENMP <LOOP-START>for (int b=0; b<batches; ++b) { cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, n, n, n, alpha, A[b].data(), n, B[b].data(), n, beta, C[b].data(), n); }<LOOP-END> <OMP-START>#pragma omp parallel for schedule(dynamic) num_threads(nt)<OMP-END>
ParRes/Kernels/Cxx11/dgemm-mpi-cblas.cc
#pragma omp parallel for schedule(dynamic) num_threads(nt)
100
const int n = order; const double alpha = 1.0; const double beta = 1.0; #ifdef _OPENMP <LOOP-START>for (int b=0; b<batches; ++b) { cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, n, n, n, alpha, A[b].data(), n, B[b].data(), n, beta, C[b].data(), n); }<LOOP-END> <OMP-START>#pragma omp parallel for schedule(dynamic) num_threads(nt)<OMP-END>
ParRes/Kernels/MPIOPENMP/Transpose/transpose.c
#pragma omp parallel for private (i,it,jt) collapse(2)
100
*/ istart = 0; if (tiling) { #if COLLAPSE <LOOP-START>#else #pragma omp parallel for private (i,it,jt) for (j=0; j<Block_order; j+=Tile_order) for (i=0; i<order; i+=Tile_order) for (jt=j; jt<MIN(Block_order,j+Tile_order);jt++) for (it=i; it<MIN(order,i+Tile_order); it++) { A(it,jt) = (double) (order*(jt+colstart) + it); B(it,jt) = 0.0; }<LOOP-END> <OMP-START>#pragma omp parallel for private (i,it,jt) collapse(2)<OMP-END>
ParRes/Kernels/MPIOPENMP/Transpose/transpose.c
#pragma omp parallel for private (i,it,jt)
100
if (tiling) { #if COLLAPSE #pragma omp parallel for private (i,it,jt) collapse(2) #else <LOOP-START>for (j=0; j<Block_order; j+=Tile_order) for (i=0; i<order; i+=Tile_order) for (jt=j; jt<MIN(Block_order,j+Tile_order);jt++) for (it=i; it<MIN(order,i+Tile_order); it++) { A(it,jt) = (double) (order*(jt+colstart) + it); B(it,jt) = 0.0; }<LOOP-END> <OMP-START>#pragma omp parallel for private (i,it,jt)<OMP-END>
ParRes/Kernels/MPIOPENMP/Transpose/transpose.c
#pragma omp parallel for private (i)
100
jt) = (double) (order*(jt+colstart) + it); B(it,jt) = 0.0; } } else { <LOOP-START>for (j=0;j<Block_order;j++) for (i=0;i<order; i++) { A(i,j) = (double) (order*(j+colstart) + i); B(i,j) = 0.0; }<LOOP-END> <OMP-START>#pragma omp parallel for private (i)<OMP-END>
ParRes/Kernels/MPIOPENMP/Transpose/transpose.c
#pragma omp parallel for private (j)
100
*/ istart = colstart; if (!tiling) { <LOOP-START>for (i=0; i<Block_order; i++) for (j=0; j<Block_order; j++) { B(j,i) += A(i,j); A(i,j) += 1.0; }<LOOP-END> <OMP-START>#pragma omp parallel for private (j)<OMP-END>
ParRes/Kernels/MPIOPENMP/Transpose/transpose.c
#pragma omp parallel for private (j,it,jt) collapse(2)
100
j++) { B(j,i) += A(i,j); A(i,j) += 1.0; } } else { #if COLLAPSE <LOOP-START>#else #pragma omp parallel for private (j,it,jt) for (i=0; i<Block_order; i+=Tile_order) for (j=0; j<Block_order; j+=Tile_order) for (it=i; it<MIN(Block_order,i+Tile_order); it++) for (jt=j; jt<MIN(Block_order,j+Tile_order);jt++) { B(jt,it) += A(it,jt); A(it,jt) += 1.0; }<LOOP-END> <OMP-START>#pragma omp parallel for private (j,it,jt) collapse(2)<OMP-END>
ParRes/Kernels/MPIOPENMP/Transpose/transpose.c
#pragma omp parallel for private (j,it,jt)
100
} else { #if COLLAPSE #pragma omp parallel for private (j,it,jt) collapse(2) #else <LOOP-START>for (i=0; i<Block_order; i+=Tile_order) for (j=0; j<Block_order; j+=Tile_order) for (it=i; it<MIN(Block_order,i+Tile_order); it++) for (jt=j; jt<MIN(Block_order,j+Tile_order);jt++) { B(jt,it) += A(it,jt); A(it,jt) += 1.0; }<LOOP-END> <OMP-START>#pragma omp parallel for private (j,it,jt)<OMP-END>
ParRes/Kernels/MPIOPENMP/Transpose/transpose.c
#pragma omp parallel for private (j)
100
COMM_WORLD, &recv_req); #endif istart = send_to*Block_order; if (!tiling) { <LOOP-START>for (i=0; i<Block_order; i++) for (j=0; j<Block_order; j++){ Work_out(j,i) = A(i,j); A(i,j) += 1.0; }<LOOP-END> <OMP-START>#pragma omp parallel for private (j)<OMP-END>
ParRes/Kernels/MPIOPENMP/Transpose/transpose.c
#pragma omp parallel for private (j,it,jt) collapse(2)
100
Work_out(j,i) = A(i,j); A(i,j) += 1.0; } } else { #if COLLAPSE <LOOP-START>#else #pragma omp parallel for private (j,it,jt) for (i=0; i<Block_order; i+=Tile_order) for (j=0; j<Block_order; j+=Tile_order) for (it=i; it<MIN(Block_order,i+Tile_order); it++) for (jt=j; jt<MIN(Block_order,j+Tile_order);jt++) { Work_out(jt,it) = A(it,jt); A(it,jt) += 1.0; }<LOOP-END> <OMP-START>#pragma omp parallel for private (j,it,jt) collapse(2)<OMP-END>
ParRes/Kernels/MPIOPENMP/Transpose/transpose.c
#pragma omp parallel for private (j,it,jt)
100
else { #if COLLAPSE #pragma omp parallel for private (j,it,jt) collapse(2) #else <LOOP-START>for (i=0; i<Block_order; i+=Tile_order) for (j=0; j<Block_order; j+=Tile_order) for (it=i; it<MIN(Block_order,i+Tile_order); it++) for (jt=j; jt<MIN(Block_order,j+Tile_order);jt++) { Work_out(jt,it) = A(it,jt); A(it,jt) += 1.0; }<LOOP-END> <OMP-START>#pragma omp parallel for private (j,it,jt)<OMP-END>
ParRes/Kernels/MPIOPENMP/Transpose/transpose.c
#pragma omp parallel for private (i)
100
cv_from*Block_order; /* scatter received block to transposed matrix; no need to tile */ <LOOP-START>for (j=0; j<Block_order; j++) for (i=0; i<Block_order; i++) B(i,j) += Work_in(i,j); } /* end of phase loop */ } /* end of iterations */ local_trans_time = wtime() - local_trans_time; MPI_Reduce(&local_trans_time, &trans_time, 1, MPI_DOUBLE, MPI_MAX, root, MPI_COMM_WORLD); abserr = 0.0; istart = 0; double addit = ((double)(iterations+1) * (double) (iterations))/2.0; #pragma omp parallel for private (i) for (j=0;j<Block_order;j++) for (i=0;i<order; i++) { abserr += ABS(B(i,j) - (double)((order*i + j+colstart)*(iterations+1)+addit)); }<LOOP-END> <OMP-START>#pragma omp parallel for private (i)<OMP-END>
ParRes/Kernels/MPIOPENMP/Transpose/transpose.c
#pragma omp parallel for private (i)
100
bserr = 0.0; istart = 0; double addit = ((double)(iterations+1) * (double) (iterations))/2.0; <LOOP-START>for (j=0;j<Block_order;j++) for (i=0;i<order; i++) { abserr += ABS(B(i,j) - (double)((order*i + j+colstart)*(iterations+1)+addit)); }<LOOP-END> <OMP-START>#pragma omp parallel for private (i)<OMP-END>
ParRes/Kernels/MPIOPENMP/Nstream/nstream.c
#pragma omp parallel for simd
100
fset = %ld\n", offset); printf("Number of iterations = %d\n", iterations); } <LOOP-START>for (j=0; j<length; j++) { a[j] = 0.0; b[j] = 2.0; c[j] = 2.0; }<LOOP-END> <OMP-START>#pragma omp parallel for simd<OMP-END>
ParRes/Kernels/MPIOPENMP/Nstream/nstream.c
#pragma omp parallel for simd
100
if (iter == 1) { MPI_Barrier(MPI_COMM_WORLD); local_nstream_time = wtime(); } <LOOP-START>for (j=0; j<length; j++) a[j] += b[j]+scalar*c[j]; } /* end iterations */ /********************************************************************* ** Analyze and output results. *********************************************************************/ local_nstream_time = wtime() - local_nstream_time; MPI_Reduce(&local_nstream_time, &nstream_time, 1, MPI_DOUBLE, MPI_MAX, root, MPI_COMM_WORLD); if (my_ID == root) { if (checkTRIADresults(iterations, length)) { avgtime = nstream_time/iterations; printf("Rate (MB/s): %lf Avg time (s): %lf\n", 1.0E-06 * bytes/avgtime, avgtime); } else error = 1; }<LOOP-END> <OMP-START>#pragma omp parallel for simd<OMP-END>
ParRes/Kernels/MPIOPENMP/Nstream/nstream.c
#pragma omp parallel for simd reduction(+:asum)
100
0; iter<=iterations; iter++) aj += bj+scalar*cj; aj = aj * (double) (length); asum = 0.0; <LOOP-START>for (j=0; j<length; j++) asum += a[j]; #if VERBOSE printf ("Results Comparison: \n"); printf (" Expected checksum: %f\n",aj); printf (" Observed checksum: %f\n",asum); if (ABS(aj-asum)/asum > epsilon) { printf ("Failed Validation on output array\n"); #if !VERBOSE printf (" Expected checksum: %f \n",aj); printf (" Observed checksum: %f \n",asum); return (0); }<LOOP-END> <OMP-START>#pragma omp parallel for simd reduction(+:asum)<OMP-END>
ParRes/Kernels/MPIOPENMP/Stencil/stencil.c
#pragma omp parallel for private (i)
100
) (n-2*RADIUS); /* intialize the input and output arrays */ <LOOP-START>for (j=jstart; j<=jend; j++) for (i=istart; i<=iend; i++) { IN(i,j) = COEFX*i+COEFY*j; OUT(i,j) = (DTYPE)0.0; }<LOOP-END> <OMP-START>#pragma omp parallel for private (i)<OMP-END>
ParRes/Kernels/MPIOPENMP/Stencil/stencil.c
#pragma omp parallel for private (i, j, ii, jj)
100
+) { IN(i,j) = left_buf_in[kk++]; } } /* Apply the stencil operator */ <LOOP-START>for (j=MAX(jstart,RADIUS); j<=MIN(n-RADIUS-1,jend); j++) { for (i=MAX(istart,RADIUS); i<=MIN(n-RADIUS-1,iend); i++) { #if LOOPGEN #include "loop_body_star.incl" #else for (jj=-RADIUS; jj<=RADIUS; jj++) OUT(i,j) += WEIGHT(0,jj)*IN(i,j+jj); for (ii=-RADIUS; ii<0; ii++) OUT(i,j) += WEIGHT(ii,0)*IN(i+ii,j); for (ii=1; ii<=RADIUS; ii++) OUT(i,j) += WEIGHT(ii,0)*IN(i+ii,j); } }<LOOP-END> <OMP-START>#pragma omp parallel for private (i, j, ii, jj)<OMP-END>
ParRes/Kernels/MPIOPENMP/Stencil/stencil.c
#pragma omp parallel for private (i)
100
i=1; ii<=RADIUS; ii++) OUT(i,j) += WEIGHT(ii,0)*IN(i+ii,j); #endif } } <LOOP-START>/* add constant to solution to force refresh of neighbor data, if any */ for (j=jstart; j<=jend; j++) for (i=istart; i<=iend; i++) IN(i,j)+= 1.0; } local_stencil_time = wtime() - local_stencil_time; MPI_Reduce(&local_stencil_time, &stencil_time, 1, MPI_DOUBLE, MPI_MAX, root, MPI_COMM_WORLD); /* compute L1 norm in parallel */ local_norm = (DTYPE) 0.0; #pragma omp parallel for reduction(+:local_norm) private (i) for (j=MAX(jstart,RADIUS); j<=MIN(n-RADIUS-1,jend); j++) { for (i=MAX(istart,RADIUS); i<=MIN(n-RADIUS-1,iend); i++) { local_norm += (DTYPE)ABS(OUT(i,j)); } }<LOOP-END> <OMP-START>#pragma omp parallel for private (i)<OMP-END>
ParRes/Kernels/MPIOPENMP/Stencil/stencil.c
#pragma omp parallel for reduction(+:local_norm) private (i)
100
e L1 norm in parallel */ local_norm = (DTYPE) 0.0; <LOOP-START>for (j=MAX(jstart,RADIUS); j<=MIN(n-RADIUS-1,jend); j++) { for (i=MAX(istart,RADIUS); i<=MIN(n-RADIUS-1,iend); i++) { local_norm += (DTYPE)ABS(OUT(i,j)); } }<LOOP-END> <OMP-START>#pragma omp parallel for reduction(+:local_norm) private (i)<OMP-END>
NikiforovAll/JacobiEigenvalueAlgorithm/JacobiEigenvalueAlgorithm/Bisection.cpp
#pragma omp parallel for
100
//omp_set_num_threads(nthreads); //omp_set_dynamic(0); //int threads = omp_get_max_threads(); <LOOP-START>for (int i = 0; i < nthreads; i++) { //std::cout << "threads" << omp_get_num_threads() << std::endl; int f = i * (n / nthreads); int l = (i + 1)*(n / nthreads) - 1; compute_group_bisect(diagonal, offdiagonal, left_boundary, right_boundary, f, l, n, relative_tolerance, eigenvalues); }<LOOP-END> <OMP-START>#pragma omp parallel for<OMP-END>
NikiforovAll/JacobiEigenvalueAlgorithm/JacobiEigenvalueAlgorithm/JacobiAsync.cpp
#pragma omp parallel for shared(distr_status, top, bot, S, U, processPointer) private(row,col)
100
j = 0; j < n - 1; j++) { distr_status.clear(); toProcess.clear(); processPointer = 0; <LOOP-START>//#pragma omp parallel for shared(top,bot) private(row,col) for (int i = 0; i < S.size1() / 2; i++) { //cout << "pair" << endl << top << endl << bot << endl; std::string num_thread_str = "[" + std::to_string(omp_get_thread_num()) + "]"; row = std::max(top(i), bot(i)) - 1; col = std::min(top(i), bot(i)) - 1; if (checkConjunction(distr_status, row) && checkConjunction(distr_status, col)) { //cout << "d_status" << num_thread_str << distr_status << endl; setConjunction(distr_status, row); setConjunction(distr_status, col); rotateRowCol(S, U, col, row); //cout << num_thread_str << "operated:" << col << " -col-row- " << row << endl; } else { toProcess(processPointer, 1) = row; toProcess(processPointer, 0) = col; #pragma omp atomic processPointer++; //cout << num_thread_str << "not operated:" << col << " -col-row- " << row << endl; } }<LOOP-END> <OMP-START>#pragma omp parallel for shared(distr_status, top, bot, S, U, processPointer) private(row,col) <OMP-END>
NikiforovAll/JacobiEigenvalueAlgorithm/JacobiEigenvalueAlgorithm/JacobiAsync.cpp
#pragma omp parallel for shared(top,bot) private(row,col)
100
lel for shared(distr_status, top, bot, S, U, processPointer) private(row,col) //num_threads(2) //<LOOP-START>for (int i = 0; i < S.size1() / 2; i++) { //cout << "pair" << endl << top << endl << bot << endl; std::string num_thread_str = "[" + std::to_string(omp_get_thread_num()) + "]"; row = std::max(top(i), bot(i)) - 1; col = std::min(top(i), bot(i)) - 1; if (checkConjunction(distr_status, row) && checkConjunction(distr_status, col)) { //cout << "d_status" << num_thread_str << distr_status << endl; setConjunction(distr_status, row); setConjunction(distr_status, col); rotateRowCol(S, U, col, row); //cout << num_thread_str << "operated:" << col << " -col-row- " << row << endl; } else { toProcess(processPointer, 1) = row; toProcess(processPointer, 0) = col; #pragma omp atomic processPointer++; //cout << num_thread_str << "not operated:" << col << " -col-row- " << row << endl; } }<LOOP-END> <OMP-START>#pragma omp parallel for shared(top,bot) private(row,col)<OMP-END>
NikiforovAll/JacobiEigenvalueAlgorithm/JacobiEigenvalueAlgorithm/parallel_jacobi.h
#pragma omp parallel for default(none) shared(mat, n, si, co, pe, isodd)
100
//root.start(); while (not_converged) { for (int set = 0; set<n; ++set) { #ifdef omptest <LOOP-START>for (int k = 0; k<m; ++k) { int p, q; pe.get(k, p, q); if (isodd && (p == n || q == n)) continue; symmetric_schur_new(mat, p, q, co[k], si[k]); premultiply(mat, p, q, co[k], si[k]); }<LOOP-END> <OMP-START>#pragma omp parallel for default(none) shared(mat, n, si, co, pe, isodd)<OMP-END>
NikiforovAll/JacobiEigenvalueAlgorithm/JacobiEigenvalueAlgorithm/parallel_jacobi.h
#pragma omp parallel for default(none) shared(mat, n, si, co, pe, isodd)
100
schur_new(mat, p, q, co[k], si[k]); premultiply(mat, p, q, co[k], si[k]); } #ifdef omptest <LOOP-START>for (int k = 0; k<m; ++k) { int p, q; pe.get(k, p, q); if (isodd && (p == n || q == n)) continue; postmultiply(mat, p, q, co[k], si[k]); }<LOOP-END> <OMP-START>#pragma omp parallel for default(none) shared(mat, n, si, co, pe, isodd) <OMP-END>
NikiforovAll/JacobiEigenvalueAlgorithm/JacobiEigenvalueAlgorithm/JacobiIteration1.cpp
#pragma omp parallel for shared(S)
100
ads(); bool iterating = true; while (iterating) { debugMatrixForm(S); ssteqr_debug(S); //<LOOP-START>for (int pp = 0; pp < n - 2; pp += 2) { int p = pp; int q = p + 1; ////printf("In thread %d p = %d q = %d\n", omp_get_thread_num(), p, q); //std::cout << "S(p, q)" << S(p, q) << " | " << "S(q, p)" << S(q, p) << std::endl; //debugMatrixForm(S); //std::cout << p <<" p|q "<< q << std::endl; rotateJacobi2(S, q, p); debugMatrixForm(S); ssteqr_debug(S); //std::cout << "S(p, q)" << S(p, q) << " | "<< "S(q, p)" << S(q, p) << std::endl; //debugMatrixForm(S); //std::cout << p << " p|q " << q << std::endl; //std::cout << "====" << std::endl; }<LOOP-END> <OMP-START>#pragma omp parallel for shared(S) <OMP-END>
NikiforovAll/JacobiEigenvalueAlgorithm/JacobiEigenvalueAlgorithm/JacobiIteration1.cpp
#pragma omp parallel for shared(S)
100
; //std::cout << p << " p|q " << q << std::endl; //std::cout << "====" << std::endl; } //<LOOP-START>for (int pp = 1; pp < n - 1; pp += 2) { int p = pp; int q = p + 1; /*std::cout << "S(p, q)" << S(p, q) << " | " << "S(q, p)" << S(q, p) << std::endl; debugMatrixForm(S); std::cout << p <<" p|q "<< q << std::endl;*/ rotateJacobi2(S, q, p); /* std::cout << "S(p, q)" << S(p, q) << " | "<< "S(q, p)" << S(q, p) << std::endl; debugMatrixForm(S); std::cout << p << " p|q " << q << std::endl; std::cout << "====" << std::endl;*/ }<LOOP-END> <OMP-START>#pragma omp parallel for shared(S)<OMP-END>
NikiforovAll/JacobiEigenvalueAlgorithm/JacobiEigenvalueAlgorithm/JacobiEigenCode/parallel_jacobi.h
#pragma omp parallel for default(none) shared(mat, n, si, co, pe, isodd)
100
//root.start(); while (not_converged) { for (int set = 0; set<n; ++set) { #ifdef omptest <LOOP-START>for (int k = 0; k<m; ++k) { int p, q; pe.get(k, p, q); if (isodd && (p == n || q == n)) continue; symmetric_schur_new(mat, p, q, co[k], si[k]); premultiply(mat, p, q, co[k], si[k]); }<LOOP-END> <OMP-START>#pragma omp parallel for default(none) shared(mat, n, si, co, pe, isodd)<OMP-END>
NikiforovAll/JacobiEigenvalueAlgorithm/JacobiEigenvalueAlgorithm/JacobiEigenCode/parallel_jacobi.h
#pragma omp parallel for default(none) shared(mat, n, si, co, pe, isodd)
100
schur_new(mat, p, q, co[k], si[k]); premultiply(mat, p, q, co[k], si[k]); } #ifdef omptest <LOOP-START>for (int k = 0; k<m; ++k) { int p, q; pe.get(k, p, q); if (isodd && (p == n || q == n)) continue; postmultiply(mat, p, q, co[k], si[k]); }<LOOP-END> <OMP-START>#pragma omp parallel for default(none) shared(mat, n, si, co, pe, isodd) <OMP-END>
NikiforovAll/JacobiEigenvalueAlgorithm/JacobiEigenvalueAlgorithm/JacobiEigenCode/JacobiIteration1.cpp
#pragma omp parallel for shared(S)
100
ads(); bool iterating = true; while (iterating) { debugMatrixForm(S); ssteqr_debug(S); //<LOOP-START>for (int pp = 0; pp < n - 2; pp += 2) { int p = pp; int q = p + 1; ////printf("In thread %d p = %d q = %d\n", omp_get_thread_num(), p, q); //std::cout << "S(p, q)" << S(p, q) << " | " << "S(q, p)" << S(q, p) << std::endl; //debugMatrixForm(S); //std::cout << p <<" p|q "<< q << std::endl; rotateJacobi2(S, q, p); debugMatrixForm(S); ssteqr_debug(S); //std::cout << "S(p, q)" << S(p, q) << " | "<< "S(q, p)" << S(q, p) << std::endl; //debugMatrixForm(S); //std::cout << p << " p|q " << q << std::endl; //std::cout << "====" << std::endl; }<LOOP-END> <OMP-START>#pragma omp parallel for shared(S) <OMP-END>
NikiforovAll/JacobiEigenvalueAlgorithm/JacobiEigenvalueAlgorithm/JacobiEigenCode/JacobiIteration1.cpp
#pragma omp parallel for shared(S)
100
; //std::cout << p << " p|q " << q << std::endl; //std::cout << "====" << std::endl; } //<LOOP-START>for (int pp = 1; pp < n - 1; pp += 2) { int p = pp; int q = p + 1; /*std::cout << "S(p, q)" << S(p, q) << " | " << "S(q, p)" << S(q, p) << std::endl; debugMatrixForm(S); std::cout << p <<" p|q "<< q << std::endl;*/ rotateJacobi2(S, q, p); /* std::cout << "S(p, q)" << S(p, q) << " | "<< "S(q, p)" << S(q, p) << std::endl; debugMatrixForm(S); std::cout << p << " p|q " << q << std::endl; std::cout << "====" << std::endl;*/ }<LOOP-END> <OMP-START>#pragma omp parallel for shared(S)<OMP-END>
rshrc/parallel-processing/openmp/parallel_loops.c
#pragma omp parallel for
100
main(int argc, char *argv[]) { int arr[50000], count0 = 0, count1 = 0, count2 = 0, count3 = 0; <LOOP-START>for (int i = 0; i < 50000; i++) { int thread_being_used = omp_get_thread_num(); arr[i] = 5 * i; printf("Using Thread : %d\n", thread_being_used); if (thread_being_used == 0) count0++; else if (thread_being_used == 1) count1++; else if (thread_being_used == 2) count2++; else count3++; }<LOOP-END> <OMP-START>#pragma omp parallel for<OMP-END>
AyushBhandariNITK/Parallel_Graph_Coloring_Using_Openmp/coloring.cpp
#pragma omp parallel for shared(allIsColored) reduction(+:num_colored)
100
nd; } bool GraphColoring::allColored() const { bool allIsColored = true; uint num_colored = 0; <LOOP-START>for (int i = 0; i < num_vertices; i++) { if (colors[i] == UNKNOWN) { allIsColored = false; } num_colored++; }<LOOP-END> <OMP-START>#pragma omp parallel for shared(allIsColored) reduction(+:num_colored)<OMP-END>
AyushBhandariNITK/Parallel_Graph_Coloring_Using_Openmp/coloring.cpp
#pragma omp parallel for reduction(+:false_colored)
100
red++; } return allIsColored; } bool GraphColoring::accuracy() const { int false_colored = 0; <LOOP-START>for (int v_i = 0; v_i < num_vertices; v_i++) { for (int neighbor_ind = row_ptr[v_i]; neighbor_ind < row_ptr[v_i + 1]; neighbor_ind++) { const int neighbor = col_ind[neighbor_ind]; if (colors[neighbor] == colors[v_i]) { false_colored++; } } }<LOOP-END> <OMP-START>#pragma omp parallel for reduction(+:false_colored)<OMP-END>
AyushBhandariNITK/Parallel_Graph_Coloring_Using_Openmp/coloring.cpp
#pragma omp parallel for
100
s // ======================================================== void GraphColoring::assignColors() { <LOOP-START>for (uint vertex_ind = 0; vertex_ind < unvisited_vertices_tail; vertex_ind++) { const uint vertex = unvisited_vertices[vertex_ind]; colors[vertex] = getNextColor(vertex); }<LOOP-END> <OMP-START>#pragma omp parallel for<OMP-END>
AyushBhandariNITK/Parallel_Graph_Coloring_Using_Openmp/coloring.cpp
#pragma omp parallel for schedule(guided)
100
ts() { // Traverse edges of the graph, for edges (u, v) where C[u] = C[v] reset color of min(u, v) <LOOP-START>for (unsigned int vertex_ind = 0; vertex_ind < unvisited_vertices_tail; vertex_ind++) { const uint vertex = unvisited_vertices[vertex_ind]; for (unsigned int neighbor_ind = row_ptr[vertex]; neighbor_ind < row_ptr[vertex + 1]; neighbor_ind++) { const uint neighbor_label = col_ind[neighbor_ind]; if (colors[neighbor_label] == colors[vertex]) { const uint minLabel = std::min(neighbor_label, vertex); colors[minLabel] = UNKNOWN; } } }<LOOP-END> <OMP-START>#pragma omp parallel for schedule(guided)<OMP-END>
AyushBhandariNITK/Parallel_Graph_Coloring_Using_Openmp/coloring.cpp
#pragma omp parallel for collapse(1)
100
e color of the one having the color on the other // version 0.01 - linear search for such vertices <LOOP-START>for (unsigned int vertex_ind = 0; vertex_ind < unvisited_vertices_tail; vertex_ind++) { const uint vertex = unvisited_vertices[vertex_ind]; const uint vertex_color = colors[vertex]; for (uint neighbor_ind = row_ptr[vertex]; neighbor_ind < row_ptr[vertex + 1]; neighbor_ind++) { const uint neighbor_label = col_ind[neighbor_ind]; if (colors[neighbor_label] != UNKNOWN) { forbiddens[vertex].insert(colors[neighbor_label]); } } }<LOOP-END> <OMP-START>#pragma omp parallel for collapse(1)<OMP-END>
lazzati-astro/MCRaT/OLDER_MCRaT_VERSIONS/mcrat.c
#pragma omp parallel for num_threads(num_thread) private(angle_count)
100
=(int) (theta_jmin); angle_count< (int) (theta_jmax+1) ;angle_count=angle_count+delta_theta ) <LOOP-START>for (angle_count=0; angle_count< num_angles ;angle_count++ ) { printf("%d\t%lf\n", omp_get_thread_num(), delta_theta ); double inj_radius; int frm2, frm0; char mc_filename[200]=""; char mc_filename_2[200]=""; char mc_operation[200]=""; char mc_dir[200]="" ; int file_count = 0; DIR * dirp; struct dirent * entry; struct stat st = {0}; double theta_jmin_thread=0, theta_jmax_thread=0; theta_jmin_thread= (*(thread_theta+angle_count))*(M_PI/180);//(*(thread_theta+omp_get_thread_num() )); theta_jmax_thread= ((*(thread_theta+angle_count))+delta_theta)*(M_PI/180);//(*(thread_theta+omp_get_thread_num()+1 )); printf("Thread %d: %0.1lf, %0.1lf \n %d %d\n", omp_get_thread_num(), theta_jmin_thread*180/M_PI, theta_jmax_thread*180/M_PI, frm2_small, frm2_large ); snprintf(mc_dir,sizeof(flash_prefix),"%s%s%0.1lf-%0.1lf/",FILEPATH,MC_PATH, theta_jmin_thread*180/M_PI, theta_jmax_thread*180/M_PI ); //have to add angle into this printf(">> Thread %d in MCRaT: I am working on path: %s \n",omp_get_thread_num(), mc_dir ); if ((theta_jmin_thread >= 0) && (theta_jmax_thread <= (2*M_PI/180) )) //if within small angle (0-2 degrees) use _small inj_radius and frm2 { inj_radius=inj_radius_small; frm2=frm2_small; frm0=frm0_small; } else { inj_radius=inj_radius_large; frm2=frm2_large; frm0=frm0_large; } printf("Thread %d: %0.1lf, %0.1lf \n %d %e %d\n", omp_get_thread_num(), theta_jmin_thread*180/M_PI, theta_jmax_thread*180/M_PI, frm2, inj_radius, frm0 ); //want to also have another set of threads that each has differing ranges of frame injections therefore do nested parallelism here so each thread can read its own checkpoint file //#pragma omp parallel num_threads(2) firstprivate(restrt) { char flash_file[200]=""; char log_file[200]=""; FILE *fPtr=NULL; //pointer to log file for each thread double *xPtr=NULL, *yPtr=NULL, *rPtr=NULL, *thetaPtr=NULL, *velxPtr=NULL, *velyPtr=NULL, *densPtr=NULL, *presPtr=NULL, *gammaPtr=NULL, *dens_labPtr=NULL; double *phiPtr=NULL, *velzPtr=NULL, *zPtr=NULL; double *szxPtr=NULL,*szyPtr=NULL, *tempPtr=NULL; //pointers to hold data from FLASH files int num_ph=0, array_num=0, ph_scatt_index=0, max_scatt=0, min_scatt=0,i=0; //number of photons produced in injection algorithm, number of array elleemnts from reading FLASH file, index of photon whch does scattering, generic counter double dt_max=0, thescatt=0, accum_time=0; double gamma_infinity=0, time_now=0, time_step=0, avg_scatt=0; //gamma_infinity not used? double ph_dens_labPtr=0, ph_vxPtr=0, ph_vyPtr=0, ph_tempPtr=0, ph_vzPtr=0;// *ph_cosanglePtr=NULL ; double min_r=0, max_r=0; int frame=0, scatt_frame=0, frame_scatt_cnt=0, scatt_framestart=0, framestart=0; struct photon *phPtr=NULL; //pointer to array of photons //if (omp_get_thread_num()==0) //{ //printf( "A:%d Im Thread: %d with ancestor %d working in %s\n", omp_get_num_threads(), omp_get_thread_num(), omp_get_ancestor_thread_num(1), mc_dir); //} if (restrt=='c') { printf(">> mc.py: Reading checkpoint\n"); //#pragma omp critical { readCheckpoint(mc_dir, &phPtr, frm0, &framestart, &scatt_framestart, &num_ph, &restrt, &time_now); /* for (i=0;i<num_ph;i++) { printf("%e,%e,%e, %e,%e,%e, %e, %e\n",(phPtr+i)->p0, (phPtr+i)->p1, (phPtr+i)->p2, (phPtr+i)->p3, (phPtr+i)->r0, (phPtr+i)->r1, (phPtr+i)->r2, (phPtr+i)->num_scatt ); } */ if (restrt=='c') { printf(">> Thread %d with ancestor %d: Starting from photons injected at frame: %d out of %d\n", omp_get_thread_num(), omp_get_ancestor_thread_num(1),framestart, frm2); printf(">> Thread %d with ancestor %d: Continuing scattering %d photons from frame: %d\n", omp_get_thread_num(), omp_get_ancestor_thread_num(1),num_ph, scatt_framestart); printf(">> Thread %d with ancestor %d: The time now is: %e\n", omp_get_thread_num(), omp_get_ancestor_thread_num(1),time_now); } else { printf(">> Thread %d with ancestor %d: Continuing simulation by injecting photons at frame: %d out of %d\n", omp_get_thread_num(), omp_get_ancestor_thread_num(1),framestart, frm2); //starting with new photon injection is same as restarting sim } } } else if (stat(mc_dir, &st) == -1) { mkdir(mc_dir, 0777); //make the directory with full permissions framestart=frm0; //if restarting then start from parameters given in mc.par file scatt_framestart=frm0; } else { //remove everything from MC directory to ensure no corruption of data if theres other files there besides the mc.par file //for a checkpoint implementation, need to find the latest checkpoint file and read it and not delete the files #pragma omp critical { printf(">> Thread %d with ancestor %d: Cleaning directory \n",omp_get_thread_num(), omp_get_ancestor_thread_num(1)); dirp = opendir(mc_dir); while ((entry = readdir(dirp)) != NULL) { if (entry->d_type == DT_REG) { /* If the entry is a regular file */ file_count++; //count how many files are in dorectory } } printf("File count %d\n", file_count); if (file_count>0) { for (i=0;i<=last_frm;i++) { snprintf(mc_filename,sizeof(mc_filename),"%s%s%d%s", mc_dir,"mcdata_",i,"_P0.dat"); if(( access( mc_filename, F_OK ) != -1 ) ) { snprintf(mc_operation,sizeof(flash_prefix),"%s%s%s%d%s","exec rm ", mc_dir,"mcdata_",i,"_*.dat"); //prepares string to remove *.dat in mc_dir printf("%s\n",mc_operation); system(mc_operation); //snprintf(mc_operation,sizeof(flash_prefix),"%s%s%s%d%s","exec rm ", mc_dir,"mcdata_",i,"_*"); //system(mc_operation); } } //snprintf(mc_operation,sizeof(flash_prefix),"%s%s%s","exec rm ", mc_dir,"mcdata_PW_*.dat"); //prepares string to remove *.dat in mc_dir //system(mc_operation); snprintf(mc_operation,sizeof(flash_prefix),"%s%s%s","exec rm ", mc_dir,"mcdata_PW.dat"); //prepares string to remove *.dat in mc_dir system(mc_operation); //snprintf(mc_operation,sizeof(flash_prefix),"%s%s%s","exec rm ", mc_dir,"mc_chkpt_*.dat"); //prepares string to remove *.dat in mc_dir //system(mc_operation); snprintf(mc_operation,sizeof(flash_prefix),"%s%s%s","exec rm ", mc_dir,"mc_output_*.log"); //prepares string to remove *.log in mc_dir system(mc_operation); } } framestart=frm0; //if restarting then start from parameters given in mc.par file scatt_framestart=frm0; } dt_max=1.0/fps; //#pragma omp barrier snprintf(log_file,sizeof(log_file),"%s%s",mc_dir,"mc_output.log" ); printf("%s\n",log_file); fPtr=fopen(log_file, "w"); fprintf(fPtr, "%d Im Thread: %d with ancestor %d Starting on Frame: %d scatt_framestart: %d\n", omp_get_num_threads(), omp_get_thread_num(), omp_get_ancestor_thread_num(1), framestart, scatt_framestart); fflush(fPtr); //fclose(fPtr); //#pragma omp barrier //exit(0); //loop over frames //for a checkpoint implementation, start from the last saved "frame" value and go to the saved "frm2" value //#pragma omp for for (frame=framestart;frame<=frm2;frame++) { if (restrt=='r') { time_now=frame/fps; //for a checkpoint implmentation, load the saved "time_now" value when reading the ckeckpoint file otherwise calculate it normally } //printf(">> mc.py: Working on Frame %d\n", frame); fprintf(fPtr,"%d Im Thread: %d with ancestor %d Working on Frame: %d\n", omp_get_num_threads(), omp_get_thread_num(), omp_get_ancestor_thread_num(1), frame); fflush(fPtr); if (restrt=='r') { //exit(0); //read in FLASH file //for a checkpoint implmentation, dont need to read the file yet if (dim_switch==0) { //put proper number at the end of the flash file modifyFlashName(flash_file, flash_prefix, frame, dim_switch); fprintf(fPtr,">> Im Thread: %d with ancestor %d: Opening FLASH file %s\n",omp_get_thread_num(), omp_get_ancestor_thread_num(1), flash_file); fflush(fPtr); #pragma omp critical { readAndDecimate(flash_file, inj_radius, fps, &xPtr, &yPtr, &szxPtr, &szyPtr, &rPtr,\ &thetaPtr, &velxPtr, &velyPtr, &densPtr, &presPtr, &gammaPtr, &dens_labPtr, &tempPtr, &array_num, 1, min_r, max_r, fPtr); } } else { read_hydro(FILEPATH, frame, inj_radius, &xPtr, &yPtr, &zPtr, &szxPtr, &szyPtr, &rPtr,\ &thetaPtr, &phiPtr, &velxPtr, &velyPtr, &velzPtr, &densPtr, &presPtr, &gammaPtr, &dens_labPtr, &tempPtr, &array_num, 1, min_r, max_r, fps, fPtr); } //check for run type if(strcmp(cyl, this_run)==0) { //printf("In cylindrical prep\n"); cylindricalPrep(gammaPtr, velxPtr, velyPtr, densPtr, dens_labPtr, presPtr, tempPtr, array_num); } else if (strcmp(sph, this_run)==0) { sphericalPrep(rPtr, xPtr, yPtr,gammaPtr, velxPtr, velyPtr, densPtr, dens_labPtr, presPtr, tempPtr, array_num ); } //determine where to place photons and how many should go in a given place //for a checkpoint implmentation, dont need to inject photons, need to load photons' last saved data fprintf(fPtr,">> Thread: %d with ancestor %d: Injecting photons\n",omp_get_thread_num(), omp_get_ancestor_thread_num(1)); fflush(fPtr); if (dim_switch==0) { photonInjection(&phPtr, &num_ph, inj_radius, ph_weight_suggest, min_photons, max_photons,spect, array_num, fps, theta_jmin_thread, theta_jmax_thread, xPtr, yPtr, szxPtr, szyPtr,rPtr,thetaPtr, tempPtr, velxPtr, velyPtr,rng[omp_get_thread_num()] ); } else { photonInjection3D(&phPtr, &num_ph, inj_radius, ph_weight_suggest, min_photons, max_photons,spect, array_num, fps, theta_jmin_thread, theta_jmax_thread, xPtr, yPtr, zPtr, szxPtr, szyPtr,rPtr,thetaPtr, phiPtr, tempPtr, velxPtr, velyPtr, velzPtr, rng[omp_get_thread_num()] ); } //printf("%d\n",num_ph); //num_ph is one more photon than i actually have /* for (i=0;i<num_ph;i++) printf("%e,%e,%e \n",(phPtr+i)->r0, (phPtr+i)->r1, (phPtr+i)->r2 ); */ } //scatter photons all the way thoughout the jet //for a checkpoint implmentation, start from the last saved "scatt_frame" value eh start_frame=frame or start_frame=cont_frame if (restrt=='r') { scatt_framestart=frame; //have to make sure that once the inner loop is done and the outer loop is incrememnted by one the inner loop starts at that new value and not the one read by readCheckpoint() } for (scatt_frame=scatt_framestart;scatt_frame<=last_frm;scatt_frame++) { fprintf(fPtr,">>\n"); fprintf(fPtr,">> Thread %d with ancestor %d : Working on photons injected at frame: %d out of %d\n", omp_get_thread_num(), omp_get_ancestor_thread_num(1),frame, frm2); fprintf(fPtr,">> Thread %d with ancestor %d: %s - Working on frame %d\n",omp_get_thread_num(), omp_get_ancestor_thread_num(1), THISRUN, scatt_frame); fprintf(fPtr,">> Thread %d with ancestor %d: Opening file...\n", omp_get_thread_num(), omp_get_ancestor_thread_num(1)); fflush(fPtr); if (dim_switch==0) { //put proper number at the end of the flash file modifyFlashName(flash_file, flash_prefix, scatt_frame, dim_switch); #pragma omp critical { phMinMax(phPtr, num_ph, &min_r, &max_r); readAndDecimate(flash_file, inj_radius, fps, &xPtr, &yPtr, &szxPtr, &szyPtr, &rPtr,\ &thetaPtr, &velxPtr, &velyPtr, &densPtr, &presPtr, &gammaPtr, &dens_labPtr, &tempPtr, &array_num, 0, min_r, max_r, fPtr); } } else { phMinMax(phPtr, num_ph, &min_r, &max_r); read_hydro(FILEPATH, scatt_frame, inj_radius, &xPtr, &yPtr, &zPtr, &szxPtr, &szyPtr, &rPtr,\ &thetaPtr, &phiPtr, &velxPtr, &velyPtr, &velzPtr, &densPtr, &presPtr, &gammaPtr, &dens_labPtr, &tempPtr, &array_num, 0, min_r, max_r, fps, fPtr); } //check for run type if(strcmp(cyl, this_run)==0) { //printf("In cylindrical prep\n"); cylindricalPrep(gammaPtr, velxPtr, velyPtr, densPtr, dens_labPtr, presPtr, tempPtr, array_num); } else if (strcmp(sph, this_run)==0) { sphericalPrep(rPtr, xPtr, yPtr,gammaPtr, velxPtr, velyPtr, densPtr, dens_labPtr, presPtr, tempPtr, array_num ); } //printf("The result of read and decimate are arrays with %d elements\n", array_num); fprintf(fPtr,">> Thread %d with ancestor %d: propagating and scattering %d photons\n", omp_get_thread_num(), omp_get_ancestor_thread_num(1),num_ph); fflush(fPtr); frame_scatt_cnt=0; while (time_now<((scatt_frame+1)/fps)) { //if simulation time is less than the simulation time of the next frame, keep scattering in this frame //go through each photon and find blocks closest to each photon and properties of those blocks to calulate mean free path //and choose the photon with the smallest mfp and calculate the timestep ph_scatt_index=findNearestPropertiesAndMinMFP(phPtr, num_ph, array_num, &time_step, xPtr, yPtr, zPtr, velxPtr, velyPtr, velzPtr, dens_labPtr, tempPtr,\ &ph_dens_labPtr, &ph_vxPtr, &ph_vyPtr, &ph_vzPtr, &ph_tempPtr, rng[omp_get_thread_num()], dim_switch); //printf("In main: %e, %d, %e, %e\n", *(ph_num_scatt+ph_scatt_index), ph_scatt_index, time_step, time_now); printf("In main: %e, %d, %e, %e\n",((phPtr+ph_scatt_index)->num_scatt), ph_scatt_index, time_step, time_now); if (time_step<dt_max) { //update number of scatterings and time //(*(ph_num_scatt+ph_scatt_index))+=1; ((phPtr+ph_scatt_index)->num_scatt)+=1; frame_scatt_cnt+=1; time_now+=time_step; updatePhotonPosition(phPtr, num_ph, time_step); //scatter the photon //printf("Passed Parameters: %e, %e, %e\n", (ph_vxPtr), (ph_vyPtr), (ph_tempPtr)); photonScatter( (phPtr+ph_scatt_index), (ph_vxPtr), (ph_vyPtr), ph_vzPtr, (ph_tempPtr), rng[omp_get_thread_num()] , dim_switch, fPtr); //if (frame_scatt_cnt%1000 == 0) { fprintf(fPtr,"Scattering Number: %d\n", frame_scatt_cnt); fprintf(fPtr,"The local temp is: %e\n", (ph_tempPtr)); fprintf(fPtr,"Average photon energy is: %e\n", averagePhotonEnergy(phPtr, num_ph)); //write function to average over the photons p0 and then do (*3e10/1.6e-9) fflush(fPtr); } } else { time_now+=dt_max; //for each photon update its position based on its momentum updatePhotonPosition(phPtr, num_ph, dt_max); } //printf("In main 2: %e, %d, %e, %e\n", ((phPtr+ph_scatt_index)->num_scatt), ph_scatt_index, time_step, time_now); } //get scattering statistics phScattStats(phPtr, num_ph, &max_scatt, &min_scatt, &avg_scatt); fprintf(fPtr,"The number of scatterings in this frame is: %d\n", frame_scatt_cnt); fprintf(fPtr,"The last time step was: %lf.\nThe time now is: %lf\n", time_step,time_now); fprintf(fPtr,"The maximum number of scatterings for a photon is: %d\nThe minimum number of scattering for a photon is: %d\n", max_scatt, min_scatt); fprintf(fPtr,"The average number of scatterings thus far is: %lf\n", avg_scatt); fflush(fPtr); printPhotons(phPtr, num_ph, scatt_frame , frame, mc_dir); exit(0); //for a checkpoint implmentation,save the checkpoint file here after every 5 frames or something //save the photons data, the scattering number data, the scatt_frame value, and the frame value //WHAT IF THE PROGRAM STOPS AFTER THE LAST SCATT_FRAME, DURING THE FIRST SCATT_FRAME OF NEW FRAME VARIABLE - save restrt variable as 'r' fprintf(fPtr, ">> Thread %d with ancestor %d: Making checkpoint file\n", omp_get_thread_num(), omp_get_ancestor_thread_num(1)); fflush(fPtr); saveCheckpoint(mc_dir, frame, scatt_frame, num_ph, time_now, phPtr, last_frm); free(xPtr);free(yPtr);free(szxPtr);free(szyPtr);free(rPtr);free(thetaPtr);free(velxPtr);free(velyPtr);free(densPtr);free(presPtr); free(gammaPtr);free(dens_labPtr);free(tempPtr); xPtr=NULL; yPtr=NULL; rPtr=NULL;thetaPtr=NULL;velxPtr=NULL;velyPtr=NULL;densPtr=NULL;presPtr=NULL;gammaPtr=NULL;dens_labPtr=NULL; szxPtr=NULL; szyPtr=NULL; tempPtr=NULL; } restrt='r';//set this to make sure that the next iteration of propogating photons doesnt use the values from the last reading of the checkpoint file free(phPtr); phPtr=NULL; } }//end omp parallel inner section //merge files from each worker thread within a directory //dirFileMerge(mc_dir, frm0, last_frm); }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(num_thread) private(angle_count)<OMP-END>
lazzati-astro/MCRaT/OLDER_MCRaT_VERSIONS/mclib.c
#pragma omp parallel for num_threads(nt)
100
rng = (gsl_rng **) malloc((num_thread ) * sizeof(gsl_rng *)); rng[0]=rand; //<LOOP-START>for(i=1;i<num_thread;i++) { rng[i] = gsl_rng_alloc (rng_t); gsl_rng_set(rng[i],gsl_rng_get(rand)); }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(nt)<OMP-END>
lazzati-astro/MCRaT/OLDER_MCRaT_VERSIONS/mclib.c
#pragma omp parallel for num_threads(num_thread) firstprivate( ph_x, ph_y, ph_z, ph_phi, dist_min, dist, j, min_index, n_dens_lab_tmp,n_vx_tmp, n_vy_tmp, n_vz_tmp, n_temp_tmp, fl_v_x, fl_v_y, fl_v_z, fl_v_norm, ph_v_norm, n_cosangle, mfp, beta, rnd_tracker) private(i) shared(min_mfp )
100
mes the min (max) photon radius //or just parallelize this part here min_mfp=1e12; <LOOP-START>for (i=0;i<num_ph; i++) { //printf("%e,%e\n", ((ph+i)->r0), ((ph+i)->r1)); if (dim_switch_3d==0) { ph_x=pow(pow(((ph+i)->r0),2.0)+pow(((ph+i)->r1),2.0), 0.5); //convert back to FLASH x coordinate ph_y=((ph+i)->r2); } else { ph_x=((ph+i)->r0); ph_y=((ph+i)->r1); ph_z=((ph+i)->r2); } //printf("ph_x:%e, ph_y:%e\n", ph_x, ph_y); ph_phi=atan2(((ph+i)->r1), ((ph+i)->r0)); dist_min=1e12;//set dist to impossible value to make sure at least first distance calulated is saved block_dist=3e9; while (dist_min==1e12) //if this is true, then the algorithm hasnt found blocks within the acceptable range given by block_dist { for(j=0;j<array_num;j++) { //if the distance between them is within 3e9, to restrict number of possible calculations, calulate the total distance between the box and photon if ((dim_switch_3d==0) &&(fabs(ph_x- (*(x+j)))<block_dist) && (fabs(ph_y- (*(y+j)))<block_dist)) { //printf("In if statement\n"); dist= pow(pow(ph_x- (*(x+j)), 2.0) + pow(ph_y- (*(y+j)) , 2.0),0.5); //fprintf(fPtr,"Dist calculated as: %e, index: %d\n", dist, j); //printf("In outer if statement, OLD: %e, %d\n", dist_min, min_index); if((dist<dist_min)) { //printf("In innermost if statement, OLD: %e, %d\n", dist_min, min_index); dist_min=dist; //save new minimum distance min_index=j; //save index //fprintf(fPtr,"New Min dist: %e, New min Index: %d, Array_Num: %e\n", dist_min, min_index, array_num); } } else if ((dim_switch_3d==1) &&(fabs(ph_x- (*(x+j)))<block_dist) && (fabs(ph_y- (*(y+j)))<block_dist) && (fabs(ph_z- (*(z+j)))<block_dist)) { dist= pow(pow(ph_x- (*(x+j)), 2.0) + pow(ph_y- (*(y+j)),2.0 ) + pow(ph_z- (*(z+j)) , 2.0),0.5); if((dist<dist_min)) { //printf("In innermost if statement, OLD: %e, %d\n", dist_min, min_index); dist_min=dist; //save new minimum distance min_index=j; //save index //fprintf(fPtr,"New Min dist: %e, New min Index: %d, Array_Num: %e\n", dist_min, min_index, array_num); } } } block_dist*=10; //increase size of accepted distances for gris points, if dist_min==1e12 then the next time the acceptance range wil be larger } //save values /* *(n_dens_lab+i)= (*(dens_lab+min_index)); *(n_vx+i)= (*(velx+min_index)); *(n_vy+i)= (*(vely+min_index)); *(n_temp+i)= (*(temp+min_index)); */ (n_dens_lab_tmp)= (*(dens_lab+min_index)); (n_vx_tmp)= (*(velx+min_index)); (n_vy_tmp)= (*(vely+min_index)); (n_temp_tmp)= (*(temp+min_index)); if (dim_switch_3d==1) { (n_vz_tmp)= (*(velz+min_index)); } if (dim_switch_3d==0) { fl_v_x=(*(velx+min_index))*cos(ph_phi); fl_v_y=(*(velx+min_index))*sin(ph_phi); fl_v_z=(*(vely+min_index)); } else { fl_v_x=(*(velx+min_index)); fl_v_y=(*(vely+min_index)); fl_v_z=(*(velz+min_index)); } fl_v_norm=pow(pow(fl_v_x, 2.0)+pow(fl_v_y, 2.0)+pow(fl_v_z, 2.0), 0.5); ph_v_norm=pow(pow(((ph+i)->p1), 2.0)+pow(((ph+i)->p2), 2.0)+pow(((ph+i)->p3), 2.0), 0.5); //(*(n_cosangle+i))=((fl_v_x* ((ph+i)->p1))+(fl_v_y* ((ph+i)->p2))+(fl_v_z* ((ph+i)->p3)))/(fl_v_norm*ph_v_norm ); //find cosine of the angle between the photon and the fluid velocities via a dot product (n_cosangle)=((fl_v_x* ((ph+i)->p1))+(fl_v_y* ((ph+i)->p2))+(fl_v_z* ((ph+i)->p3)))/(fl_v_norm*ph_v_norm ); //make 1 for cylindrical otherwise its undefined if (dim_switch_3d==0) { beta=pow((pow((n_vx_tmp),2)+pow((n_vy_tmp),2)),0.5); } else { beta=pow((pow((n_vx_tmp),2)+pow((n_vy_tmp),2)+pow((n_vz_tmp),2)),0.5); } //put this in to double check that random number is between 0 and 1 (exclusive) because there was a problem with this for parallel case rnd_tracker=0; //while ((rnd_tracker<=0) || (rnd_tracker>=1)) //{ rnd_tracker=gsl_rng_uniform_pos(rng[omp_get_thread_num()]); //rnd_tracker=gsl_rng_uniform_pos(rand); //printf("Rnd_tracker: %e Thread number %d \n",rnd_tracker, omp_get_thread_num() ); //} mfp=(-1)*(M_P/((n_dens_lab_tmp))/THOMP_X_SECT/(1.0-beta*((n_cosangle))))*log(rnd_tracker) ; //calulate the mfp and then multiply it by the ln of a random number to simulate distribution of mean free paths //if (mfp<0) //{ //printf("\nThread: %d Photon: %d mfp: %e cos_angle: %e beta: %e dens_lab: %e rnd_tracker: %e\n\n",omp_get_thread_num(), i, mfp, n_cosangle , beta,n_dens_lab_tmp, rnd_tracker ); //} #pragma omp critical if ( mfp<min_mfp) { min_mfp=mfp; n_dens_lab_min= n_dens_lab_tmp; n_vx_min= n_vx_tmp; n_vy_min= n_vy_tmp; if (dim_switch_3d==1) { n_vz_min= n_vz_tmp; } n_temp_min= n_temp_tmp; index=i; printf("Thread is %d. new min: %e for photon %d with block properties: %e, %e, %e\n", omp_get_thread_num(), mfp, index, n_vx_tmp, n_vy_tmp, n_temp_tmp); //printf("Ancestor: %d Total Threads: %d\n", omp_get_num_threads(), omp_get_ancestor_thread_num(2)); #pragma omp flush(min_mfp) } }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(num_thread) firstprivate( ph_x, ph_y, ph_z, ph_phi, dist_min, dist, j, min_index, n_dens_lab_tmp,n_vx_tmp, n_vy_tmp, n_vz_tmp, n_temp_tmp, fl_v_x, fl_v_y, fl_v_z, fl_v_norm, ph_v_norm, n_cosangle, mfp, beta, rnd_tracker) private(i) shared(min_mfp ) <OMP-END>
lazzati-astro/MCRaT/OLDER_MCRaT_VERSIONS/PARALLELIZE/mclib.c
#pragma omp parallel for num_threads(nt)
100
)); //minus 1 because master thread already has rand initalized rng[0]=rand; //<LOOP-START>for(i=1;i<num_threads;i++) { rng[i] = gsl_rng_alloc (rng_t); gsl_rng_set(rng[i],gsl_rng_get(rand)); }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(nt)<OMP-END>
lazzati-astro/MCRaT/OLDER_MCRaT_VERSIONS/PARALLELIZE/mclib.c
#pragma omp parallel for firstprivate( ph_x, ph_y, ph_phi, dist_min, dist, j, min_index, n_dens_lab_tmp,n_vx_tmp, n_vy_tmp, n_temp_tmp, fl_v_x, fl_v_y, fl_v_z, fl_v_norm, ph_v_norm, n_cosangle, mfp, beta, rnd_tracker) private(i) shared(min_mfp )
100
n (max) photon radius //or just parallelize this part here min_mfp=1e12; <LOOP-START>for (i=0;i<num_ph; i++) { //printf("%e,%e\n", ((ph+i)->r0), ((ph+i)->r1)); ph_x=pow(pow(((ph+i)->r0),2.0)+pow(((ph+i)->r1),2.0), 0.5); //convert back to FLASH x coordinate ph_y=((ph+i)->r2); //printf("ph_x:%e, ph_y:%e\n", ph_x, ph_y); ph_phi=atan2(((ph+i)->r1), ((ph+i)->r0)); dist_min=1e12;//set dist to impossible value to make sure at least first distance calulated is saved for(j=0;j<array_num;j++) { //if the distance between them is within 3e9, to restrict number of possible calculations, calulate the total distance between the box and photon if ( (fabs(ph_x- (*(x+j)))<3e9) && (fabs(ph_y- (*(y+j)))<3e9)) { //printf("In if statement\n"); dist= pow(pow(ph_x- (*(x+j)), 2.0) + pow(ph_y- (*(y+j)) , 2.0),0.5); //printf("Dist calculated as: %e, index: %d\n", dist, j); //printf("In outer if statement, OLD: %e, %d\n", dist_min, min_index); if((dist<dist_min)) { //printf("In innermost if statement, OLD: %e, %d\n", dist_min, min_index); dist_min=dist; //save new minimum distance min_index=j; //save index //printf("New Min dist: %e, New min Index: %d\n", dist_min, min_index); } } } //save values /* *(n_dens_lab+i)= (*(dens_lab+min_index)); *(n_vx+i)= (*(velx+min_index)); *(n_vy+i)= (*(vely+min_index)); *(n_temp+i)= (*(temp+min_index)); */ (n_dens_lab_tmp)= (*(dens_lab+min_index)); (n_vx_tmp)= (*(velx+min_index)); (n_vy_tmp)= (*(vely+min_index)); (n_temp_tmp)= (*(temp+min_index)); fl_v_x=(*(velx+min_index))*cos(ph_phi); fl_v_y=(*(velx+min_index))*sin(ph_phi); fl_v_z=(*(vely+min_index)); fl_v_norm=pow(pow(fl_v_x, 2.0)+pow(fl_v_y, 2.0)+pow(fl_v_z, 2.0), 0.5); ph_v_norm=pow(pow(((ph+i)->p1), 2.0)+pow(((ph+i)->p2), 2.0)+pow(((ph+i)->p3), 2.0), 0.5); //(*(n_cosangle+i))=((fl_v_x* ((ph+i)->p1))+(fl_v_y* ((ph+i)->p2))+(fl_v_z* ((ph+i)->p3)))/(fl_v_norm*ph_v_norm ); //find cosine of the angle between the photon and the fluid velocities via a dot product (n_cosangle)=((fl_v_x* ((ph+i)->p1))+(fl_v_y* ((ph+i)->p2))+(fl_v_z* ((ph+i)->p3)))/(fl_v_norm*ph_v_norm ); //make 1 for cylindrical otherwise its undefined beta=pow((pow((n_vx_tmp),2)+pow((n_vy_tmp),2)),0.5); //put this in to double check that random number is between 0 and 1 (exclusive) because there was a problem with this for parallel case rnd_tracker=0; //while ((rnd_tracker<=0) || (rnd_tracker>=1)) //{ rnd_tracker=gsl_rng_uniform_pos(rng[omp_get_thread_num()]); //printf("Rnd_tracker: %e Thread number %d \n",rnd_tracker, omp_get_thread_num() ); //} mfp=(-1)*(M_P/((n_dens_lab_tmp))/THOMP_X_SECT/(1.0-beta*((n_cosangle))))*log(rnd_tracker) ; //calulate the mfp and then multiply it by the ln of a random number to simulate distribution of mean free paths //if (mfp<0) //{ //printf("\nThread: %d Photon: %d mfp: %e cos_angle: %e beta: %e dens_lab: %e rnd_tracker: %e\n\n",omp_get_thread_num(), i, mfp, n_cosangle , beta,n_dens_lab_tmp, rnd_tracker ); //} #pragma omp critical if ( mfp<min_mfp) { min_mfp=mfp; n_dens_lab_min= n_dens_lab_tmp; n_vx_min= n_vx_tmp; n_vy_min= n_vy_tmp; n_temp_min= n_temp_tmp; index=i; //printf("Thread is %d. new min: %e for photon %d with block properties: %e, %e, %e\n", omp_get_thread_num(), mfp, index, n_vx_tmp, n_vy_tmp, n_temp_tmp); #pragma omp flush(min_mfp) } }<LOOP-END> <OMP-START>#pragma omp parallel for firstprivate( ph_x, ph_y, ph_phi, dist_min, dist, j, min_index, n_dens_lab_tmp,n_vx_tmp, n_vy_tmp, n_temp_tmp, fl_v_x, fl_v_y, fl_v_z, fl_v_norm, ph_v_norm, n_cosangle, mfp, beta, rnd_tracker) private(i) shared(min_mfp )<OMP-END>
lazzati-astro/MCRaT/OLDER_MCRaT_VERSIONS/HYBRID_PARALLEL/mclib_3d.c
#pragma omp parallel for num_threads(num_thread) firstprivate(ph_r, ph_theta) reduction(min:temp_r_min) reduction(max:temp_r_max) reduction(min:temp_theta_min) reduction(max:temp_theta_max)
100
eta_min=DBL_MAX; int i=0, num_thread=omp_get_num_threads(); double ph_r=0, ph_theta=0; <LOOP-START>for (i=0;i<ph_num;i++) { if ((ph+i)->weight != 0) { ph_r=pow(pow( ((ph+i)->r0), 2.0) + pow(((ph+i)->r1),2.0 ) + pow(((ph+i)->r2) , 2.0),0.5); ph_theta=acos(((ph+i)->r2) /ph_r); //this is the photons theta psition in the FLASH grid, gives in radians if (ph_r > temp_r_max ) { temp_r_max=ph_r; //fprintf(fPtr, "The new max is: %e from photon %d with x: %e y: %e z: %e\n", temp_r_max, i, ((ph+i)->r0), (ph+i)->r1, (ph+i)->r2); } //if ((i==0) || (ph_r<temp_r_min)) if (ph_r<temp_r_min) { temp_r_min=ph_r; //fprintf(fPtr, "The new min is: %e from photon %d with x: %e y: %e z: %e\n", temp_r_min, i, ((ph+i)->r0), (ph+i)->r1, (ph+i)->r2); } if (ph_theta > temp_theta_max ) { temp_theta_max=ph_theta; //fprintf(fPtr, "The new max is: %e from photon %d with x: %e y: %e z: %e\n", temp_r_max, i, ((ph+i)->r0), (ph+i)->r1, (ph+i)->r2); } //if ((i==0) || (ph_r<temp_r_min)) if (ph_theta<temp_theta_min) { temp_theta_min=ph_theta; //fprintf(fPtr, "The new min is: %e from photon %d with x: %e y: %e z: %e\n", temp_r_min, i, ((ph+i)->r0), (ph+i)->r1, (ph+i)->r2); } } }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(num_thread) firstprivate(ph_r, ph_theta) reduction(min:temp_r_min) reduction(max:temp_r_max) reduction(min:temp_theta_min) reduction(max:temp_theta_max)<OMP-END>
lazzati-astro/MCRaT/OLDER_MCRaT_VERSIONS/HYBRID_PARALLEL/mclib.c
#pragma omp parallel for num_threads(nt)
100
rng = (gsl_rng **) malloc((num_thread ) * sizeof(gsl_rng *)); rng[0]=rand; //<LOOP-START>for(i=1;i<num_thread;i++) { rng[i] = gsl_rng_alloc (rng_t); gsl_rng_set(rng[i],gsl_rng_get(rand)); }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(nt)<OMP-END>
lazzati-astro/MCRaT/OLDER_MCRaT_VERSIONS/HYBRID_PARALLEL/mclib.c
#pragma omp parallel for num_threads(num_thread) firstprivate( is_in_block, ph_block_index, ph_r, ph_x, ph_y, ph_z, ph_phi, min_index, n_dens_lab_tmp,n_vx_tmp, n_vy_tmp, n_vz_tmp, n_temp_tmp, fl_v_x, fl_v_y, fl_v_z, fl_v_norm, ph_v_norm, n_cosangle, mfp, beta, rnd_tracker) private(i) shared(min_mfp )
100
parallelize this part here all_time_steps=malloc(num_ph*sizeof(double)); min_mfp=1e12; <LOOP-START>for (i=0;i<num_ph; i++) { //printf("%d, %e,%e\n", i, ((ph+i)->r0), ((ph+i)->r1)); if (find_nearest_block_switch==0) { ph_block_index=(ph+i)->nearest_block_index; //if starting a new frame the number of indexes can change and cause a seg fault } else { ph_block_index=0; //if starting a new frame set index=0 to avoid this issue } if (dim_switch_3d==0) { ph_x=pow(pow(((ph+i)->r0),2.0)+pow(((ph+i)->r1),2.0), 0.5); //convert back to FLASH x coordinate ph_y=((ph+i)->r2); ph_phi=atan2(((ph+i)->r1), ((ph+i)->r0)); ph_r=pow(ph_x*ph_x + ph_y*ph_y, 0.5); } else { ph_x=((ph+i)->r0); ph_y=((ph+i)->r1); ph_z=((ph+i)->r2); ph_r=pow(ph_x*ph_x + ph_y*ph_y+ph_z*ph_z, 0.5); } //if the location of the photon is less than the domain of the hydro simulation then do all of this, otherwise assing huge mfp value so no scattering occurs and the next frame is loaded if ((ph_y<hydro_domain_y) && (ph_x<hydro_domain_x)) { //printf("ph_x:%e, ph_y:%e\n", ph_x, ph_y); is_in_block=checkInBlock(ph_block_index, ph_x, ph_y, ph_z, x, y, z, szx, szy, dim_switch_3d, riken_switch); if (find_nearest_block_switch==0 && is_in_block) { //keep the saved grid index min_index=ph_block_index; } else { //find the new index of the block closest to the photon //min_index=findNearestBlock(array_num, ph_x, ph_y, ph_z, x, y, z, dim_switch_3d); //stop doing this one b/c nearest grid could be one that the photon isnt actually in due to adaptive mesh //find the new index of the block that the photon is actually in min_index=findContainingBlock(array_num, ph_x, ph_y, ph_z, x, y, z, szx, szy, dim_switch_3d, riken_switch, fPtr); (ph+i)->nearest_block_index=min_index; //save the index } //fprintf(fPtr,"Outside\n"); //save values (n_dens_lab_tmp)= (*(dens_lab+min_index)); (n_vx_tmp)= (*(velx+min_index)); (n_vy_tmp)= (*(vely+min_index)); (n_temp_tmp)= (*(temp+min_index)); if (dim_switch_3d==1) { (n_vz_tmp)= (*(velz+min_index)); } if (dim_switch_3d==0) { fl_v_x=(*(velx+min_index))*cos(ph_phi); fl_v_y=(*(velx+min_index))*sin(ph_phi); fl_v_z=(*(vely+min_index)); } else { fl_v_x=(*(velx+min_index)); fl_v_y=(*(vely+min_index)); fl_v_z=(*(velz+min_index)); } fl_v_norm=pow(pow(fl_v_x, 2.0)+pow(fl_v_y, 2.0)+pow(fl_v_z, 2.0), 0.5); ph_v_norm=pow(pow(((ph+i)->p1), 2.0)+pow(((ph+i)->p2), 2.0)+pow(((ph+i)->p3), 2.0), 0.5); //(*(n_cosangle+i))=((fl_v_x* ((ph+i)->p1))+(fl_v_y* ((ph+i)->p2))+(fl_v_z* ((ph+i)->p3)))/(fl_v_norm*ph_v_norm ); //find cosine of the angle between the photon and the fluid velocities via a dot product (n_cosangle)=((fl_v_x* ((ph+i)->p1))+(fl_v_y* ((ph+i)->p2))+(fl_v_z* ((ph+i)->p3)))/(fl_v_norm*ph_v_norm ); //make 1 for cylindrical otherwise its undefined if (dim_switch_3d==0) { beta=pow((pow((n_vx_tmp),2)+pow((n_vy_tmp),2)),0.5); } else { beta=pow((pow((n_vx_tmp),2)+pow((n_vy_tmp),2)+pow((n_vz_tmp),2)),0.5); } //put this in to double check that random number is between 0 and 1 (exclusive) because there was a problem with this for parallel case rnd_tracker=0; rnd_tracker=gsl_rng_uniform_pos(rng[omp_get_thread_num()]); //printf("Rnd_tracker: %e Thread number %d \n",rnd_tracker, omp_get_thread_num() ); mfp=(-1)*(M_P/((n_dens_lab_tmp))/THOMP_X_SECT/(1.0-beta*((n_cosangle))))*log(rnd_tracker) ; //calulate the mfp and then multiply it by the ln of a random number to simulate distribution of mean free paths } else { mfp=min_mfp; //printf("In ELSE\n"); } *(all_time_steps+i)=mfp/C_LIGHT; }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(num_thread) firstprivate( is_in_block, ph_block_index, ph_r, ph_x, ph_y, ph_z, ph_phi, min_index, n_dens_lab_tmp,n_vx_tmp, n_vy_tmp, n_vz_tmp, n_temp_tmp, fl_v_x, fl_v_y, fl_v_z, fl_v_norm, ph_v_norm, n_cosangle, mfp, beta, rnd_tracker) private(i) shared(min_mfp )<OMP-END>
lazzati-astro/MCRaT/OLDER_MCRaT_VERSIONS/HYBRID_PARALLEL/mclib.c
#pragma omp parallel for num_threads(nt)
100
rng = (gsl_rng **) malloc((num_thread ) * sizeof(gsl_rng *)); rng[0]=rand; //<LOOP-START>for(i=1;i<num_thread;i++) { rng[i] = gsl_rng_alloc (rng_t); gsl_rng_set(rng[i],gsl_rng_get(rand)); }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(nt)<OMP-END>
lazzati-astro/MCRaT/OLDER_MCRaT_VERSIONS/HYBRID_PARALLEL/mclib.c
#pragma omp parallel for num_threads(num_thread) firstprivate( r, theta,dv, v, all_adjacent_block_indexes, j, left_block_index, right_block_index, top_block_index, bottom_block_index, is_in_block, ph_block_index, ph_x, ph_y, ph_z, ph_phi, min_index, n_dens_lab_tmp,n_vx_tmp, n_vy_tmp, n_vz_tmp, n_temp_tmp, fl_v_x, fl_v_y, fl_v_z, fl_v_norm, ph_v_norm, n_cosangle, mfp, beta, rnd_tracker) private(i) shared(min_mfp )
100
mes the min (max) photon radius //or just parallelize this part here min_mfp=1e12; <LOOP-START>for (i=0;i<num_ph; i++) { //printf("%d, %e,%e\n", i, ((ph+i)->r0), ((ph+i)->r1)); if (find_nearest_block_switch==0) { ph_block_index=(ph+i)->nearest_block_index; //if starting a new frame the number of indexes can change and cause a seg fault } else { ph_block_index=0; //if starting a new frame set index=0 to avoid this issue } if (dim_switch_3d==0) { ph_x=pow(pow(((ph+i)->r0),2.0)+pow(((ph+i)->r1),2.0), 0.5); //convert back to FLASH x coordinate ph_y=((ph+i)->r2); ph_phi=atan2(((ph+i)->r1), ((ph+i)->r0)); } else { ph_x=((ph+i)->r0); ph_y=((ph+i)->r1); ph_z=((ph+i)->r2); } //printf("ph_x:%e, ph_y:%e\n", ph_x, ph_y); is_in_block=checkInBlock(ph_block_index, ph_x, ph_y, ph_z, x, y, z, szx, szy, dim_switch_3d, riken_switch); if (find_nearest_block_switch==0 && is_in_block) { //keep the saved grid index min_index=ph_block_index; } else { //find the new index of the block closest to the photon //min_index=findNearestBlock(array_num, ph_x, ph_y, ph_z, x, y, z, dim_switch_3d); //stop doing this one b/c nearest grid could be one that the photon isnt actually in due to adaptive mesh //find the new index of the block that the photon is actually in min_index=findContainingBlock(array_num, ph_x, ph_y, ph_z, x, y, z, szx, szy, dim_switch_3d, riken_switch, fPtr); (ph+i)->nearest_block_index=min_index; //save the index } //look for the blocks surounding the block of interest and order them by the left_dist_min=1e15;//set dist to impossible value to make sure at least first distance calulated is saved right_dist_min=1e15; top_dist_min=1e15; bottom_dist_min=1e15; for (j=0;j<array_num;j++) { if ((dim_switch_3d==0)) { dist= pow(pow((*(x+min_index))- (*(x+j)), 2.0) + pow((*(y+min_index))- (*(y+j)) , 2.0),0.5); } else { dist= pow(pow((*(x+min_index))- (*(x+j)), 2.0) + pow((*(y+min_index))- (*(y+j)),2.0 ) + pow((*(z+min_index))- (*(z+j)) , 2.0),0.5); } if ((*(x+j))<(*(x+min_index)) && (dist < left_dist_min) ) { left_block_index=j; left_dist_min=dist; } else if ((*(x+j))>(*(x+min_index)) && (dist < right_dist_min)) { right_block_index=j; right_dist_min=dist; } if ((*(y+j))<(*(y+min_index)) && (dist < bottom_dist_min) ) { bottom_block_index=j; bottom_dist_min=dist; } else if ((*(y+j))>(*(y+min_index)) && (dist < top_dist_min) ) { top_block_index=j; top_dist_min=dist; } } all_adjacent_block_indexes[0]=left_block_index; all_adjacent_block_indexes[1]=right_block_index; all_adjacent_block_indexes[2]=bottom_block_index; all_adjacent_block_indexes[3]=top_block_index; //do a weighted average of the 4 nearest grids based on volume v=0; (n_dens_lab_tmp)=0; (n_vx_tmp)= 0; (n_vy_tmp)= 0; (n_temp_tmp)= 0; (n_vz_tmp)= 0; for (j=0;j<4;j++) { if (riken_switch==0) { //using FLASH dv=2.0*M_PI*(*(x+all_adjacent_block_indexes[j]))*pow(*(szx+all_adjacent_block_indexes[j]),2.0) ; } else { r=pow(pow((*(x+all_adjacent_block_indexes[j])),2.0)+pow((*(y+all_adjacent_block_indexes[j])),2.0), 0.5); theta=atan2((*(x+all_adjacent_block_indexes[j])), (*(y+all_adjacent_block_indexes[j]))); dv=2.0*M_PI*pow(r,2)*sin(theta)*(*(szx+all_adjacent_block_indexes[j]))*(*(szy+all_adjacent_block_indexes[j])) ; } v+=dv; //save values (n_dens_lab_tmp)+= (*(dens_lab+all_adjacent_block_indexes[j]))*dv; (n_vx_tmp)+= (*(velx+all_adjacent_block_indexes[j]))*dv; (n_vy_tmp)+= (*(vely+all_adjacent_block_indexes[j]))*dv; (n_temp_tmp)+= (*(temp+all_adjacent_block_indexes[j]))*dv; if (dim_switch_3d==1) { (n_vz_tmp)+= (*(velz+all_adjacent_block_indexes[j]))*dv; } } //fprintf(fPtr,"Outside\n"); //save values (n_dens_lab_tmp)/= v; (n_vx_tmp)/= v; (n_vy_tmp)/= v; (n_temp_tmp)/= v; if (dim_switch_3d==1) { (n_vz_tmp)/= v; } if (dim_switch_3d==0) { fl_v_x=n_vx_tmp*cos(ph_phi); fl_v_y=n_vx_tmp*sin(ph_phi); fl_v_z=n_vy_tmp; } else { fl_v_x=n_vx_tmp; fl_v_y=n_vy_tmp; fl_v_z=n_vz_tmp; } fl_v_norm=pow(pow(fl_v_x, 2.0)+pow(fl_v_y, 2.0)+pow(fl_v_z, 2.0), 0.5); ph_v_norm=pow(pow(((ph+i)->p1), 2.0)+pow(((ph+i)->p2), 2.0)+pow(((ph+i)->p3), 2.0), 0.5); //(*(n_cosangle+i))=((fl_v_x* ((ph+i)->p1))+(fl_v_y* ((ph+i)->p2))+(fl_v_z* ((ph+i)->p3)))/(fl_v_norm*ph_v_norm ); //find cosine of the angle between the photon and the fluid velocities via a dot product (n_cosangle)=((fl_v_x* ((ph+i)->p1))+(fl_v_y* ((ph+i)->p2))+(fl_v_z* ((ph+i)->p3)))/(fl_v_norm*ph_v_norm ); //make 1 for cylindrical otherwise its undefined if (dim_switch_3d==0) { beta=pow((pow((n_vx_tmp),2)+pow((n_vy_tmp),2)),0.5); } else { beta=pow((pow((n_vx_tmp),2)+pow((n_vy_tmp),2)+pow((n_vz_tmp),2)),0.5); } //put this in to double check that random number is between 0 and 1 (exclusive) because there was a problem with this for parallel case rnd_tracker=0; rnd_tracker=gsl_rng_uniform_pos(rng[omp_get_thread_num()]); mfp=(-1)*(M_P/((n_dens_lab_tmp))/THOMP_X_SECT/(1.0-beta*((n_cosangle))))*log(rnd_tracker) ; //calulate the mfp and then multiply it by the ln of a random number to simulate distribution of mean free paths #pragma omp critical if ( mfp<min_mfp) { min_mfp=mfp; n_dens_lab_min= n_dens_lab_tmp; n_vx_min= n_vx_tmp; n_vy_min= n_vy_tmp; if (dim_switch_3d==1) { n_vz_min= n_vz_tmp; } n_temp_min= n_temp_tmp; index=i; //fprintf(fPtr, "Thread is %d. new min: %e for photon %d with block properties: %e, %e, %e Located at: %e, %e, Dist: %e\n", omp_get_thread_num(), mfp, index, n_vx_tmp, n_vy_tmp, n_temp_tmp, *(x+min_index), *(y+min_index), dist_min); //fflush(fPtr); #pragma omp flush(min_mfp) } }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(num_thread) firstprivate( r, theta,dv, v, all_adjacent_block_indexes, j, left_block_index, right_block_index, top_block_index, bottom_block_index, is_in_block, ph_block_index, ph_x, ph_y, ph_z, ph_phi, min_index, n_dens_lab_tmp,n_vx_tmp, n_vy_tmp, n_vz_tmp, n_temp_tmp, fl_v_x, fl_v_y, fl_v_z, fl_v_norm, ph_v_norm, n_cosangle, mfp, beta, rnd_tracker) private(i) shared(min_mfp )<OMP-END>
lazzati-astro/MCRaT/OLDER_MCRaT_VERSIONS/HYBRID_PARALLEL/mclib.c
#pragma omp parallel for num_threads(num_thread) firstprivate(old_position, new_position, divide_p0)
100
thread=omp_get_num_threads(); double old_position=0, new_position=0, divide_p0=0; <LOOP-START>for (i=0;i<num_ph;i++) { old_position= pow( pow(ph->r0,2)+pow(ph->r1,2)+pow(ph->r2,2), 0.5 ); divide_p0=1.0/((ph+i)->p0); ((ph+i)->r0)+=((ph+i)->p1)*divide_p0*C_LIGHT*t; //update x position ((ph+i)->r1)+=((ph+i)->p2)*divide_p0*C_LIGHT*t;//update y ((ph+i)->r2)+=((ph+i)->p3)*divide_p0*C_LIGHT*t;//update z new_position= pow( pow(ph->r0,2)+pow(ph->r1,2)+pow(ph->r2,2), 0.5 ); if ((new_position-old_position)/t > C_LIGHT) { fprintf(fPtr, "PHOTON NUMBER %d IS SUPERLUMINAL. ITS SPEED IS %e c.\n", i, ((new_position-old_position)/t)/C_LIGHT); } //printf("In update function: %e, %e, %e, %e, %e, %e, %e\n",((ph+i)->r0), ((ph+i)->r1), ((ph+i)->r2), t, ((ph+i)->p1)/((ph+i)->p0), ((ph+i)->p2)/((ph+i)->p0), ((ph+i)->p3)/((ph+i)->p0) ); }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(num_thread) firstprivate(old_position, new_position, divide_p0)<OMP-END>
lazzati-astro/MCRaT/OLDER_MCRaT_VERSIONS/HYBRID_PARALLEL/mclib.c
#pragma omp parallel for num_threads(num_thread) firstprivate( filename_k, file_no_thread_num, cmd,mcdata_type,num_files, increment ) private(i,j,k)
100
000]="", cmd[2000]="", mcdata_type[200]=""; //printf("Merging files in %s\n", dir); //<LOOP-START>// i < last frame because calculation before this function gives last_frame as the first frame of the next process set of frames to merge files for for (i=start_frame;i<last_frame;i=i+increment) { fprintf(fPtr, "Merging files for frame: %d\n", i); fflush(fPtr); if ((riken_switch==1) && (dim_switch==1) && (i>=3000)) { increment=10; //when the frame ==3000 for RIKEN 3D hydro files, increment file numbers by 10 instead of by 1 } for (j=0;j<num_files;j=j+1) { switch (j) { case 0: snprintf(mcdata_type,sizeof(mcdata_type), "%s", "P0"); break; case 1: snprintf(mcdata_type,sizeof(mcdata_type), "%s", "P1");break; case 2: snprintf(mcdata_type,sizeof(mcdata_type), "%s", "P2"); break; case 3: snprintf(mcdata_type,sizeof(mcdata_type), "%s", "P3"); break; case 4: snprintf(mcdata_type,sizeof(mcdata_type), "%s", "R0"); break; case 5: snprintf(mcdata_type,sizeof(mcdata_type), "%s", "R1"); break; case 6: snprintf(mcdata_type,sizeof(mcdata_type), "%s", "R2"); break; case 7: snprintf(mcdata_type,sizeof(mcdata_type), "%s", "NS"); break; } for (k=0;k<numprocs;k++) { snprintf(file_no_thread_num,sizeof(file_no_thread_num),"%s%s%d%s%s%s", dir,"mcdata_",i,"_", mcdata_type,".dat"); snprintf(filename_k,sizeof(filename_k),"%s%s%d%s%s%s%d%s", dir,"mcdata_",i,"_", mcdata_type ,"_",k, ".dat"); //check if both the file exists if (( access( filename_k, F_OK ) != -1 ) ) { //if they both do make command to cat the together always in the same order //fprintf(fPtr, "Merging: %s\n", filename_k); snprintf(cmd, sizeof(cmd), "%s%s %s%s", "cat ", filename_k, " >> ", file_no_thread_num); system(cmd); } //remove file snprintf(cmd, sizeof(cmd), "%s%s", "rm ", filename_k); system(cmd); } } }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(num_thread) firstprivate( filename_k, file_no_thread_num, cmd,mcdata_type,num_files, increment ) private(i,j,k)<OMP-END>
lazzati-astro/MCRaT/Src/mc_cyclosynch.c
#pragma omp parallel for num_threads(num_thread) reduction(+:block_cnt)
100
fprintf(fPtr, "rmin %e rmax %e, theta min/max: %e %e\n", rmin, rmax, theta_min, theta_max); <LOOP-START>for(i=0;i<hydro_data->num_elements;i++) { //look at all boxes in width delta r=c/fps and within angles we are interested in NEED TO IMPLEMENT #if DIMENSIONS == THREE //want inner corner to be close to origin, therfore ned to have abs for 3D cartesian with negative coordinates, shouldnt affect the other geometry systems since theyre all defined from r=0, theta=0, phi=0 hydroCoordinateToSpherical(&r_grid_innercorner, &theta_grid_innercorner, fabs((hydro_data->r0)[i])-0.5*(hydro_data->r0_size)[i], fabs((hydro_data->r1)[i])-0.5*(hydro_data->r1_size)[i], fabs((hydro_data->r2)[i])-0.5*(hydro_data->r2_size)[i]); hydroCoordinateToSpherical(&r_grid_outercorner, &theta_grid_outercorner, fabs((hydro_data->r0)[i])+0.5*(hydro_data->r0_size)[i], fabs((hydro_data->r1)[i])+0.5*(hydro_data->r1_size)[i], fabs((hydro_data->r2)[i])+0.5*(hydro_data->r2_size)[i]); #else hydroCoordinateToSpherical(&r_grid_innercorner, &theta_grid_innercorner, (hydro_data->r0)[i]-0.5*(hydro_data->r0_size)[i], (hydro_data->r1)[i]-0.5*(hydro_data->r1_size)[i], 0); hydroCoordinateToSpherical(&r_grid_outercorner, &theta_grid_outercorner, (hydro_data->r0)[i]+0.5*(hydro_data->r0_size)[i], (hydro_data->r1)[i]+0.5*(hydro_data->r1_size)[i], 0); if ((rmin <= r_grid_outercorner) && (r_grid_innercorner < rmax ) && (theta_grid_outercorner >= theta_min) && (theta_grid_innercorner < theta_max)) { block_cnt+=1; } }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(num_thread) reduction(+:block_cnt)<OMP-END>
lazzati-astro/MCRaT/Src/mc_cyclosynch.c
#pragma omp parallel for num_threads(num_thread) reduction(+:null_ph_count)
100
IER INDEXES AND HOW MANY, dont subtract this from ph_tot @ the end, WILL NEED FOR PRINT PHOTONS <LOOP-START>for (i=0;i<*num_ph;i++) { if (((*ph_orig)[i].weight == 0)) //if photons are null COMPTONIZED_PHOTON photons and not absorbed UNABSORBED_CS_PHOTON photons { null_ph_count+=1; } }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(num_thread) reduction(+:null_ph_count)<OMP-END>
lazzati-astro/MCRaT/Src/mc_cyclosynch.c
#pragma omp parallel for num_threads(num_thread) firstprivate(b_field, el_dens, nu_c) reduction(+:abs_ph_count)
100
h=0;//set thsi equal to 0, to recount in this function and get prepared for the next frame <LOOP-START>for (i=0;i<*num_ph;i++) { if (((*ph_orig)[i].weight != 0) && ((*ph_orig)[i].nearest_block_index != -1)) { // if the photon isnt a null photon already, see if it should be absorbed el_dens= (hydro_data->dens)[(*ph_orig)[i].nearest_block_index]/M_P;//(*(dens+(*ph_orig)[i].nearest_block_index))/M_P; #if B_FIELD_CALC == TOTAL_E || B_FIELD_CALC == INTERNAL_E b_field=calcB(el_dens,(hydro_data->temp)[(*ph_orig)[i].nearest_block_index]); #else #if DIMENSIONS == TWO b_field=vectorMagnitude((hydro_data->B0)[(*ph_orig)[i].nearest_block_index], (hydro_data->B1)[(*ph_orig)[i].nearest_block_index], 0); #else b_field=vectorMagnitude((hydro_data->B0)[(*ph_orig)[i].nearest_block_index], (hydro_data->B1)[(*ph_orig)[i].nearest_block_index], (hydro_data->B2)[(*ph_orig)[i].nearest_block_index]); nu_c=calcCyclotronFreq(b_field); //nu_c=calcCyclotronFreq(calcB(el_dens, (hydro_data->temp)[(*ph_orig)[i].nearest_block_index])); old way //*(temp+(*ph_orig)[i].nearest_block_index))); //printf("photon %d has lab nu %e comv frequency %e and nu_c %e with FLASH grid number %d\n", i, (*ph_orig)[i].p0*C_LIGHT/PL_CONST, (*ph_orig)[i].comv_p0*C_LIGHT/PL_CONST, nu_c, (*ph_orig)[i].nearest_block_index); if (((*ph_orig)[i].comv_p0*C_LIGHT/PL_CONST <= nu_c) || ((*ph_orig)[i].type == CS_POOL_PHOTON)) { //if the photon has a frequency less that nu_c, it should be absorbed and becomes a null photon //preset values for the the newly created spots to hold the emitted phtoons in; //if this is a synchrotron photons or photons that have been scattered that were once synch photons in this frame //fprintf(fPtr,"photon %d being absorbed\n", i); if (((*ph_orig)[i].type != INJECTED_PHOTON) && ((*ph_orig)[i].type != UNABSORBED_CS_PHOTON) ) { (*ph_orig)[i].weight=0; (*ph_orig)[i].nearest_block_index=-1; abs_ph_count++; if ((*ph_orig)[i].type == CS_POOL_PHOTON) { synch_ph_count++; } } else { //have an injected photon or UNABSORBED_CS_PHOTON (previous COMPTONIZED_PHOTON photon) that has a nu that can be absorbed abs_count+=(*ph_orig)[i].weight; (*ph_orig)[i].p0=-1; //set its energy negative so we know for later analysis that it can't be used and its been absorbed, (*ph_orig)[i].nearest_block_index=-1; //also set the weight equal to 0 since we no longer care about saving it (*ph_orig)[i].weight=0; abs_ph_count++; } } else { //if the phootn isnt going to be absorbed, see if its a COMPTONIZED_PHOTON photon thats survived and change it to an injected type //replace the potantial null photon with this photon's data (*ph_orig)[count].p0=(*ph_orig)[i].p0; (*ph_orig)[count].p1=(*ph_orig)[i].p1; (*ph_orig)[count].p2=(*ph_orig)[i].p2; (*ph_orig)[count].p3=(*ph_orig)[i].p3; (*ph_orig)[count].comv_p0=(*ph_orig)[i].comv_p0; (*ph_orig)[count].comv_p1=(*ph_orig)[i].comv_p1; (*ph_orig)[count].comv_p2=(*ph_orig)[i].comv_p2; (*ph_orig)[count].comv_p3=(*ph_orig)[i].comv_p3; (*ph_orig)[count].r0= (*ph_orig)[i].r0; (*ph_orig)[count].r1=(*ph_orig)[i].r1 ; (*ph_orig)[count].r2=(*ph_orig)[i].r2; (*ph_orig)[count].s0=(*ph_orig)[i].s0; (*ph_orig)[count].s1=(*ph_orig)[i].s1; (*ph_orig)[count].s2=(*ph_orig)[i].s2; (*ph_orig)[count].s3=(*ph_orig)[i].s3; (*ph_orig)[count].num_scatt=(*ph_orig)[i].num_scatt; (*ph_orig)[count].weight=(*ph_orig)[i].weight; (*ph_orig)[count].nearest_block_index=(*ph_orig)[i].nearest_block_index; (*ph_orig)[count].type=(*ph_orig)[i].type; //increment count count+=1; if (((*ph_orig)[i].type == COMPTONIZED_PHOTON) || ((*ph_orig)[i].type == UNABSORBED_CS_PHOTON) ) { //if the photon is a COMPTONIZED_PHOTON phton (scattered synch photon from the current frame) or a UNABSORBED_CS_PHOTON photon (scattered synch photon) from an old frame //count how many of these there are *scatt_cyclosynch_num_ph+=1; } } } else { //see if the photon was a previous INJECTED_PHOTON photon absorbed that we still have to account for in the array if (((*ph_orig)[i].p0 < 0) ) { //replace the potantial null photon with this photon's data (*ph_orig)[count].p0=(*ph_orig)[i].p0; (*ph_orig)[count].p1=(*ph_orig)[i].p1; (*ph_orig)[count].p2=(*ph_orig)[i].p2; (*ph_orig)[count].p3=(*ph_orig)[i].p3; (*ph_orig)[count].comv_p0=(*ph_orig)[i].comv_p0; (*ph_orig)[count].comv_p1=(*ph_orig)[i].comv_p1; (*ph_orig)[count].comv_p2=(*ph_orig)[i].comv_p2; (*ph_orig)[count].comv_p3=(*ph_orig)[i].comv_p3; (*ph_orig)[count].r0= (*ph_orig)[i].r0; (*ph_orig)[count].r1=(*ph_orig)[i].r1 ; (*ph_orig)[count].r2=(*ph_orig)[i].r2; (*ph_orig)[count].s0=(*ph_orig)[i].s0; (*ph_orig)[count].s1=(*ph_orig)[i].s1; (*ph_orig)[count].s2=(*ph_orig)[i].s2; (*ph_orig)[count].s3=(*ph_orig)[i].s3; (*ph_orig)[count].num_scatt=(*ph_orig)[i].num_scatt; (*ph_orig)[count].weight=(*ph_orig)[i].weight; (*ph_orig)[count].nearest_block_index=(*ph_orig)[i].nearest_block_index; (*ph_orig)[count].type=(*ph_orig)[i].type; //increment count count+=1; } } //fprintf(fPtr, "photon %d has energy %e and weight %e with FLASH grid number %d\n", i, (*ph_orig)[i].p0*C_LIGHT/1.6e-9, (*ph_orig)[i].weight, (*ph_orig)[i].nearest_block_index); }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(num_thread) firstprivate(b_field, el_dens, nu_c) reduction(+:abs_ph_count)<OMP-END>
lazzati-astro/MCRaT/Src/mcrat_io.c
#pragma omp parallel for num_threads(num_thread) reduction(+:weight_net_num_ph)
100
BOVE count=0;//used to keep track of weight values since it may not be the same as num_ph //<LOOP-START>for (i=0;i<num_ph;i++) { if ((ph+i)->weight != 0) { p0[count]= ((ph+i)->p0); p1[count]= ((ph+i)->p1); p2[count]= ((ph+i)->p2); p3[count]= ((ph+i)->p3); r0[count]= ((ph+i)->r0); r1[count]= ((ph+i)->r1); r2[count]= ((ph+i)->r2); #if COMV_SWITCH == ON { comv_p0[count]= ((ph+i)->comv_p0); comv_p1[count]= ((ph+i)->comv_p1); comv_p2[count]= ((ph+i)->comv_p2); comv_p3[count]= ((ph+i)->comv_p3); } #if STOKES_SWITCH == ON { s0[count]= ((ph+i)->s0); s1[count]= ((ph+i)->s1); s2[count]= ((ph+i)->s2); s3[count]= ((ph+i)->s3); } num_scatt[count]= ((ph+i)->num_scatt); weight[count]= ((ph+i)->weight); //fprintf(fPtr, "%d %c %e %e %e %e %e %e %e %e\n", i, (ph+i)->type, (ph+i)->r0, (ph+i)->r1, (ph+i)->r2, (ph+i)->num_scatt, (ph+i)->weight, (ph+i)->p0, (ph+i)->comv_p0, (ph+i)->p0*C_LIGHT/1.6e-9); if ((frame==frame_last)) { global_weight[count]=((ph+i)->weight); } *(ph_type+count)=(ph+i)->type; //printf("%d %c %e %e %e %e %e %e %e %e %c\n", i, (ph+i)->type, (ph+i)->r0, (ph+i)->r1, (ph+i)->r2, (ph+i)->num_scatt, (ph+i)->weight, (ph+i)->p0, (ph+i)->comv_p0, (ph+i)->p0*C_LIGHT/1.6e-9, *(ph_type+count)); count++; } }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(num_thread) reduction(+:weight_net_num_ph)<OMP-END>
lazzati-astro/MCRaT/Src/mcrat_io.c
#pragma omp parallel for num_threads(num_thread) firstprivate( filename_k, file_no_thread_num, cmd,mcdata_type,num_files, increment ) private(i,j,k)
100
dset_weight, dset_weight_frame, dset_ph_type; //printf("Merging files in %s\n", dir); //<LOOP-START>// i < last frame because calculation before this function gives last_frame as the first frame of the next process set of frames to merge files for #if COMV_SWITCH == ON && STOKES_SWITCH == ON { num_types=17;//both switches on, want to save comv and stokes }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(num_thread) firstprivate( filename_k, file_no_thread_num, cmd,mcdata_type,num_files, increment ) private(i,j,k)<OMP-END>
lazzati-astro/MCRaT/Src/mclib.c
#pragma omp parallel for num_threads(nt)
100
xs0; rng = (gsl_rng **) malloc((num_thread ) * sizeof(gsl_rng *)); rng[0]=rand; //<LOOP-START>for(i=1;i<num_thread;i++) { rng[i] = gsl_rng_alloc (rng_t); gsl_rng_set(rng[i],gsl_rng_get(rand)); }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(nt)<OMP-END>
lazzati-astro/MCRaT/Src/mclib.c
#pragma omp parallel for num_threads(num_thread) firstprivate( is_in_block, ph_block_index, ph_x, ph_y, ph_z, ph_phi, ph_r, min_index, n_dens_lab_tmp,n_vx_tmp, n_vy_tmp, n_vz_tmp, n_temp_tmp, fl_v_x, fl_v_y, fl_v_z, fl_v_norm, ph_v_norm, n_cosangle, mfp, beta, rnd_tracker, ph_p_comv, el_p, ph_p, fluid_beta) private(i) shared(min_mfp ) reduction(+:num_photons_find_new_element)
100
mes the min (max) photon radius //or just parallelize this part here min_mfp=1e12; <LOOP-START>for (i=0;i<num_ph; i++) { //fprintf(fPtr, "%d, %d,%e\n", i, ((ph+i)->nearest_block_index), ((ph+i)->weight)); //fflush(fPtr); if (find_nearest_block_switch==0) { ph_block_index=(ph+i)->nearest_block_index; //if starting a new frame the number of indexes can change and cause a seg fault here } else { ph_block_index=0; // therefore if starting a new frame set index=0 to avoid this issue } mcratCoordinateToHydroCoordinate(&photon_hydro_coord, (ph+i)->r0, (ph+i)->r1, (ph+i)->r2);//convert the photons coordinate to the hydro sim coordinate system //printf("ph_x:%e, ph_y:%e\n", ph_x, ph_y); //if the location of the photon is inside the domain of the hydro simulation then do all of this, otherwise assign huge mfp value so no scattering occurs and the next frame is loaded // absorbed photons have ph_block_index=-1, therefore if this value is not less than 0, calulate the mfp properly but doesnt work when go to new frame and find new indexes (will change b/c will get rid of these photons when printing) //alternatively make decision based on 0 weight #if DIMENSIONS == TWO || DIMENSIONS == TWO_POINT_FIVE if (((photon_hydro_coord[1]<(hydro_data->r1_domain)[1]) && (photon_hydro_coord[1]>(hydro_data->r1_domain)[0]) && (photon_hydro_coord[0]<(hydro_data->r0_domain)[1]) && (photon_hydro_coord[0]>(hydro_data->r0_domain)[0])) && ((ph+i)->nearest_block_index != -1) ) //can use sorted index to see which photons have been absorbed efficiently before printing and get the indexes #else if (((photon_hydro_coord[2]<(hydro_data->r2_domain)[1]) && (photon_hydro_coord[2]>(hydro_data->r2_domain)[0]) && (photon_hydro_coord[1]<(hydro_data->r1_domain)[1]) && (photon_hydro_coord[1]>(hydro_data->r1_domain)[0]) && (photon_hydro_coord[0]<(hydro_data->r0_domain)[1]) && (photon_hydro_coord[0]>(hydro_data->r0_domain)[0])) && ((ph+i)->nearest_block_index != -1) ) { is_in_block=checkInBlock(photon_hydro_coord[0], photon_hydro_coord[1], photon_hydro_coord[2], hydro_data, ph_block_index); //when rebinning photons can have comoving 4 momenta=0 and nearest_block_index=0 (and block 0 be the actual block the photon is in making it not refind the proper index and reclaulate the comoving 4 momenta) which can make counting synch scattered photons be thrown off, thus take care of this case by forcing the function to recalc things #if CYCLOSYNCHROTRON_SWITCH == ON if ((ph_block_index==0) && ( ((ph+i)->comv_p0)+((ph+i)->comv_p1)+((ph+i)->comv_p2)+((ph+i)->comv_p3) == 0 ) ) { is_in_block=0; //say that photon is not in the block, force it to recompute things } if (find_nearest_block_switch==0 && is_in_block) { //keep the saved grid index min_index=ph_block_index; } else { //find the new index of the block closest to the photon //min_index=findNearestBlock(array_num, ph_x, ph_y, ph_z, x, y, z); //stop doing this one b/c nearest grid could be one that the photon isnt actually in due to adaptive mesh //find the new index of the block that the photon is actually in min_index=findContainingBlock(photon_hydro_coord[0], photon_hydro_coord[1], photon_hydro_coord[2], hydro_data, fPtr); //(array_num, ph_x, ph_y, ph_z, x, y, z, szx, szy, ph_block_index, find_nearest_block_switch, fPtr); if (min_index != -1) { (ph+i)->nearest_block_index=min_index; //save the index if min_index != -1 //also recalculate the photons' comoving frequency in this new fluid element ph_p[0]=((ph+i)->p0); ph_p[1]=((ph+i)->p1); ph_p[2]=((ph+i)->p2); ph_p[3]=((ph+i)->p3); #if DIMENSIONS == THREE hydroVectorToCartesian(&fluid_beta, (hydro_data->v0)[min_index], (hydro_data->v1)[min_index], (hydro_data->v2)[min_index], (hydro_data->r0)[min_index], (hydro_data->r1)[min_index], (hydro_data->r2)[min_index]); #elif DIMENSIONS == TWO_POINT_FIVE ph_phi=atan2(((ph+i)->r1), ((ph+i)->r0)); hydroVectorToCartesian(&fluid_beta, (hydro_data->v0)[min_index], (hydro_data->v1)[min_index], (hydro_data->v2)[min_index], (hydro_data->r0)[min_index], (hydro_data->r1)[min_index], ph_phi); #else ph_phi=atan2(((ph+i)->r1), ((ph+i)->r0)); //this may have to change if PLUTO can save vectors in 3D when conidering 2D sim hydroVectorToCartesian(&fluid_beta, (hydro_data->v0)[min_index], (hydro_data->v1)[min_index], 0, (hydro_data->r0)[min_index], (hydro_data->r1)[min_index], ph_phi); lorentzBoost(&fluid_beta, &ph_p, &ph_p_comv, 'p', fPtr); ((ph+i)->comv_p0)=ph_p_comv[0]; ((ph+i)->comv_p1)=ph_p_comv[1]; ((ph+i)->comv_p2)=ph_p_comv[2]; ((ph+i)->comv_p3)=ph_p_comv[3]; num_photons_find_new_element+=1; } else { fprintf(fPtr, "Photon number %d FLASH index not found, making sure it doesnt scatter.\n", i); } } //if min_index!= -1 (know which fluid element photon is in) do all this stuff, otherwise make sure photon doesnt scatter if (min_index != -1) { //fprintf(fPtr,"Min Index: %d\n", min_index); //save values (n_dens_lab_tmp)= (hydro_data->dens_lab)[min_index];//(*(dens_lab+min_index)); (n_temp_tmp)= (hydro_data->temp)[min_index];//(*(temp+min_index)); #if DIMENSIONS == THREE hydroVectorToCartesian(&fluid_beta, (hydro_data->v0)[min_index], (hydro_data->v1)[min_index], (hydro_data->v2)[min_index], (hydro_data->r0)[min_index], (hydro_data->r1)[min_index], (hydro_data->r2)[min_index]); #elif DIMENSIONS == TWO_POINT_FIVE ph_phi=atan2(((ph+i)->r1), ((ph+i)->r0)); hydroVectorToCartesian(&fluid_beta, (hydro_data->v0)[min_index], (hydro_data->v1)[min_index], (hydro_data->v2)[min_index], (hydro_data->r0)[min_index], (hydro_data->r1)[min_index], ph_phi); #else ph_phi=atan2(((ph+i)->r1), ((ph+i)->r0)); //this may have to change if PLUTO can save vectors in 3D when conidering 2D sim hydroVectorToCartesian(&fluid_beta, (hydro_data->v0)[min_index], (hydro_data->v1)[min_index], 0, (hydro_data->r0)[min_index], (hydro_data->r1)[min_index], ph_phi); fl_v_x=fluid_beta[0]; fl_v_y=fluid_beta[1]; fl_v_z=fluid_beta[2]; fl_v_norm=sqrt(fl_v_x*fl_v_x+fl_v_y*fl_v_y+fl_v_z*fl_v_z); ph_v_norm=sqrt(((ph+i)->p1)*((ph+i)->p1)+((ph+i)->p2)*((ph+i)->p2)+((ph+i)->p3)*((ph+i)->p3)); //(*(n_cosangle+i))=((fl_v_x* ((ph+i)->p1))+(fl_v_y* ((ph+i)->p2))+(fl_v_z* ((ph+i)->p3)))/(fl_v_norm*ph_v_norm ); //find cosine of the angle between the photon and the fluid velocities via a dot product n_cosangle=((fl_v_x* ((ph+i)->p1))+(fl_v_y* ((ph+i)->p2))+(fl_v_z* ((ph+i)->p3)))/(fl_v_norm*ph_v_norm ); //make 1 for cylindrical otherwise its undefined beta=sqrt(1.0-1.0/((hydro_data->gamma)[min_index]*(hydro_data->gamma)[min_index])); //put this in to double check that random number is between 0 and 1 (exclusive) because there was a problem with this for parallel case rnd_tracker=0; #if defined(_OPENMP) thread_id=omp_get_thread_num(); rnd_tracker=gsl_rng_uniform_pos(rng[thread_id]); //printf("Rnd_tracker: %e Thread number %d \n",rnd_tracker, omp_get_thread_num() ); //mfp=(-1)*log(rnd_tracker)*(M_P/((n_dens_tmp))/(THOM_X_SECT)); ///(1.0-beta*((n_cosangle)))) ; // the mfp and then multiply it by the ln of a random number to simulate distribution of mean free paths IN COMOV FRAME for reference mfp=(-1)*(M_P/((n_dens_lab_tmp))/THOM_X_SECT/(1.0-beta*n_cosangle))*log(rnd_tracker) ; } else { mfp=min_mfp; } } else { mfp=min_mfp; //fprintf(fPtr,"Photon %d In ELSE\n", i); //exit(0); } *(all_time_steps+i)=mfp/C_LIGHT; //fprintf(fPtr,"Photon %d has time %e\n", i, *(all_time_steps+i)); //fflush(fPtr); }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(num_thread) firstprivate( is_in_block, ph_block_index, ph_x, ph_y, ph_z, ph_phi, ph_r, min_index, n_dens_lab_tmp,n_vx_tmp, n_vy_tmp, n_vz_tmp, n_temp_tmp, fl_v_x, fl_v_y, fl_v_z, fl_v_norm, ph_v_norm, n_cosangle, mfp, beta, rnd_tracker, ph_p_comv, el_p, ph_p, fluid_beta) private(i) shared(min_mfp ) reduction(+:num_photons_find_new_element)<OMP-END>
lazzati-astro/MCRaT/Src/mclib.c
#pragma omp parallel for num_threads(nt)
100
rng = (gsl_rng **) malloc((num_thread ) * sizeof(gsl_rng *)); rng[0]=rand; //<LOOP-START>for(i=1;i<num_thread;i++) { rng[i] = gsl_rng_alloc (rng_t); gsl_rng_set(rng[i],gsl_rng_get(rand)); }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(nt)<OMP-END>
lazzati-astro/MCRaT/Src/mclib.c
#pragma omp parallel for num_threads(num_thread) firstprivate( r, theta,dv, v, all_adjacent_block_indexes, j, left_block_index, right_block_index, top_block_index, bottom_block_index, is_in_block, ph_block_index, ph_x, ph_y, ph_z, ph_phi, min_index, n_dens_lab_tmp,n_vx_tmp, n_vy_tmp, n_vz_tmp, n_temp_tmp, fl_v_x, fl_v_y, fl_v_z, fl_v_norm, ph_v_norm, n_cosangle, mfp, beta, rnd_tracker) private(i) shared(min_mfp )
100
mes the min (max) photon radius //or just parallelize this part here min_mfp=1e12; <LOOP-START>for (i=0;i<num_ph; i++) { //printf("%d, %e,%e\n", i, ((ph+i)->r0), ((ph+i)->r1)); if (find_nearest_block_switch==0) { ph_block_index=(ph+i)->nearest_block_index; //if starting a new frame the number of indexes can change and cause a seg fault } else { ph_block_index=0; //if starting a new frame set index=0 to avoid this issue } //if (strcmp(DIM_SWITCH, dim_2d_str)==0) #if DIMENSIONS == 2 { ph_x=pow(pow(((ph+i)->r0),2.0)+pow(((ph+i)->r1),2.0), 0.5); //convert back to FLASH x coordinate ph_y=((ph+i)->r2); ph_phi=atan2(((ph+i)->r1), ((ph+i)->r0)); } #else { ph_x=((ph+i)->r0); ph_y=((ph+i)->r1); ph_z=((ph+i)->r2); } //printf("ph_x:%e, ph_y:%e\n", ph_x, ph_y); is_in_block=checkInBlock(ph_block_index, ph_x, ph_y, ph_z, x, y, z, szx, szy); if (find_nearest_block_switch==0 && is_in_block) { //keep the saved grid index min_index=ph_block_index; } else { //find the new index of the block closest to the photon //min_index=findNearestBlock(array_num, ph_x, ph_y, ph_z, x, y, z); //stop doing this one b/c nearest grid could be one that the photon isnt actually in due to adaptive mesh //find the new index of the block that the photon is actually in //min_index=findContainingBlock(array_num, ph_x, ph_y, ph_z, x, y, z, szx, szy, ph_block_index, find_nearest_block_switch, fPtr); (ph+i)->nearest_block_index=min_index; //save the index } //look for the blocks surounding the block of interest and order them by the left_dist_min=1e15;//set dist to impossible value to make sure at least first distance calulated is saved right_dist_min=1e15; top_dist_min=1e15; bottom_dist_min=1e15; for (j=0;j<array_num;j++) { //if (strcmp(DIM_SWITCH, dim_2d_str)==0) #if DIMENSIONS == 2 { dist= pow(pow((*(x+min_index))- (*(x+j)), 2.0) + pow((*(y+min_index))- (*(y+j)) , 2.0),0.5); } #else { dist= pow(pow((*(x+min_index))- (*(x+j)), 2.0) + pow((*(y+min_index))- (*(y+j)),2.0 ) + pow((*(z+min_index))- (*(z+j)) , 2.0),0.5); } if ((*(x+j))<(*(x+min_index)) && (dist < left_dist_min) ) { left_block_index=j; left_dist_min=dist; } else if ((*(x+j))>(*(x+min_index)) && (dist < right_dist_min)) { right_block_index=j; right_dist_min=dist; } if ((*(y+j))<(*(y+min_index)) && (dist < bottom_dist_min) ) { bottom_block_index=j; bottom_dist_min=dist; } else if ((*(y+j))>(*(y+min_index)) && (dist < top_dist_min) ) { top_block_index=j; top_dist_min=dist; } } all_adjacent_block_indexes[0]=left_block_index; all_adjacent_block_indexes[1]=right_block_index; all_adjacent_block_indexes[2]=bottom_block_index; all_adjacent_block_indexes[3]=top_block_index; //do a weighted average of the 4 nearest grids based on volume v=0; (n_dens_lab_tmp)=0; (n_vx_tmp)= 0; (n_vy_tmp)= 0; (n_temp_tmp)= 0; (n_vz_tmp)= 0; for (j=0;j<4;j++) { #if SIM_SWITCH == RIKEN { r=pow(pow((*(x+all_adjacent_block_indexes[j])),2.0)+pow((*(y+all_adjacent_block_indexes[j])),2.0), 0.5); theta=atan2((*(x+all_adjacent_block_indexes[j])), (*(y+all_adjacent_block_indexes[j]))); dv=2.0*M_PI*pow(r,2)*sin(theta)*(*(szx+all_adjacent_block_indexes[j]))*(*(szy+all_adjacent_block_indexes[j])) ; } #else { //using FLASH dv=2.0*M_PI*(*(x+all_adjacent_block_indexes[j]))*pow(*(szx+all_adjacent_block_indexes[j]),2.0) ; } v+=dv; //save values (n_dens_lab_tmp)+= (*(dens_lab+all_adjacent_block_indexes[j]))*dv; (n_vx_tmp)+= (*(velx+all_adjacent_block_indexes[j]))*dv; (n_vy_tmp)+= (*(vely+all_adjacent_block_indexes[j]))*dv; (n_temp_tmp)+= (*(temp+all_adjacent_block_indexes[j]))*dv; //if (strcmp(DIM_SWITCH, dim_3d_str)==0) #if DIMENSIONS == 3 { (n_vz_tmp)+= (*(velz+all_adjacent_block_indexes[j]))*dv; } } //fprintf(fPtr,"Outside\n"); //save values (n_dens_lab_tmp)/= v; (n_vx_tmp)/= v; (n_vy_tmp)/= v; (n_temp_tmp)/= v; //if (strcmp(DIM_SWITCH, dim_3d_str)==0) #if DIMENSIONS == 3 { (n_vz_tmp)/= v; } //if (strcmp(DIM_SWITCH, dim_2d_str)==0) #if DIMENSIONS == 2 { fl_v_x=n_vx_tmp*cos(ph_phi); fl_v_y=n_vx_tmp*sin(ph_phi); fl_v_z=n_vy_tmp; } #else { fl_v_x=n_vx_tmp; fl_v_y=n_vy_tmp; fl_v_z=n_vz_tmp; } fl_v_norm=pow(pow(fl_v_x, 2.0)+pow(fl_v_y, 2.0)+pow(fl_v_z, 2.0), 0.5); ph_v_norm=pow(pow(((ph+i)->p1), 2.0)+pow(((ph+i)->p2), 2.0)+pow(((ph+i)->p3), 2.0), 0.5); //(*(n_cosangle+i))=((fl_v_x* ((ph+i)->p1))+(fl_v_y* ((ph+i)->p2))+(fl_v_z* ((ph+i)->p3)))/(fl_v_norm*ph_v_norm ); //find cosine of the angle between the photon and the fluid velocities via a dot product (n_cosangle)=((fl_v_x* ((ph+i)->p1))+(fl_v_y* ((ph+i)->p2))+(fl_v_z* ((ph+i)->p3)))/(fl_v_norm*ph_v_norm ); //make 1 for cylindrical otherwise its undefined //if (strcmp(DIM_SWITCH, dim_2d_str)==0) #if DIMENSIONS == 2 { beta=pow((pow((n_vx_tmp),2)+pow((n_vy_tmp),2)),0.5); } #else { beta=pow((pow((n_vx_tmp),2)+pow((n_vy_tmp),2)+pow((n_vz_tmp),2)),0.5); } //put this in to double check that random number is between 0 and 1 (exclusive) because there was a problem with this for parallel case rnd_tracker=0; #if defined(_OPENMP) thread_id=omp_get_thread_num(); rnd_tracker=gsl_rng_uniform_pos(rng[thread_id]); mfp=(-1)*(M_P/((n_dens_lab_tmp))/THOM_X_SECT/(1.0-beta*((n_cosangle))))*log(rnd_tracker) ; //calulate the mfp and then multiply it by the ln of a random number to simulate distribution of mean free paths #pragma omp critical if ( mfp<min_mfp) { min_mfp=mfp; n_dens_lab_min= n_dens_lab_tmp; n_vx_min= n_vx_tmp; n_vy_min= n_vy_tmp; //if (strcmp(DIM_SWITCH, dim_3d_str)==0) #if DIMENSIONS == 3 { n_vz_min= n_vz_tmp; } n_temp_min= n_temp_tmp; index=i; //fprintf(fPtr, "Thread is %d. new min: %e for photon %d with block properties: %e, %e, %e Located at: %e, %e, Dist: %e\n", omp_get_thread_num(), mfp, index, n_vx_tmp, n_vy_tmp, n_temp_tmp, *(x+min_index), *(y+min_index), dist_min); //fflush(fPtr); #pragma omp flush(min_mfp) } }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(num_thread) firstprivate( r, theta,dv, v, all_adjacent_block_indexes, j, left_block_index, right_block_index, top_block_index, bottom_block_index, is_in_block, ph_block_index, ph_x, ph_y, ph_z, ph_phi, min_index, n_dens_lab_tmp,n_vx_tmp, n_vy_tmp, n_vz_tmp, n_temp_tmp, fl_v_x, fl_v_y, fl_v_z, fl_v_norm, ph_v_norm, n_cosangle, mfp, beta, rnd_tracker) private(i) shared(min_mfp )<OMP-END>
lazzati-astro/MCRaT/Src/mclib.c
#pragma omp parallel for num_threads(num_thread) firstprivate(old_position, new_position, divide_p0)
100
get_num_threads(); #endif double old_position=0, new_position=0, divide_p0=0; <LOOP-START>for (i=0;i<num_ph;i++) { if (((ph+i)->type != CS_POOL_PHOTON) && ((ph+i)->weight != 0)) { old_position= sqrt(((ph+i)->r0)*((ph+i)->r0)+((ph+i)->r1)*((ph+i)->r1)+((ph+i)->r2)*((ph+i)->r2)); //uncommented checks since they were not necessary anymore divide_p0=1.0/((ph+i)->p0); ((ph+i)->r0)+=((ph+i)->p1)*divide_p0*C_LIGHT*t; //update x position ((ph+i)->r1)+=((ph+i)->p2)*divide_p0*C_LIGHT*t;//update y ((ph+i)->r2)+=((ph+i)->p3)*divide_p0*C_LIGHT*t;//update z new_position= sqrt(((ph+i)->r0)*((ph+i)->r0)+((ph+i)->r1)*((ph+i)->r1)+((ph+i)->r2)*((ph+i)->r2)); /* if ((new_position-old_position)/t > C_LIGHT) { fprintf(fPtr, "PHOTON NUMBER %d IS SUPERLUMINAL. ITS SPEED IS %e c.\n", i, ((new_position-old_position)/t)/C_LIGHT); } */ //if ( (ph+i)->s0 != 1) { // fprintf(fPtr, "PHOTON NUMBER %d DOES NOT HAVE I=1. Instead it is: %e\n", i, (ph+i)->s0); } //printf("In update function: %e, %e, %e, %e, %e, %e, %e\n",((ph+i)->r0), ((ph+i)->r1), ((ph+i)->r2), t, ((ph+i)->p1)/((ph+i)->p0), ((ph+i)->p2)/((ph+i)->p0), ((ph+i)->p3)/((ph+i)->p0) ); } }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(num_thread) firstprivate(old_position, new_position, divide_p0)<OMP-END>
lazzati-astro/MCRaT/Src/mclib.c
#pragma omp parallel for reduction(+:e_sum) reduction(+:w_sum)
100
_OPENMP) int num_thread=omp_get_num_threads(); #endif double e_sum=0, w_sum=0; <LOOP-START>for (i=0;i<num_ph;i++) { #if CYCLOSYNCHROTRON_SWITCH == ON if (((ph+i)->weight != 0)) //dont want account for null or absorbed UNABSORBED_CS_PHOTON photons { e_sum+=(((ph+i)->p0)*((ph+i)->weight)); w_sum+=((ph+i)->weight); } }<LOOP-END> <OMP-START>#pragma omp parallel for reduction(+:e_sum) reduction(+:w_sum)<OMP-END>
lazzati-astro/MCRaT/Src/mclib.c
#pragma omp parallel for num_threads(num_thread) reduction(min:temp_min) reduction(max:temp_max) reduction(+:sum) reduction(+:avg_r_sum) reduction(+:count)
100
um_synch=0, avg_r_sum_comp=0, avg_r_sum_inject=0; //printf("Num threads: %d", num_thread); <LOOP-START>for (i=0;i<ph_num;i++) { #if CYCLOSYNCHROTRON_SWITCH == ON if (((ph+i)->weight != 0)) //dont want account for null or absorbed UNABSORBED_CS_PHOTON photons { sum+=((ph+i)->num_scatt); avg_r_sum+=sqrt(((ph+i)->r0)*((ph+i)->r0) + ((ph+i)->r1)*((ph+i)->r1) + ((ph+i)->r2)*((ph+i)->r2)); //printf("%d %c %e %e %e %e %e %e\n", i, (ph+i)->type, (ph+i)->p0, (ph+i)->comv_p0, (ph+i)->r0, (ph+i)->r1, (ph+i)->r2, (ph+i)->num_scatt); if (((ph+i)->num_scatt) > temp_max ) { temp_max=((ph+i)->num_scatt); //printf("The new max is: %d\n", temp_max); } //if ((i==0) || (((ph+i)->num_scatt)<temp_min)) if (((ph+i)->num_scatt)<temp_min) { temp_min=((ph+i)->num_scatt); //printf("The new min is: %d\n", temp_min); } if (((ph+i)->type) == INJECTED_PHOTON ) { avg_r_sum_inject+=sqrt(((ph+i)->r0)*((ph+i)->r0) + ((ph+i)->r1)*((ph+i)->r1) + ((ph+i)->r2)*((ph+i)->r2)); count_i++; } #if CYCLOSYNCHROTRON_SWITCH == ON if ((((ph+i)->type) == COMPTONIZED_PHOTON) || (((ph+i)->type) == UNABSORBED_CS_PHOTON)) { avg_r_sum_comp+=sqrt(((ph+i)->r0)*((ph+i)->r0) + ((ph+i)->r1)*((ph+i)->r1) + ((ph+i)->r2)*((ph+i)->r2)); count_comp++; } count++; } #if CYCLOSYNCHROTRON_SWITCH == ON if (((ph+i)->type) == CS_POOL_PHOTON ) { avg_r_sum_synch+=sqrt(((ph+i)->r0)*((ph+i)->r0) + ((ph+i)->r1)*((ph+i)->r1) + ((ph+i)->r2)*((ph+i)->r2)); count_synch++; } }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(num_thread) reduction(min:temp_min) reduction(max:temp_max) reduction(+:sum) reduction(+:avg_r_sum) reduction(+:count)<OMP-END>
lazzati-astro/MCRaT/Src/mclib.c
#pragma omp parallel for num_threads(num_thread) firstprivate(ph_r, ph_theta) reduction(min:temp_r_min) reduction(max:temp_r_max) reduction(min:temp_theta_min) reduction(max:temp_theta_max)
100
d(_OPENMP) int num_thread=omp_get_num_threads(); #endif double ph_r=0, ph_theta=0; <LOOP-START>for (i=0;i<ph_num;i++) { if ((ph+i)->weight != 0) { ph_r=sqrt(((ph+i)->r0)*((ph+i)->r0) + ((ph+i)->r1)*((ph+i)->r1) + ((ph+i)->r2)*((ph+i)->r2)); ph_theta=acos(((ph+i)->r2) /ph_r); //this is the photons theta psition in the FLASH grid, gives in radians if (ph_r > temp_r_max ) { temp_r_max=ph_r; //fprintf(fPtr, "The new max is: %e from photon %d with x: %e y: %e z: %e\n", temp_r_max, i, ((ph+i)->r0), (ph+i)->r1, (ph+i)->r2); } //if ((i==0) || (ph_r<temp_r_min)) if (ph_r<temp_r_min) { temp_r_min=ph_r; //fprintf(fPtr, "The new min is: %e from photon %d with x: %e y: %e z: %e\n", temp_r_min, i, ((ph+i)->r0), (ph+i)->r1, (ph+i)->r2); } if (ph_theta > temp_theta_max ) { temp_theta_max=ph_theta; //fprintf(fPtr, "The new max is: %e from photon %d with x: %e y: %e z: %e\n", temp_r_max, i, ((ph+i)->r0), (ph+i)->r1, (ph+i)->r2); } //if ((i==0) || (ph_r<temp_r_min)) if (ph_theta<temp_theta_min) { temp_theta_min=ph_theta; //fprintf(fPtr, "The new min is: %e from photon %d with x: %e y: %e z: %e\n", temp_r_min, i, ((ph+i)->r0), (ph+i)->r1, (ph+i)->r2); } } }<LOOP-END> <OMP-START>#pragma omp parallel for num_threads(num_thread) firstprivate(ph_r, ph_theta) reduction(min:temp_r_min) reduction(max:temp_r_max) reduction(min:temp_theta_min) reduction(max:temp_theta_max)<OMP-END>
LLNL/dataracebench/micro-benchmarks-fortran/utilities/fpolybench.c
#pragma omp parallel for
100
double* flush = (double*) calloc (cs, sizeof(double)); int i; double tmp = 0.0; #ifdef _OPENMP <LOOP-START>for (i = 0; i < cs; i++) tmp += flush[i]; assert (tmp <= 10.0); free (flush); } #ifdef POLYBENCH_LINUX_FIFO_SCHEDULER void polybench_linux_fifo_scheduler() { /* Use FIFO scheduler to limit OS interference. Program must be run as root, and this works only for Linux kernels. */ struct sched_param schedParam; schedParam.sched_priority = sched_get_priority_max (SCHED_FIFO); sched_setscheduler (0, SCHED_FIFO, &schedParam); }<LOOP-END> <OMP-START>#pragma omp parallel for<OMP-END>
LLNL/dataracebench/micro-benchmarks/DRB043-adi-parallel-no.c
#pragma omp parallel for private(c2)
100
0],double B[500 + 0][500 + 0]) { //int i; //int j; { int c1; int c2; if (n >= 1) { <LOOP-START>for (c1 = 0; c1 <= n + -1; c1++) { for (c2 = 0; c2 <= n + -1; c2++) { X[c1][c2] = (((double )c1) * (c2 + 1) + 1) / n; A[c1][c2] = (((double )c1) * (c2 + 2) + 2) / n; B[c1][c2] = (((double )c1) * (c2 + 3) + 3) / n; } }<LOOP-END> <OMP-START>#pragma omp parallel for private(c2)<OMP-END>