|
Zoltan2
|
00001 // @HEADER 00002 // 00003 // *********************************************************************** 00004 // 00005 // Zoltan2: A package of combinatorial algorithms for scientific computing 00006 // Copyright 2012 Sandia Corporation 00007 // 00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00009 // the U.S. Government retains certain rights in this software. 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are 00013 // met: 00014 // 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice, this list of conditions and the following disclaimer. 00017 // 00018 // 2. Redistributions in binary form must reproduce the above copyright 00019 // notice, this list of conditions and the following disclaimer in the 00020 // documentation and/or other materials provided with the distribution. 00021 // 00022 // 3. Neither the name of the Corporation nor the names of the 00023 // contributors may be used to endorse or promote products derived from 00024 // this software without specific prior written permission. 00025 // 00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 // 00038 // Questions? Contact Karen Devine (kddevin@sandia.gov) 00039 // Erik Boman (egboman@sandia.gov) 00040 // Siva Rajamanickam (srajama@sandia.gov) 00041 // 00042 // *********************************************************************** 00043 // 00044 // @HEADER 00045 00046 #ifndef _ZOLTAN2_TPLTRAITS_HPP_ 00047 #define _ZOLTAN2_TPLTRAITS_HPP_ 00048 00049 #include <Teuchos_RCP.hpp> 00050 #include <Teuchos_ArrayView.hpp> 00051 #include <Teuchos_as.hpp> 00052 #include <Zoltan2_Standards.hpp> 00053 #include <Zoltan2_Environment.hpp> 00054 00059 00060 namespace Zoltan2 { 00061 00063 // General case // 00065 00066 template <typename tpl_t, typename zno_t> 00067 struct TPL_Traits { 00068 00069 static inline bool OK_TO_CAST_TPL_T() 00070 { 00071 // Return true is pointer to tpl_t can be safely used as pointer to zno_t 00072 return ((sizeof(tpl_t) == sizeof(zno_t)) && 00073 (std::numeric_limits<tpl_t>::is_signed == 00074 std::numeric_limits<zno_t>::is_signed)); 00075 } 00076 00077 static inline void ASSIGN_TPL_T(tpl_t &a, zno_t b, 00078 const RCP<const Environment> &env) 00079 { 00080 // Assign a = b; make sure tpl_t is large enough to accept zno_t. 00081 try { 00082 a = Teuchos::asSafe<tpl_t, zno_t>(b); 00083 } 00084 catch (std::exception &e) { 00085 env->localInputAssertion(__FILE__, __LINE__, 00086 "Value too large for TPL index type. " 00087 "Rebuild TPL with larger index type or rebuild without the TPL.", 00088 false, BASIC_ASSERTION); 00089 } 00090 } 00091 00092 static inline void ASSIGN_TPL_T_ARRAY(tpl_t **a, ArrayView<const zno_t> &b, 00093 const RCP<const Environment> &env) 00094 { 00095 // Allocate array a; copy b values into a. 00096 size_t size = b.size(); 00097 if (size > 0) { 00098 *a = new tpl_t[size]; 00099 for (size_t i = 0; i < size; i++) ASSIGN_TPL_T((*a)[i], b[i], env); 00100 } 00101 else { 00102 *a = NULL; 00103 // Note: the Scotch manual says that if any rank has a non-NULL array, 00104 // every process must have a non-NULL array. In practice, 00105 // however, this condition is not needed for the arrays we use. 00106 // For now, we'll set these arrays to NULL. We could allocate 00107 // a dummy value here if needed. KDD 1/23/14 00108 // Note: ParMETIS would likely prefer a dummy value as well. It does 00109 // not like NULL adjcny array. KDD 10/7/14 00110 } 00111 } 00112 00113 static inline void DELETE_TPL_T_ARRAY(tpl_t **a) 00114 { 00115 // Delete the copy made in ASSIGN_TPL_T_ARRAY. 00116 delete [] *a; 00117 } 00118 }; 00119 00121 // Special case: zno_t == tpl_t // 00122 // No error checking or copies // 00124 00125 template <typename tpl_t> 00126 struct TPL_Traits<tpl_t, tpl_t> { 00127 00128 static inline bool OK_TO_CAST_TPL_T() {return true;} 00129 00130 static inline void ASSIGN_TPL_T(tpl_t &a, tpl_t b, 00131 const RCP<const Environment> &env) 00132 { a = b; } 00133 00134 static inline void ASSIGN_TPL_T_ARRAY(tpl_t **a, ArrayView<const tpl_t> &b, 00135 const RCP<const Environment> &env) 00136 { 00137 if (b.size() > 0) 00138 *a = const_cast<tpl_t *> (b.getRawPtr()); 00139 else 00140 *a = NULL; 00141 // Note: the Scotch manual says that if any rank has a non-NULL array, 00142 // every process must have a non-NULL array. In practice, 00143 // however, this condition is not needed for the arrays we use. 00144 // For now, we'll set these arrays to NULL. We could allocate 00145 // a dummy value here if needed. KDD 1/23/14 00146 } 00147 static inline void DELETE_TPL_T_ARRAY(tpl_t **a) { } 00148 }; 00149 00150 } // namespace Zoltan2 00151 00152 #endif
1.7.6.1