/*--------------------------------------------------------------------------------*/ bool XMLADMData::ReadChnaFromFile(const std::string& filename, bool finalise) { EnhancedFile fp; bool success = false; if (fp.fopen(filename.c_str())) { char buffer[1024]; int l; success = true; while (success && ((l = fp.readline(buffer, sizeof(buffer) - 1)) != EOF)) { if (l > 0) { std::vector<std::string> words; SplitString(std::string(buffer), words); if (words.size() == 4) { uint_t tracknum; if (Evaluate(words[0], tracknum)) { if (tracknum) { const std::string& trackuid = words[1]; const std::string& trackformat = words[2]; const std::string& packformat = words[3]; ADMAudioTrack *track; std::string id; if ((track = dynamic_cast<ADMAudioTrack *>(Create(ADMAudioTrack::Type, trackuid, ""))) != NULL) { XMLValue tvalue, pvalue; track->SetTrackNum(tracknum - 1); tvalue.name = ADMAudioTrackFormat::Reference; tvalue.value = trackformat; track->AddValue(tvalue); pvalue.name = ADMAudioPackFormat::Reference; pvalue.value = packformat; track->AddValue(pvalue); track->SetValues(); BBCDEBUG2(("Track %u: Index %u UID '%s' TrackFormatRef '%s' PackFormatRef '%s'", (uint_t)tracklist.size(), track->GetTrackNum() + 1, track->GetID().c_str(), tvalue.value.c_str(), pvalue.value.c_str())); } else { BBCERROR("Failed to create AudioTrack for UID %u", tracknum); success = false; } } } else { BBCERROR("CHNA line '%s' word 1 ('%s') should be a track number", buffer, words[0].c_str()); success = false; } } else { BBCERROR("CHNA line '%s' requires 4 words", buffer); success = false; } } } fp.fclose(); if (success && finalise) Finalise(); } return success; }
//--------------------------------------------------------- bool CSADO_SolarRadiation::Get_Insolation(void) { //----------------------------------------------------- if( Initialise() ) { if( m_bMoment ) { Get_Insolation(m_Day_A, m_Hour); Finalise(); } //------------------------------------------------- else { for(int Day=m_Day_A; Day<=m_Day_B && Process_Get_Okay(false); Day+=m_dDays) { for(double Hour=m_Hour; Hour<24.0 && Process_Get_Okay(false); Hour+=m_dHour) { Process_Set_Text(CSG_String::Format(SG_T("%s: %d(%d-%d), %s: %f"), _TL("Day"), Day, m_Day_A, m_Day_B, _TL("Hour"), Hour)); if( m_bUpdateDirect ) m_pSumDirect->Assign(0.0); if( m_bUpdateDiffus ) m_pSumDiffus->Assign(0.0); if( m_bUpdateTotal ) m_pSumTotal ->Assign(0.0); if( Get_Insolation(Day, Hour) ) { if( m_bUpdateDirect ) { m_TmpDirect += *m_pSumDirect; DataObject_Update(m_pSumDirect); } if( m_bUpdateDiffus ) { m_TmpDiffus += *m_pSumDiffus; DataObject_Update(m_pSumDiffus); } if( m_bUpdateTotal ) { m_TmpTotal += *m_pSumTotal; DataObject_Update(m_pSumTotal); } } } } Finalise(m_dHour / (24.0 * (1 + m_Day_B - m_Day_A))); // *m_pSumDirect *= m_dHour / D->size(); } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------------------------------- void MainL(void) { test.Start(_L("Kern Perf Logger tests")); Initialise(); RBTrace trace; TInt error = trace.Open(); test(error == KErrNone); trace.Empty(); trace.SetFilter(BTrace::EThreadIdentification,0); //-- actually, for hardware platforms, the testing category and trace enabling //-- may be set up in appropriate "header.iby" file trace.SetMode(RBTrace::EEnable); trace.SetFilter(BTrace::EKernPerfLog, ETrue); //-- unit-test for PERF_LOG macros TestMacros(trace); //-- functionality test TestPerfLogger(trace); trace.Close(); Finalise(); test.End(); }
void PetscMatTools::ZeroColumn(Mat matrix, PetscInt col) { Finalise(matrix); PetscInt lo, hi; GetOwnershipRange(matrix, lo, hi); // Determine which rows in this column are non-zero (and therefore need to be zeroed) std::vector<unsigned> nonzero_rows; for (PetscInt row = lo; row < hi; row++) { if (GetElement(matrix, row, col) != 0.0) { nonzero_rows.push_back(row); } } // Set those rows to be zero by calling MatSetValues unsigned size = nonzero_rows.size(); PetscInt* rows = new PetscInt[size]; PetscInt cols[1]; double* zeros = new double[size]; cols[0] = col; for (unsigned i=0; i<size; i++) { rows[i] = nonzero_rows[i]; zeros[i] = 0.0; } MatSetValues(matrix, size, rows, 1, cols, zeros, INSERT_VALUES); delete [] rows; delete [] zeros; }
int main(int argc, char* argv[]) { if( Initialize() ) { #ifdef DAEDALUS_BATCH_TEST_ENABLED if( argc > 1 ) { BatchTestMain( argc, argv ); } #else //Makes it possible to load a ROM directly without using the GUI //There are no checks for wrong file name so be careful!!! //Ex. from PSPLink -> ./Daedalus.prx "Roms/StarFox 64.v64" //Corn if( argc > 1 ) { printf("Loading %s\n", argv[1] ); System_Open( argv[1] ); CPU_Run(); System_Close(); Finalise(); sceKernelExitGame(); return 0; } #endif //Translate_Init(); bool show_splash = true; for(;;) { DisplayRomsAndChoose( show_splash ); show_splash = false; // // Commit the preferences and roms databases before starting to run // CRomDB::Get()->Commit(); CPreferences::Get()->Commit(); CPU_Run(); System_Close(); } Finalise(); } sceKernelExitGame(); return 0; }
/*++ ExitHandler Cleans up library on exit, frees all state structures for every interpreter this extension was loaded in. Arguments: dummy - Not used. Return Value: None. --*/ static void ExitHandler( ClientData dummy ) { DebugPrint("ExitHandler: none\n"); Finalise(0); }
void Shutdown() { static CCriticalSection cs_Shutdown; TRY_LOCK(cs_Shutdown, lockShutdown); if (!lockShutdown) return; Finalise(); LogPrintf("Shutdown complete.\n\n"); }
bool Statement::Execute() { int Err = sqlite3_step(Inner); if (Err != SQLITE_DONE) { Finalise(); return LogError(sqlite3_errstr(Err), false); } return true; }
void Skeleton::Serialise(serialise::Archive& archive) { archive.Serialise(mBones); //If serialising in, finalise skeleton if(archive.GetDirection() == serialise::Archive::In) { Finalise(); } }
/*! \brief Transition has completed */ void Transition::Finished() { // Hide old image before it is reset m_old->SetVisible(false); // Undo transition effects Finalise(); LOG(VB_FILE, LOG_DEBUG, LOC + QString("Finished transition to %1").arg(m_new->objectName())); emit finished(); }
bool Statement::Prepare(sqlite3 * const Database, const std::string &Query) { Inner = nullptr; int Err = sqlite3_prepare_v2(Database, Query.c_str(), -1, &Inner, nullptr); if (Err != SQLITE_OK) { Finalise(); LogError("Failed to prepare statement with query \"" + Query + "\"."); LogError(sqlite3_errstr(Err), false); return false; } return true; }
bool Statement::BindNull(const std::string &Name) { if (Inner == nullptr) return false; int Err = sqlite3_bind_null(Inner, sqlite3_bind_parameter_index(Inner, Name.c_str())); if (Err != SQLITE_OK) { Finalise(); LogError("Failed to bind NULL value to statement variable \"" + Name + "\"."); return LogError(sqlite3_errstr(Err), false); } return true; }
bool Statement::Bind(const std::string &Name, const std::string &Value) { if (Inner == nullptr) return false; int Err = sqlite3_bind_text(Inner, sqlite3_bind_parameter_index(Inner, Name.c_str()), Value.c_str(), -1, SQLITE_TRANSIENT); if (Err != SQLITE_OK) { Finalise(); LogError("Failed to bind value \"" + Value + "\" to statement variable \"" + Name + "\"."); return LogError(sqlite3_errstr(Err), false); } return true; }
/*--------------------------------------------------------------------------------*/ bool XMLADMData::SetAxml(const std::string& data, bool finalise) { bool success = false; BBCDEBUG3(("Read XML:\n%s", data.c_str())); if (TranslateXML(data.c_str())) { if (finalise) Finalise(); success = true; } return success; }
/*++ Alcoext_Unload Unloads the extension from a process or interpreter. Arguments: interp - Current interpreter. flags - Type of detachment. Return Value: A standard Tcl result. --*/ int Alcoext_Unload( Tcl_Interp *interp, int flags ) { DebugPrint("Unload: interp=%p flags=%d\n", interp, flags); if (flags == TCL_UNLOAD_DETACH_FROM_INTERPRETER) { ExtState *state; Tcl_MutexLock(&stateListMutex); for (state = stateHead; state != NULL; state = state->next) { if (interp == state->interp) { // Remove the interpreter's state from the list. if (state->next != NULL) { state->next->prev = state->prev; } if (state->prev != NULL) { state->prev->next = state->next; } if (stateHead == state) { stateHead = state->next; } FreeState(state, 1, 1); break; } } Tcl_MutexUnlock(&stateListMutex); } else if (flags == TCL_UNLOAD_DETACH_FROM_PROCESS) { // Remove registered exit handlers. Tcl_DeleteExitHandler(ExitHandler, NULL); Finalise(1); } else { // Unknown flags value. return TCL_ERROR; } // Unregister the package (there is no Tcl_PkgForget(), or similar). Tcl_Eval(interp, "package forget " PACKAGE_NAME); return TCL_OK; }
//--------------------------------------------------------- bool CFlow_AreaUpslope::Initialise(int Method, CSG_Grid *pDTM, CSG_Grid *pRoute, CSG_Grid *pFlow, double MFD_Converge) { Finalise(); if( pDTM && pDTM->is_Valid() && pFlow && pFlow->is_Valid() && pFlow->Get_System() == pDTM->Get_System() ) { m_Method = Method; m_pDTM = pDTM; m_pFlow = pFlow; m_MFD_Converge = MFD_Converge; if( pRoute && pRoute->is_Valid() && pRoute->Get_System() == pDTM->Get_System() ) { m_pRoute = pRoute; } return( true ); } return( false ); }
void CSkin::Apply() { CreateDefault(); Finalise(); }
// The dtor. ScintillaQt::~ScintillaQt() { Finalise(); }
// The dtor. QsciScintillaQt::~QsciScintillaQt() { Finalise(); }
//--------------------------------------------------------- CFlow_AreaUpslope::~CFlow_AreaUpslope(void) { Finalise(); }
Statement::~Statement() { Finalise(); }
void mpi_manager_3D::setup(NumArray<int> &nproc, NumArray<int> &mx) { // Save number of processors in each dimension for(int dir=0; dir<DIM; ++dir) { this->nproc[dir] = nproc[dir]; } // Determine the rank of the current task MPI_Comm_rank(MPI_COMM_WORLD, &rank); // Get number of ranks from MPI int ntasks; MPI_Comm_size(MPI_COMM_WORLD, &ntasks); this->ntasks = ntasks; // Set the distribution of processes: if(ntasks != nproc[0]*nproc[1]*nproc[2]){ std::cerr << " Wrong number of processes " << std::endl; std::cout << ntasks << " " << nproc[0]*nproc[1]*nproc[2] << std::endl; Finalise(); } if(rank==0) { std::cout << " Number of tasks: " << ntasks << std::endl; } // Check if grid can be subdevided as desired for(int dir = 0; dir < DIM; ++dir) { if(mx[dir] < nproc[dir] && nproc[dir] > 1) { if(rank == 0) { std::cerr << " Wrong grid topology for dimension "; std::cerr << dir << std::endl; std::cerr << " mx[" << dir << "]:" << mx[dir] << std::endl; std::cerr << " nproc[" << dir << "]:" << nproc[dir] << std::endl; } Finalise(); } } // Check if grid is a power of 2: double eps = 1.e-12; for(int dir = 0; dir < DIM; ++dir) { double exponent = log(mx[dir])/log(2.); int i_exponent = static_cast<int>(exponent+eps); if(exponent - i_exponent > 2.*eps) { if(rank == 0) { std::cerr << " Error: grid must be of the form mx = 2^n "; std::cerr << std::endl; std::cerr << " Exiting " << std::endl; } Finalise(); } } // Grid is not periodic int periods[3] = {false, false, false}; int reorder = false; // If all is okay: Create new communicator "comm3d" MPI_Cart_create(MPI_COMM_WORLD, DIM, nproc, periods, reorder, &comm3d); // Retrieve the cartesian topology if (rank == 0) { int TopoType; std::cout << " Cart topology: "; MPI_Topo_test(comm3d, &TopoType); switch (TopoType) { case MPI_UNDEFINED : std::cout << " MPI_UNDEFINED " << std::endl; break; case MPI_GRAPH : std::cout << "MPI_GRAPH" << std::endl; break; case MPI_CART : std::cout << "MPI_CART" << std::endl; break; } } // Determine rank again for cartesian communicator -> overwrite rank MPI_Comm_rank(comm3d, &rank); // std::cout << " my rank: " << rank << std::endl; // Translate rank to coordinates MPI_Cart_coords(comm3d, rank, DIM, coords); // // Backwards translation // int TranslateRank; // MPI_Cart_rank(comm3d, coords, &TranslateRank); // Find neighbouring ranks // Syntax: comm3d, shift direction, displacement, source, destination MPI_Cart_shift(comm3d, 0, 1, &left , &right); MPI_Cart_shift(comm3d, 1, 1, &front, &back); MPI_Cart_shift(comm3d, 2, 1, &bottom, &top); // std::cout << " My rank " << rank << " " << left << " " << right << " " << front << " " << back << " " << bottom << " " << top << std::endl; if(rank==0) { std::cout << " nearby " << right << " " << back << " " << top << std::endl; } // Determine ranks of neighbour processes: int shiftcoord[DIM]; int lbound[DIM],ubound[DIM]; for(int dim=0;dim<DIM;dim++){ lbound[dim]=-1; ubound[dim]= 1; } Neighbour.resize(lbound,ubound); Neighbour.clear(); for(int dim0=-1; dim0<=1; dim0++){ shiftcoord[0] = (coords[0]+dim0)%nproc[0]; if(shiftcoord[0] < 0) shiftcoord[0]+=nproc[0]; for(int dim1=-1; dim1<=1; dim1++){ shiftcoord[1] = (coords[1]+dim1)%nproc[1]; if(shiftcoord[1] < 0) shiftcoord[1]+=nproc[1]; for(int dim2=-1; dim2<=1; dim2++){ shiftcoord[2] = (coords[2]+dim2)%nproc[2]; if(shiftcoord[2] < 0) shiftcoord[2]+=nproc[2]; MPI_Cart_rank(comm3d, shiftcoord,&Neighbour(dim0,dim1,dim2)); } } } // if(rank==1) { // for(int dim0=-1; dim0<=1; dim0++){ // for(int dim1=-1; dim1<=1; dim1++){ // for(int dim2=-1; dim2<=1; dim2++){ // std::cout << " neighbour " << dim0 << " " << dim1 << " "; // std::cout << dim2 << " " << Neighbour(dim0, dim1, dim2); // std::cout << std::endl; // } // } // } // } // Determine absolute position of any rank: AllRanks.resize(Index::set(0,0,0), Index::set(nproc[0]-1,nproc[1]-1,nproc[2]-1)); for(int dim0=0; dim0<nproc[0]; ++dim0) { for(int dim1=0; dim1<nproc[1]; ++dim1) { for(int dim2=0; dim2<nproc[2]; ++dim2) { int coord[3] = {dim0, dim1, dim2}; MPI_Cart_rank(comm3d, coord, &AllRanks(dim0, dim1, dim2)); } } } // if(rank==2) { // std::cout << " Neigh: " << rank << " "<<Neighbour(0,0,0) << " " << AllRanks(2,0,0) << std::endl; // } // Now make additional mpi groups relating to planes: int count(0); int num_xy = nproc[0]*nproc[1]; int num_xz = nproc[0]*nproc[2]; int num_yz = nproc[1]*nproc[2]; NumMatrix<int,1> x_ranks[nproc[0]]; NumMatrix<int,1> y_ranks[nproc[1]]; NumMatrix<int,1> z_ranks[nproc[2]]; // Walk trough z-axis -- xy plane for(int irz=0; irz<nproc[2]; irz++) { count = 0; z_ranks[irz].resize(Index::set(0), Index::set(num_xy)); for(int irx=0; irx<nproc[0]; irx++) { for(int iry=0; iry<nproc[1]; iry++) { z_ranks[irz](count) = AllRanks(irx,iry,irz); count++; } } } // Walk trough y-axis -- xz plane for(int iry=0; iry<nproc[1]; iry++) { count = 0; y_ranks[iry].resize(Index::set(0), Index::set(num_xz)); for(int irx=0; irx<nproc[0]; irx++) { for(int irz=0; irz<nproc[2]; irz++) { y_ranks[iry](count) = AllRanks(irx,iry,irz); count++; } } } // Walk trough x-axis -- yz plane for(int irx=0; irx<nproc[0]; irx++) { count = 0; x_ranks[irx].resize(Index::set(0), Index::set(num_yz)); for(int iry=0; iry<nproc[1]; iry++) { for(int irz=0; irz<nproc[2]; irz++) { x_ranks[irx](count) = AllRanks(irx,iry,irz); count++; } } } // Build local communicator: MPI_Group group_all, group_constz, group_consty, group_constx; // Get standard group handle: MPI_Comm_group(comm3d, &group_all); // Devide tasks into groups based on z-position MPI_Group_incl(group_all, num_xy, z_ranks[coords[2]], &group_constz); // Devide tasks into groups based on z-position MPI_Group_incl(group_all, num_xz, y_ranks[coords[1]], &group_consty); // Devide tasks into groups based on x-position MPI_Group_incl(group_all, num_yz, x_ranks[coords[0]], &group_constx); // // Make corresponding communicators: // MPI_Comm_create(comm3d, group_constz, &comm_plane_xy); // const z // MPI_Comm_create(comm3d, group_consty, &comm_plane_xz); // const x // MPI_Comm_create(comm3d, group_constx, &comm_plane_yz); // const x // // Get corresponding rank // MPI_Group_rank (group_constz, &rank_plane_xy); // MPI_Group_rank (group_consty, &rank_plane_xz); // MPI_Group_rank (group_constx, &rank_plane_yz); int remain_dims[3]; // x-y plane: remain_dims[0] = 1; remain_dims[1] = 1; remain_dims[2] = 0; MPI_Cart_sub(comm3d, remain_dims, &comm_plane_xy); MPI_Comm_rank(comm_plane_xy, &rank_plane_xy); // x-z plane remain_dims[0] = 1; remain_dims[1] = 0; remain_dims[2] = 1; MPI_Cart_sub(comm3d, remain_dims, &comm_plane_xz); MPI_Comm_rank(comm_plane_xz, &rank_plane_xz); // y-z plane remain_dims[0] = 0; remain_dims[1] = 1; remain_dims[2] = 1; MPI_Cart_sub(comm3d, remain_dims, &comm_plane_yz); MPI_Comm_rank(comm_plane_yz, &rank_plane_yz); }
void mpi_manager_2D::setup(NumArray<int> &nproc, NumArray<int> &mx) { // Determine the rank of the current task MPI_Comm_rank(MPI_COMM_WORLD, &rank); // Get number of ranks from MPI int ntasks; MPI_Comm_size(MPI_COMM_WORLD, &ntasks); this->ntasks = ntasks; // Set the distribution of processes: if(ntasks != nproc[0]*nproc[1]){ std::cerr << " Wrong number of processes " << std::endl; std::cout << ntasks << " " << nproc[0]*nproc[1] << std::endl; Finalise(); } if(rank==0) { std::cout << " Number of tasks: " << ntasks << " " << nproc[0] << " " << nproc[1] << std::endl; } // Check if grid can be subdevided as desired for(int dir = 0; dir < DIM; ++dir) { if(mx[dir] < nproc[dir] && nproc[dir] > 1) { if(rank == 0) { std::cerr << " Wrong grid topology for dimension "; std::cerr << dir << std::endl; std::cerr << " mx[" << dir << "]:" << mx[dir] << std::endl; std::cerr << " nproc[" << dir << "]:" << nproc[dir] << std::endl; } Finalise(); } } // Check if grid is a power of 2: double eps = 1.e-12; for(int dir = 0; dir < DIM; ++dir) { double exponent = log(mx[dir])/log(2.); int i_exponent = static_cast<int>(exponent+eps); if(exponent - i_exponent > 2.*eps) { if(rank == 0) { std::cerr << " Error: grid must be of the form mx = 2^n "; std::cerr << std::endl; std::cerr << " Exiting " << std::endl; } Finalise(); } } // Grid is not periodic int periods[3] = {false, false, false}; int reorder = false; // If all is okay: Create new communicator "comm3d" MPI_Cart_create(MPI_COMM_WORLD, DIM, nproc, periods, reorder, &comm2d); // Retrieve the cartesian topology if (rank == 0) { int TopoType; std::cout << " Cart topology: "; MPI_Topo_test(comm2d, &TopoType); switch (TopoType) { case MPI_UNDEFINED : std::cout << " MPI_UNDEFINED " << std::endl; break; case MPI_GRAPH : std::cout << "MPI_GRAPH" << std::endl; break; case MPI_CART : std::cout << "MPI_CART" << std::endl; break; } } // Determine rank again for cartesian communicator -> overwrite rank MPI_Comm_rank(comm2d, &rank); // std::cout << " my rank: " << rank << std::endl; // Translate rank to coordinates MPI_Cart_coords(comm2d, rank, DIM, coords); // // Backwards translation // int TranslateRank; // MPI_Cart_rank(comm3d, coords, &TranslateRank); // Find neighbouring ranks // Syntax: comm3d, shift direction, displacement, source, destination MPI_Cart_shift(comm2d, 0, 1, &left , &right); MPI_Cart_shift(comm2d, 1, 1, &front, &back); // std::cout << " My rank " << rank << " " << left << " " << right << " " << front << " " << back << " " << bottom << " " << top << std::endl; // Determine position of other ranks determin_OtherRanks(); get_SubComms(); }
void PetscMatTools::ZeroRowsWithValueOnDiagonal(Mat matrix, std::vector<unsigned>& rRows, double diagonalValue) { Finalise(matrix); /* * Important! PETSc by default will destroy the sparsity structure for this row and deallocate memory * when the row is zeroed, and if there is a next timestep, the memory will have to reallocated when * assembly to done again. This can kill performance. The following makes sure the zeroed rows are kept. * * Note: if the following lines are called, then once MatZeroRows() is called below, there will be an * error if some rows have no entries at all. Hence for problems with dummy variables, Stokes flow for * example, the identity block needs to be added before dirichlet BCs. */ #if (PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR >= 1) //PETSc 3.1 or later MatSetOption(matrix, MAT_KEEP_NONZERO_PATTERN, PETSC_TRUE); #elif (PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR == 0) //PETSc 3.0 MatSetOption(matrix, MAT_KEEP_ZEROED_ROWS, PETSC_TRUE); #else //PETSc 2.x.x MatSetOption(matrix, MAT_KEEP_ZEROED_ROWS); #endif PetscInt* rows = new PetscInt[rRows.size()]; for (unsigned i=0; i<rRows.size(); i++) { rows[i] = rRows[i]; } #if (PETSC_VERSION_MAJOR == 2 && PETSC_VERSION_MINOR == 2) //PETSc 2.2 IS is; ISCreateGeneral(PETSC_COMM_WORLD, rRows.size(), rows, &is); MatZeroRows(matrix, is, &diagonalValue); ISDestroy(PETSC_DESTROY_PARAM(is)); /* * [2]PETSC ERROR: MatMissingDiagonal_SeqAIJ() line 1011 in src/mat/impls/aij/seq/aij.c [2]PETSC ERROR: PETSc has generated inconsistent data! [2]PETSC ERROR: Matrix is missing diagonal number 15! [2]PETSC ERROR: MatILUFactorSymbolic_SeqAIJ() line 906 in src/mat/impls/aij/seq/aijfact.c * * // There appears to be a problem with MatZeroRows not setting diagonals correctly // While we are supporting PETSc 2.2, we have to do this the slow way AssembleFinal(matrix); PetscInt lo, hi; GetOwnershipRange(matrix, lo, hi); PetscInt size=GetSize(matrix); ///assert(rRows.size() == 1); for (unsigned index=0; index<rRows.size(); index++) { PetscInt row = rRows[index]; if (row >= lo && row < hi) { std::vector<unsigned> non_zero_cols; // This row is local, so zero it. for (PetscInt column = 0; column < size; column++) { if (GetElement(matrix, row, column) != 0.0) { non_zero_cols.push_back(column); } } // Separate "gets" from "sets" so that we don't have to keep going into "assembled" mode for (unsigned i=0; i<non_zero_cols.size();i++) { SetElement(matrix, row, non_zero_cols[i], 0.0); } // Set the diagonal SetElement(matrix, row, row, diagonalValue); } // Everyone communicate after row is finished AssembleFinal(matrix); } */ #elif (PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR >= 2) //PETSc 3.2 or later MatZeroRows(matrix, rRows.size(), rows, diagonalValue , NULL, NULL); #else MatZeroRows(matrix, rRows.size(), rows, diagonalValue); #endif delete [] rows; }
void PetscMatTools::ZeroRowsAndColumnsWithValueOnDiagonal(Mat matrix, std::vector<unsigned> rowColIndices, double diagonalValue) { Finalise(matrix); // sort the vector as we will be repeatedly searching for entries in it std::sort(rowColIndices.begin(), rowColIndices.end()); PetscInt lo, hi; GetOwnershipRange(matrix, lo, hi); unsigned size = hi-lo; std::vector<unsigned>* cols_to_zero_per_row = new std::vector<unsigned>[size]; // collect the columns to be zeroed, for each row. We don't zero yet as we would // then have to repeatedly call Finalise before each MatGetRow for (PetscInt row = lo; row < hi; row++) { // get all the non-zero cols for this row PetscInt num_cols; const PetscInt* cols; MatGetRow(matrix, row, &num_cols, &cols, PETSC_NULL); // see which of these cols are in the list of cols to be zeroed for(PetscInt i=0; i<num_cols; i++) { if(std::binary_search(rowColIndices.begin(), rowColIndices.end(), cols[i])) { cols_to_zero_per_row[row-lo].push_back(cols[i]); } } // this must be called for each MatGetRow MatRestoreRow(matrix, row, &num_cols, &cols, PETSC_NULL); } // Now zero columns of each row for (PetscInt row = lo; row < hi; row++) { unsigned num_cols_to_zero_this_row = cols_to_zero_per_row[row-lo].size(); if(num_cols_to_zero_this_row>0) { PetscInt* cols_to_zero = new PetscInt[num_cols_to_zero_this_row]; double* zeros = new double[num_cols_to_zero_this_row]; for(unsigned i=0; i<num_cols_to_zero_this_row; i++) { cols_to_zero[i] = cols_to_zero_per_row[row-lo][i]; zeros[i] = 0.0; } PetscInt rows[1]; rows[0] = row; MatSetValues(matrix, 1, rows, num_cols_to_zero_this_row, cols_to_zero, zeros, INSERT_VALUES); delete [] cols_to_zero; delete [] zeros; } } delete [] cols_to_zero_per_row; // Now zero the rows and add the diagonal entries ZeroRowsWithValueOnDiagonal(matrix, rowColIndices, diagonalValue); }
/** * @brief Destructor * Logs the shut down then closes the file stream */ Log::~Log() { Finalise(); }