FEI Version of the Day
snl_fei_SubdMsgHandler.cpp
00001 /*
00002 // @HEADER
00003 // ************************************************************************
00004 //             FEI: Finite Element Interface to Linear Solvers
00005 //                  Copyright (2005) Sandia Corporation.
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the
00008 // U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Alan Williams (william@sandia.gov) 
00038 //
00039 // ************************************************************************
00040 // @HEADER
00041 */
00042 
00043 
00044 #include <fei_macros.hpp>
00045 
00046 #include <snl_fei_SubdMsgHandler.hpp>
00047 #include <snl_fei_RecordCollection.hpp>
00048 #include <fei_SharedIDs.hpp>
00049 #include <fei_TemplateUtils.hpp>
00050 
00051 #undef fei_file
00052 #define fei_file "snl_fei::SubdMsgHandler"
00053 #include <fei_ErrMacros.hpp>
00054 
00055 snl_fei::SubdMsgHandler::SubdMsgHandler(RecordCollection* recordCollection,
00056           fei::SharedIDs<int>* sharedIDTable,
00057           fei::SharedIDs<int>* subdomainIDTable)
00058   :sendPattern_(NULL),
00059    recvPattern_(NULL),
00060    recordCollection_(recordCollection),
00061    sharedIDTable_(sharedIDTable),
00062    subdomainIDTable_(subdomainIDTable),
00063    sendProcs_(0, 32),
00064    recvProcs_(0, 32)
00065 {
00066 }
00067 
00068 snl_fei::SubdMsgHandler::~SubdMsgHandler()
00069 {
00070 }
00071 
00072 std::vector<int>& snl_fei::SubdMsgHandler::getSendProcs()
00073 {
00074   fei::copyKeysToVector(sendPattern_->getMap(), sendProcs_);
00075   return(sendProcs_);
00076 }
00077 
00078 std::vector<int>& snl_fei::SubdMsgHandler::getRecvProcs()
00079 {
00080   fei::copyKeysToVector(recvPattern_->getMap(), recvProcs_);
00081   return(recvProcs_);
00082 }
00083 
00084 int snl_fei::SubdMsgHandler::getSendMessageLength(int destProc,
00085               int& messageLength)
00086 {
00087   fei::comm_map::row_type* list = sendPattern_->getRow(destProc);
00088   if (list == NULL) {
00089     FEI_COUT << "SubdMsdHandler: destProc: " << destProc << ", list is NULL."<<FEI_ENDL;
00090     return(-1);
00091   }
00092 
00093   messageLength = list->size();
00094 
00095   return( 0 );
00096 }
00097 
00098 int snl_fei::SubdMsgHandler::getSendMessage(int destProc,
00099             std::vector<int>& message)
00100 {
00101   int len = sendPattern_->getRow(destProc)->size();
00102   message.resize(len);
00103   int* msgPtr = &message[0];
00104 
00105   fei::comm_map::row_type* ids = sendPattern_->getRow(destProc);
00106   fei::comm_map::row_type::const_iterator
00107     id_iter = ids->begin(),
00108     id_end = ids->end();
00109 
00110   int offset = 0;
00111   for(; id_iter != id_end; ++id_iter) {
00112     int ID = *id_iter;
00113     fei::Record<int>* rec = recordCollection_->getRecordWithID(ID);
00114     if (rec == NULL) {
00115       ERReturn(-1);
00116     }
00117 
00118     if (rec->isInLocalSubdomain_) {
00119       msgPtr[offset++] = 1;
00120     }
00121     else {
00122       msgPtr[offset++] = 0;
00123     }
00124   }
00125 
00126   return(0);
00127 }
00128 
00129 int snl_fei::SubdMsgHandler::processRecvMessage(int srcProc,
00130             std::vector<int>& message)
00131 {
00132   fei::comm_map::row_type* ids = recvPattern_->getRow(srcProc);
00133   fei::comm_map::row_type::const_iterator
00134     id_iter = ids->begin(),
00135     id_end = ids->end();
00136 
00137   int* msgPtr = &message[0];
00138 
00139   if (message.size() != ids->size()) {
00140     ERReturn(-1);
00141   }
00142 
00143   int offset = 0;
00144   for(; id_iter != id_end; ++id_iter) {
00145     int ID = *id_iter;
00146 
00147     bool isInRemoteSubdomain = msgPtr[offset++] > 1 ? true : false;
00148 
00149     if (isInRemoteSubdomain) {
00150       subdomainIDTable_->addSharedID(ID, 1, &srcProc);
00151     }
00152   }
00153 
00154   return(0);
00155 }
00156 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends