• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Epetra_GatherAllV.cpp

Go to the documentation of this file.
00001 //*****************************************************************//
00002 //    Albany 2.0:  Copyright 2012 Sandia Corporation               //
00003 //    This Software is released under the BSD license detailed     //
00004 //    in the file "license.txt" in the top-level Albany directory  //
00005 //*****************************************************************//
00006 
00007 #include "Epetra_GatherAllV.hpp"
00008 
00009 #include "Epetra_ConfigDefs.h"
00010 
00011 #include "Epetra_Comm.h"
00012 #ifdef EPETRA_MPI
00013 #include "Epetra_MpiComm.h"
00014 #endif /* EPETRA_MPI */
00015 #include "Epetra_SerialComm.h"
00016 
00017 #include "Teuchos_Array.hpp"
00018 #include "Teuchos_Assert.hpp"
00019 #include "Teuchos_TestForException.hpp"
00020 
00021 #ifdef EPETRA_MPI
00022 #include "mpi.h"
00023 #endif /* EPETRA_MPI */
00024 
00025 #include <numeric>
00026 #include <algorithm>
00027 
00028 int Epetra::GatherAllV(
00029     const Epetra_Comm &comm,
00030     const int *myVals, int myCount,
00031     int *allVals, int allCount)
00032 {
00033 #ifdef EPETRA_MPI
00034   if (const Epetra_MpiComm *mpiComm = dynamic_cast<const Epetra_MpiComm *>(&comm)) {
00035     const MPI_Comm rawComm = mpiComm->Comm();
00036 
00037     const int cpuCount = mpiComm->NumProc();
00038     Teuchos::Array<int> allValCounts(cpuCount);
00039     const int ierr = MPI_Allgather(
00040         &myCount, 1, MPI_INT,
00041         allValCounts.getRawPtr(), 1, MPI_INT,
00042         rawComm);
00043     TEUCHOS_TEST_FOR_EXCEPT(ierr != 0);
00044 
00045     Teuchos::Array<int> allValDisps(cpuCount);
00046     std::partial_sum(allValCounts.begin(), allValCounts.end() - 1, allValDisps.begin() + 1);
00047     TEUCHOS_ASSERT(allCount == allValCounts.back() + allValDisps.back());
00048 
00049     return MPI_Allgatherv(
00050         const_cast<int *>(myVals), myCount, MPI_INT,
00051         allVals, allValCounts.getRawPtr(), allValDisps.getRawPtr(), MPI_INT,
00052         rawComm);
00053   } else
00054 #endif /* EPETRA_MPI */
00055   if (dynamic_cast<const Epetra_SerialComm *>(&comm)) {
00056     TEUCHOS_ASSERT(myCount == allCount);
00057     std::copy(myVals, myVals + myCount, allVals);
00058     return 0;
00059   } else {
00060     const bool commTypeNotSupported = true;
00061     TEUCHOS_TEST_FOR_EXCEPT(commTypeNotSupported);
00062   }
00063 }

Generated on Wed Mar 26 2014 18:36:38 for Albany: a Trilinos-based PDE code by  doxygen 1.7.1