ARTS  2.2.66
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 "matpackIV.h"
20 #include "arts_omp.h"
21 #include "rte.h"
22 
23 int main()
24 {
25  Index nloop = 2000;
26  Index nf = 115;
27  Index np = 50;
28  Index stokes_dim = 1;
29 
30  Tensor4 ppath_abs(nf, stokes_dim, stokes_dim, np, 0.);
31  Tensor4 trans_cumulat(nf, stokes_dim, stokes_dim, np, 0.);
32  Tensor4 trans_partial(nf, stokes_dim, stokes_dim, np, 0.);
33  Vector scalar_tau(nf, 0.);
34  Vector lstep(np, 1.);
35 
36 
37  ArrayOfArrayOfIndex extmat_case(np);
38  for( Index ip = 0; ip < np; ip++)
39  {
40  extmat_case[ip].resize(nf);
41  }
42 
43 // Commenting in the next two lines shouldn't change anything, because
44 // the outer loop will still run sequentially and the inner one parallel.
45 // Nonetheless, performance grinds to a halt because OpenMP can not reuse
46 // the initial threads. It has to create new ones for the inner loop on
47 // every iteration.
48 /*#pragma omp parallel for \
49 if (0)*/
50  for( Index n = 0; n < nloop; n++)
51  {
52  for( Index ip = 1; ip < np; ip++)
53  {
54 #pragma omp parallel for
55  for( Index iv=0; iv<nf; iv++ )
56  {
57  // Transmission due to absorption
58  Matrix ext_mat(stokes_dim,stokes_dim);
59  for( Index is1=0; is1<stokes_dim; is1++ ) {
60  for( Index is2=0; is2<stokes_dim; is2++ ) {
61  ext_mat(is1,is2) = 0.5 * ( ppath_abs(iv,is1,is2,ip-1) +
62  ppath_abs(iv,is1,is2,ip ) );
63  }
64  }
65  scalar_tau[iv] += lstep[ip-1] * ext_mat(0,0);
66  extmat_case[ip-1][iv] = 0;
67  ext2trans( trans_partial(iv,joker,joker,ip-1),
68  extmat_case[ip-1][iv], ext_mat, lstep[ip-1] );
69 
70  // Cumulative transmission
71  // (note that multiplication below depends on ppath loop order)
72  mult( trans_cumulat(iv,joker,joker,ip),
73  trans_cumulat(iv,joker,joker,ip-1),
74  trans_partial(iv,joker,joker,ip-1) );
75  }
76  }
77  }
78  return 0;
79 }
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
The Vector class.
Definition: matpackI.h:556
The Tensor4 class.
Definition: matpackIV.h:383
void mult(VectorView y, const ConstMatrixView &M, const ConstVectorView &x)
Matrix Vector multiplication.
Definition: matpackI.cc:1648
const Joker joker
The Matrix class.
Definition: matpackI.h:788
int main()
Definition: test_omp.cc:23
Header file for helper functions for OpenMP.
void ext2trans(MatrixView trans_mat, Index &icase, ConstMatrixView ext_mat, const Numeric &lstep)
Definition: rte.cc:903
Declaration of functions in rte.cc.