/* //@HEADER //************************************************************************ // // Isorropia: Partitioning and Load Balancing Package // Copyright (2006) Sandia Corporation // //Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive //license for use of this work by or on behalf of the U.S. Government. // // 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. // //************************************************************************ //@HEADER */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define SUCCESS 0 #define FAIL 1 #ifdef HAVE_MPI #include #endif #ifdef EPETRA_MPI #include #else #include #endif #include #include #include #include /////////////////////////////////////// // Answers /////////////////////////////////////// int blockAnswer2[100] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; int blockAnswer4[100] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}; int cyclicAnswer2[100] = {0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0, 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1, 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0, 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1}; int cyclicAnswer4[100] = {0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0, 1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1, 2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2, 3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3}; /////////////////////////////////////// int getMatrixDim(char *mmfilename, Epetra_Comm &comm, int *N, int *M, int *nnz); int read_matrixmarket_linear(const char *, Epetra_Comm &, Epetra_CrsMatrix *&); bool testPartitioningMVRCPInput(Teuchos::RCP mv, const char *method, int worldsize, int myrank); bool testPartitioningMVPtrInput(const Epetra_MultiVector *mv, const char *method, int worldsize, int myrank); bool testPartitioningMatrixRCPInput(Teuchos::RCP mat, const char *method, int worldsize, int myrank); bool testPartitioningMatrixPtrInput(const Epetra_CrsMatrix *mat, const char *method, int worldsize, int myrank); bool testPartitioningMapRCPInput(Teuchos::RCP map, const char *method, int worldsize, int myrank); bool testPartitioningMapPtrInput(const Epetra_BlockMap *map, const char *method, int worldsize, int myrank); bool checkPartition1(const Isorropia::Epetra::Partitioner &partitioner); bool checkPartition2(const Isorropia::Epetra::Partitioner &partitioner, const Epetra_BlockMap &map, const char* method); bool checkPartition4(const Isorropia::Epetra::Partitioner &partitioner, const Epetra_BlockMap &map, const char* method); //////////////////////////////////////////////////////////////////////////////// // Testing simple methods with Multivector //////////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { #ifdef EPETRA_MPI MPI_Init(&argc,&argv); Epetra_MpiComm Comm(MPI_COMM_WORLD); #else Epetra_SerialComm Comm; #endif Epetra_CrsMatrix *A; int worldsize = Comm.NumProc(); int myrank = Comm.MyPID(); bool success = true; ///////////////////////////////////////////////////////////// /// Read and distribute matrices ///////////////////////////////////////////////////////////// read_matrixmarket_linear("arrow100.mtx",Comm,A); ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// // Test partitioning with matrix ptr input ///////////////////////////////////////////////////////////// success = success && testPartitioningMatrixPtrInput(A,"BLOCK",worldsize,myrank); success = testPartitioningMatrixPtrInput(A,"CYCLIC",worldsize,myrank) && success; // test lhs of && so it is run ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// // Test partitioning with matrix rcp input ///////////////////////////////////////////////////////////// Teuchos::RCP rowmatrix = Teuchos::rcp(A); success = testPartitioningMatrixRCPInput(rowmatrix,"BLOCK",worldsize,myrank) && success; success = testPartitioningMatrixRCPInput(rowmatrix,"CYCLIC",worldsize,myrank) && success; // test lhs of && so it is run ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// // Test partitioning with multivector ptr input ///////////////////////////////////////////////////////////// const Epetra_MultiVector *mvPtr = new Epetra_MultiVector(A->RowMap(),1); success = testPartitioningMVPtrInput(mvPtr,"BLOCK",worldsize,myrank) && success; success = testPartitioningMVPtrInput(mvPtr,"CYCLIC",worldsize,myrank) && success; ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// // Test partitioning with multivector rcp input ///////////////////////////////////////////////////////////// Teuchos::RCP mv = Teuchos::rcp(mvPtr); success = testPartitioningMVRCPInput(mv,"BLOCK",worldsize,myrank) && success; success = testPartitioningMVRCPInput(mv,"CYCLIC",worldsize,myrank) && success; ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// // Test partitioning with BlockMap ptr input ///////////////////////////////////////////////////////////// const Epetra_BlockMap *mapPtr = &(A->RowMap()); success = testPartitioningMapPtrInput(mapPtr,"BLOCK",worldsize,myrank) && success; success = testPartitioningMapPtrInput(mapPtr,"CYCLIC",worldsize,myrank) && success; ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// // Test partitioning with BlockMap rcp input ///////////////////////////////////////////////////////////// Teuchos::RCP map = Teuchos::rcp(mapPtr,false); success = testPartitioningMapRCPInput(map,"BLOCK",worldsize,myrank) && success; success = testPartitioningMapRCPInput(map,"CYCLIC",worldsize,myrank) && success; ///////////////////////////////////////////////////////////// #ifdef EPETRA_MPI MPI_Finalize(); #endif if(!success) { return FAIL; } return(SUCCESS); } //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// bool testPartitioningMVRCPInput(Teuchos::RCP mv, const char *method, int worldsize, int myrank) { bool success=true; ///////////////////////////////////////////////////////////// // Partition ///////////////////////////////////////////////////////////// Teuchos::ParameterList paramlist; paramlist.set("IMBALANCE TOL","1.03"); if(strcmp(method,"BLOCK")==0) { paramlist.set("PARTITIONING_METHOD", "BLOCK"); } else if(strcmp(method,"CYCLIC")==0) { paramlist.set("PARTITIONING_METHOD", "CYCLIC"); } else { if(myrank==0) { std::cout << "Error in testPartitionMVInput() with method argument " << method << "." << std::endl << " Method must be 'BLOCK' or 'CYCLIC'" << std::endl; } return(false); } Isorropia::Epetra::Partitioner partitioner(mv, paramlist, false); partitioner.partition(); ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// /// Check partition ///////////////////////////////////////////////////////////// if (worldsize==1) { success = checkPartition1(partitioner); } else if (worldsize==2) { success = checkPartition2(partitioner,mv->Map(),method); } else if (worldsize==4) { success = checkPartition4(partitioner,mv->Map(),method); } else { if(myrank==0) { std::cout << "WARNING for testPartitionMVInput() with number of processors = " << worldsize << std::endl << " Number of processes not supported .... (by default) returning success" << std::endl; } } if(myrank==0) { if (success == false) { std::cout << "Failure in testPartitionMVInput(), method argument " << method << ", numProcs = " << worldsize << std::endl; } else { std::cout << "Success in testPartitionMVInput(), method argument " << method << ", numProcs = " << worldsize << std::endl; } } ///////////////////////////////////////////////////////////// return success; } //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// bool testPartitioningMVPtrInput(const Epetra_MultiVector *mv, const char *method, int worldsize, int myrank) { bool success=true; ///////////////////////////////////////////////////////////// // Partition ///////////////////////////////////////////////////////////// Teuchos::ParameterList paramlist; paramlist.set("IMBALANCE TOL","1.03"); if(strcmp(method,"BLOCK")==0) { paramlist.set("PARTITIONING_METHOD", "BLOCK"); } else if(strcmp(method,"CYCLIC")==0) { paramlist.set("PARTITIONING_METHOD", "CYCLIC"); } else { if(myrank==0) { std::cout << "Error in testPartitionMVInput() with method argument " << method << "." << std::endl << " Method must be 'BLOCK' or 'CYCLIC'" << std::endl; } return(false); } Isorropia::Epetra::Partitioner partitioner(mv, paramlist, false); partitioner.partition(); ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// /// Check partition ///////////////////////////////////////////////////////////// if (worldsize==1) { success = checkPartition1(partitioner); } else if (worldsize==2) { success = checkPartition2(partitioner,mv->Map(),method); } else if (worldsize==4) { success = checkPartition4(partitioner,mv->Map(),method); } else { if(myrank==0) { std::cout << "WARNING for testPartitionMVInput() with number of processors = " << worldsize << std::endl << " Number of processes not supported .... (by default) returning success" << std::endl; } } if(myrank==0) { if (success == false) { std::cout << "Failure in testPartitionMVInput(), method argument " << method << ", numProcs = " << worldsize << std::endl; } else { std::cout << "Success in testPartitionMVInput(), method argument " << method << ", numProcs = " << worldsize << std::endl; } } ///////////////////////////////////////////////////////////// return success; } //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// bool testPartitioningMatrixRCPInput(Teuchos::RCP mat, const char *method, int worldsize, int myrank) { bool success=true; ///////////////////////////////////////////////////////////// // Partition ///////////////////////////////////////////////////////////// Teuchos::ParameterList paramlist; paramlist.set("IMBALANCE TOL","1.03"); if(strcmp(method,"BLOCK")==0) { paramlist.set("PARTITIONING_METHOD", "BLOCK"); } else if(strcmp(method,"CYCLIC")==0) { paramlist.set("PARTITIONING_METHOD", "CYCLIC"); } else { if(myrank==0) { std::cout << "Error in testPartitionMatrixInput() with method argument " << method << "." << std::endl << " Method must be 'BLOCK' or 'CYCLIC'" << std::endl; } return(false); } Isorropia::Epetra::Partitioner partitioner(mat, paramlist, false); partitioner.partition(); ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// /// Check partition ///////////////////////////////////////////////////////////// if (worldsize==1) { success = checkPartition1(partitioner); } else if (worldsize==2) { success = checkPartition2(partitioner,mat->Map(),method); } else if (worldsize==4) { success = checkPartition4(partitioner,mat->Map(),method); } else { if(myrank==0) { std::cout << "WARNING for testPartitionMatrixInput() with number of processors = " << worldsize << std::endl << " Number of processes not supported .... (by default) returning success" << std::endl; } } if(myrank==0) { if (success == false) { std::cout << "Failure in testPartitionMatrixInput(), method argument " << method << ", numProcs = " << worldsize << std::endl; } else { std::cout << "Success in testPartitionMatrixInput(), method argument " << method << ", numProcs = " << worldsize << std::endl; } } ///////////////////////////////////////////////////////////// return success; } //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// bool testPartitioningMatrixPtrInput(const Epetra_CrsMatrix *mat, const char *method, int worldsize, int myrank) { bool success=true; ///////////////////////////////////////////////////////////// // Partition ///////////////////////////////////////////////////////////// Teuchos::ParameterList paramlist; paramlist.set("IMBALANCE TOL","1.03"); if(strcmp(method,"BLOCK")==0) { paramlist.set("PARTITIONING_METHOD", "BLOCK"); } else if(strcmp(method,"CYCLIC")==0) { paramlist.set("PARTITIONING_METHOD", "CYCLIC"); } else { if(myrank==0) { std::cout << "Error in testPartitionMatrixInput() with method argument " << method << "." << std::endl << " Method must be 'BLOCK' or 'CYCLIC'" << std::endl; } return(false); } Isorropia::Epetra::Partitioner partitioner(mat, paramlist, false); partitioner.partition(); ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// /// Check partition ///////////////////////////////////////////////////////////// if (worldsize==1) { success = checkPartition1(partitioner); } else if (worldsize==2) { success = checkPartition2(partitioner,mat->Map(),method); } else if (worldsize==4) { success = checkPartition4(partitioner,mat->Map(),method); } else { if(myrank==0) { std::cout << "WARNING for testPartitionMatrixInput() with number of processors = " << worldsize << std::endl << " Number of processes not supported .... (by default) returning success" << std::endl; } } if(myrank==0) { if (success == false) { std::cout << "Failure in testPartitionMatrixInput(), method argument " << method << ", numProcs = " << worldsize << std::endl; } else { std::cout << "Success in testPartitionMatrixInput(), method argument " << method << ", numProcs = " << worldsize << std::endl; } } ///////////////////////////////////////////////////////////// return success; } //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// bool testPartitioningMapRCPInput(Teuchos::RCP map, const char *method, int worldsize, int myrank) { bool success=true; ///////////////////////////////////////////////////////////// // Partition ///////////////////////////////////////////////////////////// Teuchos::ParameterList paramlist; paramlist.set("IMBALANCE TOL","1.03"); if(strcmp(method,"BLOCK")==0) { paramlist.set("PARTITIONING_METHOD", "BLOCK"); } else if(strcmp(method,"CYCLIC")==0) { paramlist.set("PARTITIONING_METHOD", "CYCLIC"); } else { if(myrank==0) { std::cout << "Error in testPartitionMapInput() with method argument " << method << "." << std::endl << " Method must be 'BLOCK' or 'CYCLIC'" << std::endl; } return(false); } Isorropia::Epetra::Partitioner partitioner(map, paramlist, false); partitioner.partition(); ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// /// Check partition ///////////////////////////////////////////////////////////// if (worldsize==1) { success = checkPartition1(partitioner); } else if (worldsize==2) { success = checkPartition2(partitioner,*map, method); } else if (worldsize==4) { success = checkPartition4(partitioner,*map, method); } else { if(myrank==0) { std::cout << "WARNING for testPartitionMapInput() with number of processors = " << worldsize << std::endl << " Number of processes not supported .... (by default) returning success" << std::endl; } } if(myrank==0) { if (success == false) { std::cout << "Failure in testPartitionMapInput(), method argument " << method << ", numProcs = " << worldsize << std::endl; } else { std::cout << "Success in testPartitionMapInput(), method argument " << method << ", numProcs = " << worldsize << std::endl; } } ///////////////////////////////////////////////////////////// return success; } //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// bool testPartitioningMapPtrInput(const Epetra_BlockMap *map, const char *method, int worldsize, int myrank) { bool success=true; ///////////////////////////////////////////////////////////// // Partition ///////////////////////////////////////////////////////////// Teuchos::ParameterList paramlist; paramlist.set("IMBALANCE TOL","1.03"); if(strcmp(method,"BLOCK")==0) { paramlist.set("PARTITIONING_METHOD", "BLOCK"); } else if(strcmp(method,"CYCLIC")==0) { paramlist.set("PARTITIONING_METHOD", "CYCLIC"); } else { if(myrank==0) { std::cout << "Error in testPartitionMapInput() with method argument " << method << "." << std::endl << " Method must be 'BLOCK' or 'CYCLIC'" << std::endl; } return(false); } Isorropia::Epetra::Partitioner partitioner(map, paramlist, false); partitioner.partition(); ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// /// Check partition ///////////////////////////////////////////////////////////// if (worldsize==1) { success = checkPartition1(partitioner); } else if (worldsize==2) { success = checkPartition2(partitioner,*map, method); } else if (worldsize==4) { success = checkPartition4(partitioner,*map, method); } else { if(myrank==0) { std::cout << "WARNING for testPartitionMapInput() with number of processors = " << worldsize << std::endl << " Number of processes not supported .... (by default) returning success" << std::endl; } } if(myrank==0) { if (success == false) { std::cout << "Failure in testPartitionMapInput(), method argument " << method << ", numProcs = " << worldsize << std::endl; } else { std::cout << "Success in testPartitionMapInput(), method argument " << method << ", numProcs = " << worldsize << std::endl; } } ///////////////////////////////////////////////////////////// return success; } //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// bool checkPartition1(const Isorropia::Epetra::Partitioner &partitioner) { int numRows = 100; for(int i=0;i> tmp[0] >> tmp[1] >> tmp[2]; mm.close(); } } comm.Broadcast(tmp, 3, 0); *N = tmp[0]; *M = tmp[1]; *nnz = tmp[2]; if (*N < 1 || *M < 1 || *N != *M) { if (comm.MyPID()==0) { cout << "getMatrixDim: Invalid input in matrix " << mmfilename << endl; cout << "getMatrixDim: N=" << *N << " M=" << *M << " nnz=" << *nnz << endl; } aok = 0; } return aok; } ////////////////////////////////////////////////////////////////////////////