Support Software for Vector Reduction/Transformation Operators Version of the Day
Loading...
Searching...
No Matches
RTOp_parallel_helpers.c
1/*
2// @HEADER
3// ***********************************************************************
4//
5// RTOp: Interfaces and Support Software for Vector Reduction Transformation
6// Operations
7// Copyright (2006) Sandia Corporation
8//
9// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
10// license for use of this work by or on behalf of the U.S. Government.
11//
12// Redistribution and use in source and binary forms, with or without
13// modification, are permitted provided that the following conditions are
14// met:
15//
16// 1. Redistributions of source code must retain the above copyright
17// notice, this list of conditions and the following disclaimer.
18//
19// 2. Redistributions in binary form must reproduce the above copyright
20// notice, this list of conditions and the following disclaimer in the
21// documentation and/or other materials provided with the distribution.
22//
23// 3. Neither the name of the Corporation nor the names of the
24// contributors may be used to endorse or promote products derived from
25// this software without specific prior written permission.
26//
27// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
28// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
31// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38//
39// Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
40//
41// ***********************************************************************
42// @HEADER
43*/
44
45#include "RTOp_parallel_helpers.h"
46
47#define MY_MIN(a,b) ( (a) < (b) ? (a) : (b) )
48#define MY_MAX(a,b) ( (a) > (b) ? (a) : (b) )
49
50void RTOp_parallel_calc_overlap(
51 Teuchos_Ordinal global_dim_in, Teuchos_Ordinal local_sub_dim_in, Teuchos_Ordinal local_off_in
52 ,const Teuchos_Ordinal first_ele_off_in, const Teuchos_Ordinal sub_dim_in, const Teuchos_Ordinal global_off_in
53 ,Teuchos_Ordinal* overlap_first_local_ele_off, Teuchos_Ordinal* overalap_local_sub_dim
54 ,Teuchos_Ordinal* overlap_global_off
55 )
56{
57 Teuchos_Ordinal global_sub_dim = 0;
58#ifdef RTOp_DEBUG
59 assert( overlap_first_local_ele_off );
60 assert( overalap_local_sub_dim );
61 assert( overlap_global_off );
62 /* ToDo: Check the rest of the preconditions! */
63#endif
64 /* Dimension of global sub-vector */
65 global_sub_dim = sub_dim_in >= 0 ? sub_dim_in : global_dim_in - first_ele_off_in;
66 /*
67 * We need to determine if the local elements stored in this process overlap
68 * with the global sub-vector that the client has requested.
69 */
70 if( !(
71 local_off_in + local_sub_dim_in < first_ele_off_in + 1
72 ||
73 first_ele_off_in + global_sub_dim < local_off_in + 1
74 )
75 )
76 {
77 /*
78 * Determine how much of the local sub-vector stored in this process gets operated on.
79 * If (first_ele_off_in-1) <= local_off_in, then we start at the first element
80 * in this process. Otherwise, we need to to increment by first_ele_off_in - local_off_in
81 */
82 *overlap_first_local_ele_off = first_ele_off_in <= local_off_in ? 0 : first_ele_off_in - local_off_in;
83 /*
84 * Deterime the number of elements in the local sub-vector that overlap with the
85 * requested logical sub-vector.
86 */
87 *overalap_local_sub_dim = (
88 MY_MIN(first_ele_off_in+global_sub_dim,local_off_in+local_sub_dim_in) /* last overlap element plus 1 in process */
89 -
90 MY_MAX(first_ele_off_in,local_off_in) /* first overlap element in process */
91 );
92 /*
93 * Finally, figure out where this local sub-vectors fit into the logical
94 * vector that the client has specified with global_off_in and
95 * first_ele_off_in. Note that the element this->(first_ele_off) acts as
96 * the the first element in the logical vector defined by the client if
97 * gloabal_offset_in == 0. Therefore, we need to subtract
98 * first_ele_off_in from local_off_in to get the true offset into the
99 * logicl vector defined by the client. Then we can adjust it by adding
100 * global_off_in to place it into the clients actual logical vector..
101 */
102 *overlap_global_off = (
103 ( first_ele_off_in > local_off_in
104 ? 0
105 : local_off_in - first_ele_off_in
106 ) /* First element in 'v' in logical sub-vector 'g' */
107 + global_off_in /* Adding adjustment into logical sub-vector 'p' */
108 );
109 }
110 else {
111 *overlap_first_local_ele_off = -1; /* No overlap */
112 }
113}