|
Support Software for Vector Reduction/Transformation Operators
Version of the Day
|
00001 /* 00002 // @HEADER 00003 // *********************************************************************** 00004 // 00005 // RTOp: Interfaces and Support Software for Vector Reduction Transformation 00006 // Operations 00007 // Copyright (2006) Sandia Corporation 00008 // 00009 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00010 // license for use of this work by or on behalf of the U.S. Government. 00011 // 00012 // Redistribution and use in source and binary forms, with or without 00013 // modification, are permitted provided that the following conditions are 00014 // met: 00015 // 00016 // 1. Redistributions of source code must retain the above copyright 00017 // notice, this list of conditions and the following disclaimer. 00018 // 00019 // 2. Redistributions in binary form must reproduce the above copyright 00020 // notice, this list of conditions and the following disclaimer in the 00021 // documentation and/or other materials provided with the distribution. 00022 // 00023 // 3. Neither the name of the Corporation nor the names of the 00024 // contributors may be used to endorse or promote products derived from 00025 // this software without specific prior written permission. 00026 // 00027 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00028 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00029 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00030 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00031 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00032 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00033 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00034 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00035 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00036 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00037 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00038 // 00039 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00040 // 00041 // *********************************************************************** 00042 // @HEADER 00043 */ 00044 00045 #include "RTOp_parallel_helpers.h" 00046 00047 #define MY_MIN(a,b) ( (a) < (b) ? (a) : (b) ) 00048 #define MY_MAX(a,b) ( (a) > (b) ? (a) : (b) ) 00049 00050 void RTOp_parallel_calc_overlap( 00051 Teuchos_Ordinal global_dim_in, Teuchos_Ordinal local_sub_dim_in, Teuchos_Ordinal local_off_in 00052 ,const Teuchos_Ordinal first_ele_off_in, const Teuchos_Ordinal sub_dim_in, const Teuchos_Ordinal global_off_in 00053 ,Teuchos_Ordinal* overlap_first_local_ele_off, Teuchos_Ordinal* overalap_local_sub_dim 00054 ,Teuchos_Ordinal* overlap_global_off 00055 ) 00056 { 00057 Teuchos_Ordinal global_sub_dim = 0; 00058 #ifdef RTOp_DEBUG 00059 assert( overlap_first_local_ele_off ); 00060 assert( overalap_local_sub_dim ); 00061 assert( overlap_global_off ); 00062 /* ToDo: Check the rest of the preconditions! */ 00063 #endif 00064 /* Dimension of global sub-vector */ 00065 global_sub_dim = sub_dim_in >= 0 ? sub_dim_in : global_dim_in - first_ele_off_in; 00066 /* 00067 * We need to determine if the local elements stored in this process overlap 00068 * with the global sub-vector that the client has requested. 00069 */ 00070 if( !( 00071 local_off_in + local_sub_dim_in < first_ele_off_in + 1 00072 || 00073 first_ele_off_in + global_sub_dim < local_off_in + 1 00074 ) 00075 ) 00076 { 00077 /* 00078 * Determine how much of the local sub-vector stored in this process gets operated on. 00079 * If (first_ele_off_in-1) <= local_off_in, then we start at the first element 00080 * in this process. Otherwise, we need to to increment by first_ele_off_in - local_off_in 00081 */ 00082 *overlap_first_local_ele_off = first_ele_off_in <= local_off_in ? 0 : first_ele_off_in - local_off_in; 00083 /* 00084 * Deterime the number of elements in the local sub-vector that overlap with the 00085 * requested logical sub-vector. 00086 */ 00087 *overalap_local_sub_dim = ( 00088 MY_MIN(first_ele_off_in+global_sub_dim,local_off_in+local_sub_dim_in) /* last overlap element plus 1 in process */ 00089 - 00090 MY_MAX(first_ele_off_in,local_off_in) /* first overlap element in process */ 00091 ); 00092 /* 00093 * Finally, figure out where this local sub-vectors fit into the logical 00094 * vector that the client has specified with global_off_in and 00095 * first_ele_off_in. Note that the element this->(first_ele_off) acts as 00096 * the the first element in the logical vector defined by the client if 00097 * gloabal_offset_in == 0. Therefore, we need to subtract 00098 * first_ele_off_in from local_off_in to get the true offset into the 00099 * logicl vector defined by the client. Then we can adjust it by adding 00100 * global_off_in to place it into the clients actual logical vector.. 00101 */ 00102 *overlap_global_off = ( 00103 ( first_ele_off_in > local_off_in 00104 ? 0 00105 : local_off_in - first_ele_off_in 00106 ) /* First element in 'v' in logical sub-vector 'g' */ 00107 + global_off_in /* Adding adjustment into logical sub-vector 'p' */ 00108 ); 00109 } 00110 else { 00111 *overlap_first_local_ele_off = -1; /* No overlap */ 00112 } 00113 }
1.7.6.1