int main() { int A[2][2]={{1,5},{2,4}}; int B[2][2] ; int I, J; printf("Matrice donnee :\n"); afficherM(A); transposer(A,B); printf("Matrice resultat :\n"); afficherM(B); return 0; }
int calcColDiagonalDominance(const RCP<MAT> &A) { TimeMonitor LocalTimer (*timeColDiagonalDominance); Tpetra::RowMatrixTransposer<ST, LO, GO, NT> transposer(A); RCP<MAT> B = transposer.createTranspose(); GO rows = B->getGlobalNumRows(); ST result = 0.0; GO totalMatch, match = 0; GO locEntries = 0; ST locDiagSum = 0.0, locRowSum = 0.0; ST totalDiagSum, totalRowSum; int strict = 1, totalStrict; for (GO row = 0; row < rows; row++) { if (B->getRowMap()->isNodeGlobalElement(row)) { size_t cols = B->getNumEntriesInGlobalRow(row); Array<ST> values(cols); Array<GO> indices(cols); B->getGlobalRowCopy(row, indices(), values(), cols); if (cols < B->getGlobalNumRows()) { totalDiagSum = totalRowSum = 0.0; for (size_t col = 0; col < cols; col++) { if (row == indices[col]) { totalDiagSum += values[col]; } else { totalRowSum += values[col]; } } if (locDiagSum < locRowSum) { //*fos << "col diagonal dominance:0" << std::endl; return 0; } else if (locDiagSum == locRowSum) { strict = 0; } } } } Teuchos::reduceAll(*comm, Teuchos::REDUCE_MAX, 1, &strict, &totalStrict); if (totalStrict == 1) { //*fos << "col diagonal dominance:2" << std::endl; return 2; } else { //*fos << "col diagonal dominance:1" << std::endl; return 1; } }
int main() { int n,i = 0, j = 0; scanf("%d",&n); int transpose[n][n]; for(; i < n; i++) { for(j = 0; j < n; j++) scanf("%d",&transpose[i][j]); printf("\n"); } transposer(&transpose[0][0],n); for(i = 0; i < n; i++) { for(j = 0; j < n; j++) { printf(" %d ", transpose[i][j]); } printf("\n"); } return 0; }
bool LOCA::Epetra::TransposeLinearSystem::ExplicitTranspose:: createJacobianTranspose() { // Get Jacobian Teuchos::RCP<Epetra_RowMatrix> jac = Teuchos::rcp_dynamic_cast<Epetra_RowMatrix>(linsys->getJacobianOperator()); if (jac == Teuchos::null) globalData->locaErrorCheck->throwError( string("LOCA::Epetra::TransposeLinearSystem::ExplicitTranspose::") + string("createJacobianTranspose()"), string("Jacobian operator must be of type Epetra_RowMatrix for ") + string("Explicit Transpose method")); // Form transpose if we haven't already, otherwise just migrate data if (jac_trans == Teuchos::null) jac_trans = Teuchos::rcp(&(transposer(*jac)), false); else transposer.fwd(); return true; }
int main(int argc, char *argv[]) { int i; #ifdef EPETRA_MPI // Initialize MPI MPI_Init(&argc,&argv); Epetra_MpiComm comm(MPI_COMM_WORLD); #else Epetra_SerialComm comm; #endif // Uncomment to debug in parallel int tmp; if (comm.MyPID()==0) cin >> tmp; comm.Barrier(); bool verbose = false; // Check if we should print results to standard out if (argc>1) if (argv[1][0]=='-' && argv[1][1]=='v') verbose = true; if (!verbose) comm.SetTracebackMode(0); // This should shut down any error traceback reporting if (verbose) cout << comm << endl << flush; if (verbose) verbose = (comm.MyPID()==0); if (verbose) cout << EpetraExt::EpetraExt_Version() << endl << endl; int nx = 128; int ny = comm.NumProc()*nx; // Scale y grid with number of processors // Create funky stencil to make sure the matrix is non-symmetric (transpose non-trivial): // (i-1,j-1) (i-1,j ) // (i ,j-1) (i ,j ) (i ,j+1) // (i+1,j-1) (i+1,j ) int npoints = 7; int xoff[] = {-1, 0, 1, -1, 0, 1, 0}; int yoff[] = {-1, -1, -1, 0, 0, 0, 1}; Epetra_Map * map; Epetra_CrsMatrix * A; Epetra_Vector * x, * b, * xexact; Trilinos_Util_GenerateCrsProblem(nx, ny, npoints, xoff, yoff, comm, map, A, x, b, xexact); if (nx<8) { cout << *A << endl; cout << "X exact = " << endl << *xexact << endl; cout << "B = " << endl << *b << endl; } // Construct transposer Epetra_Time timer(comm); double start = timer.ElapsedTime(); //bool IgnoreNonLocalCols = false; bool MakeDataContiguous = true; EpetraExt::RowMatrix_Transpose transposer( MakeDataContiguous ); if (verbose) cout << "\nTime to construct transposer = " << timer.ElapsedTime() - start << endl; Epetra_CrsMatrix & transA = dynamic_cast<Epetra_CrsMatrix&>(transposer(*A)); start = timer.ElapsedTime(); if (verbose) cout << "\nTime to create transpose matrix = " << timer.ElapsedTime() - start << endl; // Now test output of transposer by performing matvecs int ierr = 0; ierr += checkResults(A, &transA, xexact, verbose); // Now change values in original matrix and test update facility of transposer // Add 2 to the diagonal of each row double Value = 2.0; for (i=0; i< A->NumMyRows(); i++) A->SumIntoMyValues(i, 1, &Value, &i); start = timer.ElapsedTime(); transposer.fwd(); if (verbose) cout << "\nTime to update transpose matrix = " << timer.ElapsedTime() - start << endl; ierr += checkResults(A, &transA, xexact, verbose); delete A; delete b; delete x; delete xexact; delete map; if (verbose) cout << endl << "Checking transposer for VbrMatrix objects" << endl<< endl; int nsizes = 4; int sizes[] = {4, 6, 5, 3}; Epetra_VbrMatrix * Avbr; Epetra_BlockMap * bmap; Trilinos_Util_GenerateVbrProblem(nx, ny, npoints, xoff, yoff, nsizes, sizes, comm, bmap, Avbr, x, b, xexact); if (nx<8) { cout << *Avbr << endl; cout << "X exact = " << endl << *xexact << endl; cout << "B = " << endl << *b << endl; } start = timer.ElapsedTime(); EpetraExt::RowMatrix_Transpose transposer1( MakeDataContiguous ); Epetra_CrsMatrix & transA1 = dynamic_cast<Epetra_CrsMatrix&>(transposer1(*Avbr)); if (verbose) cout << "\nTime to create transpose matrix = " << timer.ElapsedTime() - start << endl; // Now test output of transposer by performing matvecs ; ierr += checkResults(Avbr, &transA1, xexact, verbose); // Now change values in original matrix and test update facility of transposer // Scale matrix on the left by rowsums Epetra_Vector invRowSums(Avbr->RowMap()); Avbr->InvRowSums(invRowSums); Avbr->LeftScale(invRowSums); start = timer.ElapsedTime(); transposer1.fwd(); if (verbose) cout << "\nTime to update transpose matrix = " << timer.ElapsedTime() - start << endl; ierr += checkResults(Avbr, &transA1, xexact, verbose); delete Avbr; delete b; delete x; delete xexact; delete bmap; #ifdef EPETRA_MPI MPI_Finalize(); #endif return ierr; }