[Trilinos-Users] Teuchos::reduceAllAndScatter issue?

Nico Schlömer nico.schloemer at ua.ac.be
Tue Aug 24 20:54:50 MDT 2010


Hi all,

I just played around with Teuchos::reduceAllAndScatter and I can't 
seem to get it to work. The data would be reduced correctly, but the 
buffers of all processes except 0 are filled with garbage; process 0 
has the correct result.

A minimal example of what I did is attached. When running on four 
cores, I get

================= *snip* =================
Sum on process 0: 4
Sum on process 1: 2.7657e-309
Sum on process 3: 6.52167e-322
Sum on process 2: 6.32404e-322
================= *snap* =================

Any obvious mistakes?

Cheers,
Nico
-------------- next part --------------
#include <Teuchos_DefaultComm.hpp>
#include <Tpetra_CrsMatrix.hpp>

typedef int ORD;

int
main (int argc, char** argv)
{
#ifdef HAVE_MPI
  MPI_Init( &argc, &argv );
#endif

    // Create a communicator for Tpetra objects
    const Teuchos::RCP<const Teuchos::Comm<ORD> > comm =
          Teuchos::DefaultComm<int>::getComm();

    int count = 1; // send *one* double
    Teuchos::Array<double> sendBuff ( count );
    Teuchos::Array<double> recvBuff ( count );

    // clear out hte receive buffer
    recvBuff[0] = 0.0;
    
    // fill send buffer
    sendBuff[0] = 1.0;

    int numProcs =  comm->getSize();
    Teuchos::Array<int> recvCounts ( numProcs );
    // fill recvCounts with {1,...,1}
    int numItemsPerProcess = 1;
    std::fill ( recvCounts.begin(), recvCounts.end(), numItemsPerProcess );

    Teuchos::reduceAllAndScatter ( *comm,
                                   Teuchos::REDUCE_SUM,
                                   count,
                                   & sendBuff[0],
                                   & recvCounts[0],
                                   & recvBuff[0]
                                 );
                                 
    std::cout << "Sum on process " << comm->getRank() << ": "
              << recvBuff[0] << std::endl;
                           
#ifdef HAVE_MPI
  MPI_Finalize();
#endif

  return( EXIT_SUCCESS );
}
-------------- next part --------------
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

FIND_PACKAGE( Trilinos REQUIRED )

SET( CMAKE_C_COMPILER ${Trilinos_C_COMPILER} )
SET( CMAKE_CXX_COMPILER ${Trilinos_CXX_COMPILER} )
SET( CMAKE_Fortran_COMPILER ${Trilinos_Fortran_COMPILER} )

PROJECT( extract CXX Fortran )

INCLUDE_DIRECTORIES ( ${Trilinos_INCLUDE_DIRS}
                      ${Trilinos_TPL_INCLUDE_DIRS} )
LINK_DIRECTORIES( ${Trilinos_LIBRARY_DIRS}
                  ${Trilinos_TPL_LIBRARY_DIRS} )

SET( MY_EXECUTABLE
     "crsgraph.exe" )
SET ( extract_SRCS
      main.cpp )
ADD_EXECUTABLE( ${MY_EXECUTABLE}
                ${extract_SRCS} )

SET_TARGET_PROPERTIES( ${MY_EXECUTABLE}
                       PROPERTIES LINKER_LANGUAGE Fortran )

TARGET_LINK_LIBRARIES( ${MY_EXECUTABLE}
                       ${Trilinos_LIBRARIES}
                       ${Trilinos_TPL_LIBRARIES} )


More information about the Trilinos-Users mailing list