ARTS  2.4.0(git:4fb77825)
test_omp.cc
Go to the documentation of this file.
1 /* Copyright (C) 2013 Oliver Lemke
2 
3  This program is free software; you can redistribute it and/or modify it
4  under the terms of the GNU General Public License as published by the
5  Free Software Foundation; either version 2, or (at your option) any
6  later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16  USA. */
17 
18 #include <iostream>
19 #include "arts_omp.h"
20 #include "matpackIV.h"
21 #include "rte.h"
22 
23 int main() {
24  Index nloop = 2000;
25  Index nf = 115;
26  Index np = 50;
27  Index stokes_dim = 1;
28 
29  Tensor4 ppath_abs(nf, stokes_dim, stokes_dim, np, 0.);
30  Tensor4 trans_cumulat(nf, stokes_dim, stokes_dim, np, 0.);
31  Tensor4 trans_partial(nf, stokes_dim, stokes_dim, np, 0.);
32  Vector scalar_tau(nf, 0.);
33  Vector lstep(np, 1.);
34 
35  ArrayOfArrayOfIndex extmat_case(np);
36  for (Index ip = 0; ip < np; ip++) {
37  extmat_case[ip].resize(nf);
38  }
39 
40  // Commenting in the next two lines shouldn't change anything, because
41  // the outer loop will still run sequentially and the inner one parallel.
42  // Nonetheless, performance grinds to a halt because OpenMP can not reuse
43  // the initial threads. It has to create new ones for the inner loop on
44  // every iteration.
45  /*#pragma omp parallel for \
46 if (0)*/
47  for (Index n = 0; n < nloop; n++) {
48  for (Index ip = 1; ip < np; ip++) {
49 #pragma omp parallel for
50  for (Index iv = 0; iv < nf; iv++) {
51  // Transmission due to absorption
53  for (Index is1 = 0; is1 < stokes_dim; is1++) {
54  for (Index is2 = 0; is2 < stokes_dim; is2++) {
55  ext_mat(is1, is2) = 0.5 * (ppath_abs(iv, is1, is2, ip - 1) +
56  ppath_abs(iv, is1, is2, ip));
57  }
58  }
59  scalar_tau[iv] += lstep[ip - 1] * ext_mat(0, 0);
60  extmat_case[ip - 1][iv] = 0;
61  ext2trans(trans_partial(iv, joker, joker, ip - 1),
62  extmat_case[ip - 1][iv],
63  ext_mat,
64  lstep[ip - 1]);
65 
66  // Cumulative transmission
67  // (note that multiplication below depends on ppath loop order)
68  mult(trans_cumulat(iv, joker, joker, ip),
69  trans_cumulat(iv, joker, joker, ip - 1),
70  trans_partial(iv, joker, joker, ip - 1));
71  }
72  }
73  }
74  return 0;
75 }
Matrix
The Matrix class.
Definition: matpackI.h:1193
joker
const Joker joker
mult
void mult(ComplexVectorView y, const ConstComplexMatrixView &M, const ConstComplexVectorView &x)
Matrix-Vector Multiplication.
Definition: complex.cc:1579
ARTS::Var::stokes_dim
Index stokes_dim(Workspace &ws) noexcept
Definition: autoarts.h:6650
Tensor4
The Tensor4 class.
Definition: matpackIV.h:421
matpackIV.h
Array< ArrayOfIndex >
main
int main()
Definition: test_omp.cc:23
ARTS::Var::ext_mat
PropagationMatrix ext_mat(Workspace &ws) noexcept
Definition: autoarts.h:3390
rte.h
Declaration of functions in rte.cc.
ext2trans
void ext2trans(MatrixView trans_mat, Index &icase, ConstMatrixView ext_mat, const Numeric &lstep)
Converts an extinction matrix to a transmission matrix.
Definition: rte.cc:800
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Vector
The Vector class.
Definition: matpackI.h:860
arts_omp.h
Header file for helper functions for OpenMP.