// Copyright 2002 - 2008, 2010, 2011 National Technology Engineering // Solutions of Sandia, LLC (NTESS). Under the terms of Contract // DE-NA0003525 with NTESS, the U.S. Government retains certain rights // in this software. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // * Neither the name of NTESS nor the names of its contributors // may be used to endorse or promote products derived from this // software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // #include "gtest/gtest.h" #include "stk_util/diag/String.hpp" // for String #include "stk_util/parallel/Parallel.hpp" // for MPI_COMM_WORLD, MPI_SUCCESS, paral... #include "stk_util/parallel/ParallelVectorConcat.hpp" // for parallel_vector_concat #include // for operator<<, ostringstream, basic_o... #include // for allocator_traits<>::value_type #include // for string, basic_string, char_traits #include // for vector class TestStruct { public: unsigned int data1; double data2; double data3; }; TEST(UnitTestParallel, testParallelVectorConcat) { int mpi_rank = stk::parallel_machine_rank(MPI_COMM_WORLD); int mpi_size = stk::parallel_machine_size(MPI_COMM_WORLD); // // Test 1, concat integer lists, each process P creates n-1 copies of P thus on 6 processors the // expected concat list is: // // 2 3 3 4 4 4 5 5 5 5 // { std::vector localIntList; for(int i=0; i globalIntList; int status = stk::parallel_vector_concat(MPI_COMM_WORLD, localIntList, globalIntList); EXPECT_EQ(status, MPI_SUCCESS); std::vector expectedIntList; for(int iproc=0; iproc localStructList; std::vector expectedStructList; for(int iproc=0; iproc globalStructList; int status = stk::parallel_vector_concat(MPI_COMM_WORLD, localStructList, globalStructList); EXPECT_EQ(status, MPI_SUCCESS); for(unsigned int i=0; i localCharList; std::vector globalCharList(10, 'a'); int status = stk::parallel_vector_concat(MPI_COMM_WORLD, localCharList, globalCharList); EXPECT_EQ(status, MPI_SUCCESS); EXPECT_EQ(globalCharList.size(), (unsigned)0); } // // Test 4, test std::string specialization. Net string should have form: // 0: "PROC |1|" // 1: "PROC |2|" // 2: "PROC |2|" // 3: "PROC |3|" // 4: "PROC |3|" // 5: "PROC |3|" // { std::vector localStringList; std::vector globalStringList; std::vector expectedStringList; for(int iproc=0; iproc localStringList; std::vector globalStringList; std::vector expectedStringList; for(int iproc=0; iproc localVec; for(int i=0; i globalVec; int status = stk::parallel_vector_concat(MPI_COMM_WORLD, localVec, globalVec); EXPECT_EQ(status, MPI_SUCCESS); std::vector expectedVec; for(int iproc=0; iproc