RTOp Package Browser (Single Doxygen Collection) Version of the Day
RTOp_parallel_helpers.c
Go to the documentation of this file.
00001 /*
00002 // @HEADER
00003 // ***********************************************************************
00004 // 
00005 //      Thyra: Interfaces and Support Code for the Interoperability of Abstract Numerical Algorithms 
00006 //                 Copyright (2004) Sandia Corporation
00007 // 
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //  
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00026 // 
00027 // ***********************************************************************
00028 // @HEADER
00029 */
00030 
00031 #include "RTOp_parallel_helpers.h"
00032 
00033 #define MY_MIN(a,b) ( (a) < (b) ? (a) : (b) )
00034 #define MY_MAX(a,b) ( (a) > (b) ? (a) : (b) )
00035 
00036 void RTOp_parallel_calc_overlap(
00037   Teuchos_Index global_dim_in, Teuchos_Index local_sub_dim_in, Teuchos_Index local_off_in
00038   ,const Teuchos_Index first_ele_off_in, const Teuchos_Index sub_dim_in, const Teuchos_Index global_off_in
00039   ,Teuchos_Index* overlap_first_local_ele_off, Teuchos_Index* overalap_local_sub_dim
00040   ,Teuchos_Index* overlap_global_off
00041   )
00042 {
00043   Teuchos_Index  global_sub_dim = 0;
00044 #ifdef RTOp_DEBUG
00045   assert( overlap_first_local_ele_off );
00046   assert( overalap_local_sub_dim );
00047   assert( overlap_global_off );
00048   /* ToDo: Check the rest of the preconditions! */
00049 #endif
00050   /* Dimension of global sub-vector */
00051   global_sub_dim = sub_dim_in >= 0 ? sub_dim_in : global_dim_in - first_ele_off_in;
00052   /*
00053    * We need to determine if the local elements stored in this process overlap
00054    * with the global sub-vector that the client has requested.
00055    */
00056   if( !(
00057         local_off_in + local_sub_dim_in < first_ele_off_in + 1
00058         ||
00059         first_ele_off_in + global_sub_dim < local_off_in + 1
00060         )
00061     )
00062   {
00063     /* 
00064      * Determine how much of the local sub-vector stored in this process gets operated on. 
00065      * If (first_ele_off_in-1) <= local_off_in, then we start at the first element 
00066      * in this process.  Otherwise, we need to to increment by first_ele_off_in - local_off_in 
00067      */
00068     *overlap_first_local_ele_off = first_ele_off_in <= local_off_in ? 0 : first_ele_off_in - local_off_in;
00069     /*
00070      * Deterime the number of elements in the local sub-vector that overlap with the
00071      * requested logical sub-vector.
00072      */
00073     *overalap_local_sub_dim  = (
00074       MY_MIN(first_ele_off_in+global_sub_dim,local_off_in+local_sub_dim_in) /* last overlap element plus 1 in process */
00075       -
00076       MY_MAX(first_ele_off_in,local_off_in)                                 /* first overlap element in process */
00077       );
00078     /*
00079      * Finally, figure out where this local sub-vectors fit into the logical
00080      * vector that the client has specified with global_off_in and
00081      * first_ele_off_in.  Note that the element this->(first_ele_off) acts as
00082      * the the first element in the logical vector defined by the client if
00083      * gloabal_offset_in == 0.  Therefore, we need to subtract
00084      * first_ele_off_in from local_off_in to get the true offset into the
00085      * logicl vector defined by the client.  Then we can adjust it by adding
00086      * global_off_in to place it into the clients actual logical vector..
00087      */
00088     *overlap_global_off   = (
00089       ( first_ele_off_in > local_off_in
00090         ? 0
00091         : local_off_in - first_ele_off_in
00092         )                 /* First element in 'v' in logical sub-vector 'g' */
00093       + global_off_in     /* Adding adjustment into logical sub-vector 'p' */
00094       );
00095   }
00096   else {
00097     *overlap_first_local_ele_off = -1; /* No overlap */
00098   }
00099 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines