static Distribution* createDistribution( const IndexType n, CommunicatorPtr comm, int kind ) { Distribution* dist; if ( kind == 0 ) { dist = new BlockDistribution( n, comm ); } else if ( kind == 1 ) { dist = new NoDistribution( n ); } else if ( kind == 2 ) { std::vector<IndexType> localIndexes; IndexType size = comm->getSize(); IndexType rank = comm->getRank(); for ( int k = 0; k < n; k++ ) { if ( k % size == rank ) { localIndexes.push_back(k); } } dist = new GeneralDistribution( n, localIndexes, comm); } else if ( kind == 3 ) { IndexType chunkSize = comm->getSize(); dist = new CyclicDistribution( n, chunkSize, comm); } else { LAMA_THROWEXCEPTION( "kind = " << kind << " unsupported here" ) } return dist; }
BOOST_AUTO_TEST_CASE_TEMPLATE( buildTest, T, test_types ) { typedef T ValueType; PartitionId size = comm->getSize(); int numRows = 3 * size; int numCols = 5 * size; scoped_array<ValueType> values( new ValueType[ numRows * numCols ] ); for ( IndexType i = 0; i < numRows; ++i) { for ( IndexType j = 0; j < numCols; ++j ) { ValueType value = static_cast<ValueType> ( i * numCols + j + 1.0 ); values[ i * numCols + j ] = value; } } DenseMatrix<ValueType> repM; repM.setRawDenseData( numRows, numCols, values.get() ); for ( IndexType i = 0; i < numRows; ++i ) { for ( IndexType j = 0; j<numCols; ++j ) { Scalar value = repM.getValue( i , j ); Scalar expectedvalue = Scalar( static_cast<ValueType>(values[i * numCols + j]) ); LAMA_CHECK_SCALAR_SMALL( value - expectedvalue, ValueType, eps<ValueType>() ); } } shared_ptr<Distribution> dist( new BlockDistribution(numRows, comm) ); shared_ptr<Distribution> distCol( new BlockDistribution(numCols, comm) ); DenseMatrix<ValueType> distM( repM, dist, distCol ); for (IndexType i = 0; i<numRows; ++i) { for (IndexType j = 0; j<numCols; ++j) { Scalar value = distM.getValue( i, j ); Scalar expectedvalue = repM.getValue( i, j ); LAMA_CHECK_SCALAR_SMALL( value - expectedvalue , ValueType, eps<ValueType>() ); } } }
BOOST_AUTO_TEST_CASE_TEMPLATE( testSolveWithoutPreconditioning, T, test_types ) { typedef T ValueType; CommunicatorPtr comm = CommunicatorFactory::get(); // default one testSolveWithoutPreconditionmethod< CSRSparseMatrix<ValueType> >(); testSolveWithoutPreconditionmethod< ELLSparseMatrix<ValueType> >(); testSolveWithoutPreconditionmethod< JDSSparseMatrix<ValueType> >(); testSolveWithoutPreconditionmethod< COOSparseMatrix<ValueType> >(); // ToDo: these tests do not run with multiple processors if ( comm->getSize() <= 1 ) { testSolveWithoutPreconditionmethod< DIASparseMatrix<ValueType> >(); testSolveWithoutPreconditionmethod< DenseMatrix<ValueType> >(); } }
GeneralDistributionTestConfig() { comm = CommunicatorFactory::get( "MPI" ); rank = comm->getRank(); size = comm->getSize(); elemsPerPartition = 10; globalSize = elemsPerPartition * size; for ( IndexType k = 0; k < elemsPerPartition; ++k ) { localIndexes.push_back( k * size + rank ); } dist = DistributionPtr( new GeneralDistribution( globalSize, localIndexes, comm ) ); }
BOOST_AUTO_TEST_CASE_TEMPLATE( multVectorTest, T, test_types ) { typedef T ValueType; int numRows = 20; int numCols = 31; // definition of raw data for setup and comparison scoped_array<ValueType> valuesA( new ValueType[numRows * numCols] ); scoped_array<ValueType> valuesX( new ValueType[numCols] ); scoped_array<ValueType> valuesY( new ValueType[numRows] ); // intialise data for the matrix for ( IndexType i = 0; i<numRows; ++i ) { for ( IndexType j = 0; j<numCols; ++j ) { ValueType value = static_cast<ValueType> ( 100.0 - ::fabs( 2.0 * i - j ) ); valuesA[i * numCols + j] = value; } } // initialize the vector x for ( IndexType j = 0; j < numCols; ++j) { valuesX[j] = static_cast<ValueType> ( 1.2 * ( j + 1 ) ); } // compute Y = A * X for comparison for (IndexType i = 0; i<numRows; ++i) { valuesY[i] = 0.0; for (IndexType j = 0; j<numCols; ++j) { valuesY[i] += static_cast<ValueType> ( valuesA[i*numCols+j]*valuesX[j] ); } } // construct replicated matrix A and vector X to be redistributed DenseMatrix<ValueType> rA; rA.setRawDenseData( numRows, numCols, valuesA.get() ); DenseVector<ValueType> rX( numCols, valuesX.get()); // try different distributions for rows and colums DistributionPtr rowDist; DistributionPtr colDist; for ( int i = 0; i < 4; i++ ) { rowDist = DistributionPtr( createDistribution( numRows, comm, i ) ); for ( int j = 0; j < 4; j++ ) { colDist = DistributionPtr( createDistribution( numCols, comm, j ) ); for ( int k = 0; k < 2; k++ ) { // redistribute A, X, setup result vector Y DenseMatrix<ValueType> A( rA, rowDist, colDist ); DenseVector<ValueType> X( rX, colDist ); if ( k == 0 ) { A.setCommunicationKind( Matrix::SYNCHRONOUS ); } else { A.setCommunicationKind( Matrix::ASYNCHRONOUS ); } LAMA_LOG_INFO( logger, "mult matrix A = " << A << " with vector X = " << X ); DenseVector<ValueType> result ( A * X ); BOOST_REQUIRE_EQUAL( result.size(), numRows ); BOOST_REQUIRE_EQUAL( result.getDistribution(), *rowDist ); // compare the result vector Y with the precomputed results valuesY for ( IndexType m = 0; m < numRows; ++m ) { Scalar value = Scalar( valuesY[m] ); Scalar expectedvalue = result.getValue( m ); //1e-1 is used because there are 8 of 1280 cases which fails with eps<1e-1 LAMA_CHECK_SCALAR_SMALL( value - expectedvalue , ValueType, 1e-1 ); } } } } //Tests for Cyclic Dist speciliatzion in case of a square matrix { PartitionId size = comm->getSize(); IndexType chunkSize = 7; IndexType n = 2 * size * chunkSize; cyclicMultVectorTest( chunkSize, n ); n = 3 * size * chunkSize + chunkSize - 2; cyclicMultVectorTest( chunkSize, n ); //Calculate the size so that each process gets more than one chunk and that not //all chunks have the same numbers of chunks and that we have at least von chunk that is not // square n = 3 * size * chunkSize + size/2 * chunkSize + chunkSize - 2; cyclicMultVectorTest( chunkSize, n ); //not all process get a chunk n = size/2 * chunkSize + chunkSize - 2; cyclicMultVectorTest( chunkSize, n ); } }