Skip to content

Commit

Permalink
zoltan2: Test for MJ with integer coordinates and weights.
Browse files Browse the repository at this point in the history
  • Loading branch information
kddevin committed Jan 17, 2019
1 parent 92a0cd9 commit 428d5f3
Show file tree
Hide file tree
Showing 2 changed files with 203 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/zoltan2/test/partition/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ TRIBITS_ADD_EXECUTABLE_AND_TEST(
FAIL_REGULAR_EXPRESSION "FAIL"
)

# MultiJagged Tests
TRIBITS_ADD_EXECUTABLE_AND_TEST(
mj_int_coordinates
SOURCES mj_int_coordinates.cpp
COMM serial mpi
PASS_REGULAR_EXPRESSION "PASS"
FAIL_REGULAR_EXPRESSION "FAIL"
)

# MultiJagged Tests
TRIBITS_ADD_EXECUTABLE_AND_TEST(
mjTest
Expand Down
194 changes: 194 additions & 0 deletions packages/zoltan2/test/partition/mj_int_coordinates.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
// @HEADER
//
// ***********************************************************************
//
// Zoltan2: A package of combinatorial algorithms for scientific computing
// Copyright 2012 Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// 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:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. 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.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "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 SANDIA CORPORATION OR THE
// 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.
//
// Questions? Contact Karen Devine ([email protected])
// Erik Boman ([email protected])
// Siva Rajamanickam ([email protected])
//
// ***********************************************************************
//
// @HEADER

/*! \file mj_int_coordinates.cpp
\brief Generate a test to partition integer coordinates
See definition of int_scalar_t
*/

#include <Zoltan2_PartitioningSolution.hpp>
#include <Zoltan2_PartitioningProblem.hpp>
#include <Zoltan2_BasicVectorAdapter.hpp>
#include <Zoltan2_InputTraits.hpp>
#include <Tpetra_Map.hpp>
#include <vector>
#include <cstdlib>

int main(int narg, char *arg[])
{
Tpetra::ScopeGuard scope(&narg, &arg);
const Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
int rank = comm->getRank();
int nprocs = comm->getSize();
int nFail = 0;

typedef Tpetra::Map<> Map_t;
typedef Map_t::local_ordinal_type localId_t;
typedef Map_t::global_ordinal_type globalId_t;
typedef int int_scalar_t; // This is the case we are testing here.

typedef Zoltan2::BasicUserTypes<int_scalar_t, localId_t, globalId_t> myTypes;
typedef Zoltan2::BasicVectorAdapter<myTypes> inputAdapter_t;

typedef Zoltan2::EvaluatePartition<inputAdapter_t> quality_t;

///////////////////////////////////////////////////////////////////////
// Create input data.

size_t localCount = 40;
int dim = 3;

// Create coordinates that range from 0 to 9
int_scalar_t *coords = new int_scalar_t [dim * localCount];
int_scalar_t *x = coords;
int_scalar_t *y = x + localCount;
int_scalar_t *z = y + localCount;

srand(rank);
for (size_t i=0; i < localCount*dim; i++)
coords[i] = int_scalar_t(rand() / (double)RAND_MAX) % 10;

// Create global ids for the coordinates.
globalId_t *globalIds = new globalId_t [localCount];
globalId_t offset = rank * localCount;
for (size_t i=0; i < localCount; i++) globalIds[i] = offset++;

///////////////////////////////////////////////////////////////////////
// Create parameters for an MJ problem

Teuchos::ParameterList params("test params");
params.set("debug_level", "basic_status");
params.set("error_check_level", "debug_mode_assertions");

params.set("algorithm", "multijagged");
params.set("num_global_parts", nprocs);

///////////////////////////////////////////////////////////////////////
// Test one: No weights

inputAdapter_t *ia1 = new inputAdapter_t(localCount,globalIds,x,y,z,1,1,1);

Zoltan2::PartitioningProblem<inputAdapter_t> *problem1 =
new Zoltan2::PartitioningProblem<inputAdapter_t>(ia1, &params);

problem1->solve();

quality_t *metricObject1 = new quality_t(ia1, &params, comm,
&problem1->getSolution());
if (rank == 0){

metricObject1->printMetrics(std::cout);

double imb = metricObject1->getObjectCountImbalance();
if (imb <= 1.01) // Should get perfect balance
std::cout << "no weights -- balance satisfied: " << imb << std::endl;
else {
std::cout << "no weights -- balance failure: " << imb << std::endl;
nFail++;
}
std::cout << std::endl;
}
delete metricObject1;
delete problem1;
delete ia1;

///////////////////////////////////////////////////////////////////////
// Test two: weighted
// Create a Zoltan2 input adapter that includes weights.

int_scalar_t *weights = new int_scalar_t [localCount];
for (size_t i=0; i < localCount; i++) weights[i] = 1 + int_scalar_t(rank);

std::vector<const int_scalar_t *>coordVec(3);
std::vector<int> coordStrides(3);

coordVec[0] = x; coordStrides[0] = 1;
coordVec[1] = y; coordStrides[1] = 1;
coordVec[2] = z; coordStrides[2] = 1;

std::vector<const int_scalar_t *>weightVec(1);
std::vector<int> weightStrides(1);

weightVec[0] = weights; weightStrides[0] = 1;

inputAdapter_t *ia2=new inputAdapter_t(localCount, globalIds, coordVec,
coordStrides,weightVec,weightStrides);

Zoltan2::PartitioningProblem<inputAdapter_t> *problem2 =
new Zoltan2::PartitioningProblem<inputAdapter_t>(ia2, &params);

problem2->solve();

quality_t *metricObject2 = new quality_t(ia2, &params, comm,
&problem2->getSolution());
if (rank == 0){

metricObject2->printMetrics(std::cout);

double imb = metricObject2->getWeightImbalance(0);
if (imb <= 1.01)
std::cout << "weighted -- balance satisfied " << imb << std::endl;
else {
std::cout << "weighted -- balance failed " << imb << std::endl;
nFail++;
}
std::cout << std::endl;
}
delete metricObject2;

if (weights) delete [] weights;
if (coords) delete [] coords;
if (globalIds) delete [] globalIds;
delete problem2;
delete ia2;

if (rank == 0) {
if (nFail == 0) std::cout << "PASS" << std::endl;
else std::cout << "FAIL: " << nFail << " tests failed" << std::endl;
}

return 0;
}

0 comments on commit 428d5f3

Please sign in to comment.