RTOp Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RTOp_parallel_helpers.c
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // RTOp: Interfaces and Support Software for Vector Reduction Transformation
4 // Operations
5 //
6 // Copyright 2006 NTESS and the RTOp contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10 #include "RTOp_parallel_helpers.h"
11 
12 #define MY_MIN(a,b) ( (a) < (b) ? (a) : (b) )
13 #define MY_MAX(a,b) ( (a) > (b) ? (a) : (b) )
14 
16  Teuchos_Ordinal global_dim_in, Teuchos_Ordinal local_sub_dim_in, Teuchos_Ordinal local_off_in
17  ,const Teuchos_Ordinal first_ele_off_in, const Teuchos_Ordinal sub_dim_in, const Teuchos_Ordinal global_off_in
18  ,Teuchos_Ordinal* overlap_first_local_ele_off, Teuchos_Ordinal* overalap_local_sub_dim
19  ,Teuchos_Ordinal* overlap_global_off
20  )
21 {
22  Teuchos_Ordinal global_sub_dim = 0;
23 #ifdef RTOp_DEBUG
24  assert( overlap_first_local_ele_off );
25  assert( overalap_local_sub_dim );
26  assert( overlap_global_off );
27  /* ToDo: Check the rest of the preconditions! */
28 #endif
29  /* Dimension of global sub-vector */
30  global_sub_dim = sub_dim_in >= 0 ? sub_dim_in : global_dim_in - first_ele_off_in;
31  /*
32  * We need to determine if the local elements stored in this process overlap
33  * with the global sub-vector that the client has requested.
34  */
35  if( !(
36  local_off_in + local_sub_dim_in < first_ele_off_in + 1
37  ||
38  first_ele_off_in + global_sub_dim < local_off_in + 1
39  )
40  )
41  {
42  /*
43  * Determine how much of the local sub-vector stored in this process gets operated on.
44  * If (first_ele_off_in-1) <= local_off_in, then we start at the first element
45  * in this process. Otherwise, we need to to increment by first_ele_off_in - local_off_in
46  */
47  *overlap_first_local_ele_off = first_ele_off_in <= local_off_in ? 0 : first_ele_off_in - local_off_in;
48  /*
49  * Deterime the number of elements in the local sub-vector that overlap with the
50  * requested logical sub-vector.
51  */
52  *overalap_local_sub_dim = (
53  MY_MIN(first_ele_off_in+global_sub_dim,local_off_in+local_sub_dim_in) /* last overlap element plus 1 in process */
54  -
55  MY_MAX(first_ele_off_in,local_off_in) /* first overlap element in process */
56  );
57  /*
58  * Finally, figure out where this local sub-vectors fit into the logical
59  * vector that the client has specified with global_off_in and
60  * first_ele_off_in. Note that the element this->(first_ele_off) acts as
61  * the the first element in the logical vector defined by the client if
62  * gloabal_offset_in == 0. Therefore, we need to subtract
63  * first_ele_off_in from local_off_in to get the true offset into the
64  * logicl vector defined by the client. Then we can adjust it by adding
65  * global_off_in to place it into the clients actual logical vector..
66  */
67  *overlap_global_off = (
68  ( first_ele_off_in > local_off_in
69  ? 0
70  : local_off_in - first_ele_off_in
71  ) /* First element in 'v' in logical sub-vector 'g' */
72  + global_off_in /* Adding adjustment into logical sub-vector 'p' */
73  );
74  }
75  else {
76  *overlap_first_local_ele_off = -1; /* No overlap */
77  }
78 }
#define MY_MIN(a, b)
TEUCHOS_ORDINAL_TYPE Teuchos_Ordinal
void RTOp_parallel_calc_overlap(Teuchos_Ordinal global_dim_in, Teuchos_Ordinal local_sub_dim_in, Teuchos_Ordinal local_off_in, const Teuchos_Ordinal first_ele_off_in, const Teuchos_Ordinal sub_dim_in, const Teuchos_Ordinal global_off_in, Teuchos_Ordinal *overlap_first_local_ele_off, Teuchos_Ordinal *overalap_local_sub_dim, Teuchos_Ordinal *overlap_global_off)
This function helps to implement vector method apply_op(...) for any type of parallel vector...
#define MY_MAX(a, b)