本文整理汇总了C++中teuchos::ArrayRCP::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ ArrayRCP::begin方法的具体用法?C++ ArrayRCP::begin怎么用?C++ ArrayRCP::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类teuchos::ArrayRCP
的用法示例。
在下文中一共展示了ArrayRCP::begin方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: int
bool Tpetra::Utils::parseRfmt(Teuchos::ArrayRCP<char> fmt, int &perline, int &width, int &prec, char &valformat) {
TEUCHOS_TEST_FOR_EXCEPT(fmt.size() != 0 && fmt[fmt.size()-1] != '\0');
std::transform(fmt.begin(), fmt.end(), fmt, static_cast < int(*)(int) > (std::toupper));
// find the first left paren '(' and the last right paren ')'
Teuchos::ArrayRCP<char>::iterator firstLeftParen = std::find( fmt.begin(), fmt.end(), '(');
Teuchos::ArrayRCP<char>::iterator lastRightParen = std::find(std::reverse_iterator<Teuchos::ArrayRCP<char>::iterator>(fmt.end()),
std::reverse_iterator<Teuchos::ArrayRCP<char>::iterator>(fmt.begin()),
')').base()-1;
// select the substring between the parens, including them
// if neither was found, set the string to empty
if (firstLeftParen == fmt.end() || lastRightParen == fmt.begin()) {
fmt.resize(0 + 1);
fmt[0] = '\0';
}
else {
fmt += (firstLeftParen - fmt.begin());
size_t newLen = lastRightParen - firstLeftParen + 1;
fmt.resize(newLen + 1);
fmt[newLen] = '\0';
}
if (std::find(fmt.begin(),fmt.end(),'P') != fmt.end()) {
// not supported
return true;
}
bool error = true;
if (std::sscanf(fmt.getRawPtr(),"(%d%c%d.%d)",&perline,&valformat,&width,&prec) == 4) {
if (valformat == 'E' || valformat == 'D' || valformat == 'F') {
error = false;
}
}
return error;
}
示例2: dump
void dump(const MV& v, const std::string& name) {
std::cout << name << std::endl;
Teuchos::ArrayRCP<const Scalar> view = v.get1dView();
for (Teuchos::ArrayRCP<const Scalar>::iterator it = view.begin(); it != view.end(); ++it) {
std::cout << *it << std::endl;
}
std::cout << std::endl;
}
示例3: errStr
void Tpetra::Utils::readHBHeader(std::ifstream &fin, Teuchos::ArrayRCP<char> &Title, Teuchos::ArrayRCP<char> &Key, Teuchos::ArrayRCP<char> &Type,
int &Nrow, int &Ncol, int &Nnzero, int &Nrhs,
Teuchos::ArrayRCP<char> &Ptrfmt, Teuchos::ArrayRCP<char> &Indfmt, Teuchos::ArrayRCP<char> &Valfmt, Teuchos::ArrayRCP<char> &Rhsfmt,
int &Ptrcrd, int &Indcrd, int &Valcrd, int &Rhscrd, Teuchos::ArrayRCP<char> &Rhstype) {
int Totcrd, Neltvl, Nrhsix;
const int MAXLINE = 81;
char line[MAXLINE];
//
Title.resize(72 + 1); std::fill(Title.begin(), Title.end(), '\0');
Key.resize(8 + 1); std::fill(Key.begin(), Key.end(), '\0');
Type.resize(3 + 1); std::fill(Type.begin(), Type.end(), '\0');
Ptrfmt.resize(16 + 1); std::fill(Ptrfmt.begin(), Ptrfmt.end(), '\0');
Indfmt.resize(16 + 1); std::fill(Indfmt.begin(), Indfmt.end(), '\0');
Valfmt.resize(20 + 1); std::fill(Valfmt.begin(), Valfmt.end(), '\0');
Rhsfmt.resize(20 + 1); std::fill(Rhsfmt.begin(), Rhsfmt.end(), '\0');
//
const std::string errStr("Tpetra::Utils::readHBHeader(): Improperly formatted H/B file: ");
/* First line: (A72,A8) */
fin.getline(line,MAXLINE);
TEUCHOS_TEST_FOR_EXCEPTION( std::sscanf(line,"%*s") < 0, std::runtime_error, errStr << "error buffering line.");
(void)std::sscanf(line, "%72c%8[^\n]", Title.getRawPtr(), Key.getRawPtr());
/* Second line: (5I14) or (4I14) */
fin.getline(line,MAXLINE);
TEUCHOS_TEST_FOR_EXCEPTION(std::sscanf(line,"%*s") < 0, std::runtime_error, errStr << "error buffering line.");
if ( std::sscanf(line,"%14d%14d%14d%14d%14d",&Totcrd,&Ptrcrd,&Indcrd,&Valcrd,&Rhscrd) != 5 ) {
Rhscrd = 0;
TEUCHOS_TEST_FOR_EXCEPTION(std::sscanf(line,"%14d%14d%14d%14d",&Totcrd,&Ptrcrd,&Indcrd,&Valcrd) != 4, std::runtime_error, errStr << "error reading pointers (line 2)");
}
/* Third line: (A3, 11X, 4I14) */
fin.getline(line,MAXLINE);
TEUCHOS_TEST_FOR_EXCEPTION(std::sscanf(line,"%*s") < 0, std::runtime_error, errStr << "error buffering line.");
TEUCHOS_TEST_FOR_EXCEPTION(std::sscanf(line, "%3c%14i%14i%14i%14i", Type.getRawPtr(),&Nrow,&Ncol,&Nnzero,&Neltvl) != 5 , std::runtime_error, errStr << "error reading matrix meta-data (line 3)");
std::transform(Type.begin(), Type.end(), Type.begin(), static_cast < int(*)(int) > (std::toupper));
/* Fourth line: */
fin.getline(line,MAXLINE);
TEUCHOS_TEST_FOR_EXCEPTION(std::sscanf(line,"%*s") < 0, std::runtime_error, errStr << "error buffering line.");
if (Rhscrd != 0) {
TEUCHOS_TEST_FOR_EXCEPTION(std::sscanf(line,"%16c%16c%20c%20c",Ptrfmt.getRawPtr(),Indfmt.getRawPtr(),Valfmt.getRawPtr(),Rhsfmt.getRawPtr()) != 4, std::runtime_error, errStr << "error reading formats (line 4)");
}
else {
TEUCHOS_TEST_FOR_EXCEPTION(std::sscanf(line,"%16c%16c%20c",Ptrfmt.getRawPtr(),Indfmt.getRawPtr(),Valfmt.getRawPtr()) != 3, std::runtime_error, errStr << "error reading formats (line 4)");
}
/* (Optional) Fifth line: */
if (Rhscrd != 0 ) {
Rhstype.resize(3 + 1,'\0');
fin.getline(line,MAXLINE);
TEUCHOS_TEST_FOR_EXCEPTION(std::sscanf(line,"%*s") < 0, std::runtime_error, errStr << "error buffering line.");
TEUCHOS_TEST_FOR_EXCEPTION(std::sscanf(line,"%3c%14d%14d", Rhstype.getRawPtr(), &Nrhs, &Nrhsix) != 3, std::runtime_error, errStr << "error reading right-hand-side meta-data (line 5)");
}
}
示例4: sum
//-----------------------------------------------------------------------------
double TpetraVector::sum() const
{
dolfin_assert(!_x.is_null());
Teuchos::ArrayRCP<const double> arr = _x->getData(0);
const double _sum = std::accumulate(arr.begin(), arr.end(), 0.0);
return MPI::sum(mpi_comm(), _sum);
}
示例5: ownedActive
void
Filtered_UniqueGlobalIndexer<LocalOrdinalT,GlobalOrdinalT>::
getOwnedAndGhostedNotFilteredIndicator(std::vector<int> & indicator) const
{
using Teuchos::RCP;
typedef GlobalOrdinalT GO;
typedef LocalOrdinalT LO;
typedef panzer::TpetraNodeType Node;
typedef Tpetra::Map<LO, GO, Node> Map;
typedef Tpetra::Vector<GO,LO,GO,Node> Vector;
typedef Tpetra::Import<LO,GO,Node> Import;
std::vector<GlobalOrdinalT> ownedIndices;
std::vector<GlobalOrdinalT> ghostedIndices;
// build owned and ghosted maps
getOwnedIndices(ownedIndices);
getOwnedAndGhostedIndices(ghostedIndices);
RCP<const Map> ownedMap
= Tpetra::createNonContigMap<LO,GO>(ownedIndices,getComm());
RCP<const Map> ghostedMap
= Tpetra::createNonContigMap<LO,GO>(ghostedIndices,getComm());
// allocate the owned vector, mark those GIDs as unfiltered
// (they are by definition)
Vector ownedActive(ownedMap);
ownedActive.putScalar(1);
// Initialize all indices to zero
Vector ghostedActive(ghostedMap);
ghostedActive.putScalar(0);
// do communication, marking unfiltered indices as 1 (filtered
// indices locally are marked as zero)
Import importer(ownedMap,ghostedMap);
ghostedActive.doImport(ownedActive,importer,Tpetra::INSERT);
Teuchos::ArrayRCP<const GO> data = ghostedActive.getData();
// copy communicated data (clear it out first)
indicator.clear();
indicator.insert(indicator.end(),data.begin(),data.end());
}
示例6: ArrayField
//---------------------------------------------------------------------------//
TEUCHOS_UNIT_TEST( FieldTools, tensor_field_test )
{
using namespace DataTransferKit;
// Setup random numbers for the test.
int num_rand = 4;
double rand_max = 10.0;
Teuchos::Array<double> random_numbers( num_rand );
std::srand( 1 );
for ( int i = 0; i < num_rand; ++i )
{
random_numbers[i] = rand_max * (double) std::rand() / RAND_MAX;
}
// Setup communication.
Teuchos::RCP< const Teuchos::Comm<int> > comm = getDefaultComm<int>();
int my_rank = comm->getRank();
int my_size = comm->getSize();
// Setup a field manager.
int field_dim = 9;
typedef FieldTraits<ArrayField> FT;
Teuchos::RCP<ArrayField> array_field =
Teuchos::rcp( new ArrayField( field_dim*(my_rank+1), field_dim ) );
FieldManager<ArrayField> field_manager( array_field, comm );
// Test the field tools.
typedef FieldTools<ArrayField> Tools;
// Dimension iterators.
FT::iterator dim_begin, dim_end;
for ( int d = 0; d < field_dim; ++d )
{
dim_begin = Tools::dimBegin( *field_manager.field(), d );
dim_end = Tools::dimEnd( *field_manager.field(), d );
TEST_ASSERT( std::distance( dim_begin, dim_end ) == my_rank+1 );
}
FT::const_iterator const_dim_begin, const_dim_end;
for ( int d = 0; d < field_dim; ++d )
{
const_dim_begin = Tools::dimBegin( *field_manager.field(), d );
const_dim_end = Tools::dimEnd( *field_manager.field(), d );
TEST_ASSERT( std::distance( const_dim_begin, const_dim_end )
== my_rank+1 );
}
// Length.
int global_size = 0;
for ( int i = 0; i < my_size; ++i )
{
global_size += field_dim*(i+1);
}
TEST_ASSERT(
Tools::globalSize( *field_manager.field(), field_manager.comm() )
== global_size );
// Scalar filling.
Tools::putScalar( *field_manager.field(), random_numbers[0] );
// Views.
double local_val;
Teuchos::ArrayRCP<const double> const_view =
Tools::view( *field_manager.field() );
Teuchos::ArrayRCP<const double>::const_iterator const_view_iterator;
for ( const_view_iterator = const_view.begin();
const_view_iterator != const_view.end();
++const_view_iterator )
{
local_val = random_numbers[0];
TEST_ASSERT( *const_view_iterator == local_val );
}
Teuchos::ArrayRCP<double> view =
Tools::nonConstView( *field_manager.field() );
Teuchos::ArrayRCP<double>::iterator view_iterator;
for ( view_iterator = view.begin();
view_iterator != view.end();
++view_iterator )
{
local_val = random_numbers[0];
TEST_ASSERT( *view_iterator == local_val );
}
Teuchos::ArrayRCP<double> copy =
Tools::copy( *field_manager.field() );
Teuchos::ArrayRCP<double>::const_iterator copy_iterator;
for ( copy_iterator = copy.begin();
copy_iterator != copy.end();
++copy_iterator )
{
local_val = random_numbers[0];
TEST_ASSERT( *copy_iterator == local_val );
}
// Multiple scalar filling.
Teuchos::Array<double> fillers( field_dim );
for ( int d = 0; d < field_dim; ++d )
{
//.........这里部分代码省略.........
示例7: broadcast
void
Tpetra::Utils::readHBMatrix(const std::string &filename,
const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
const Teuchos::RCP<Node> &node,
Teuchos::RCP< Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps> > &A,
Teuchos::RCP< const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > rowMap,
const Teuchos::RCP<ParameterList> ¶ms)
{
const int myRank = comm->getRank();
int numRows,numCols,numNZ;
Teuchos::ArrayRCP<Scalar> svals;
Teuchos::ArrayRCP<GlobalOrdinal> colinds;
Teuchos::ArrayRCP<int> rowptrs;
Teuchos::ArrayRCP<size_t> nnzPerRow;
int fail = 0;
if (myRank == 0) {
bool isSymmetric=false;
Teuchos::ArrayRCP<double> dvals;
Teuchos::ArrayRCP<int> colptrs, rowinds;
std::string type;
Tpetra::Utils::readHBMatDouble(filename,numRows,numCols,numNZ,type,colptrs,rowinds,dvals);
TEUCHOS_TEST_FOR_EXCEPT(type.size() != 3);
if (type[0] != 'R' && type[0] != 'r') {
// only real matrices right now
fail = 1;
}
if (fail == 0 && numNZ > 0) {
if (type[1] == 'S' || type[1] == 's') {
isSymmetric = true;
}
else {
isSymmetric = false;
}
}
if (fail == 0 && numNZ > 0) {
// find num non-zero per row
nnzPerRow = Teuchos::arcp<size_t>(numRows);
std::fill(nnzPerRow.begin(), nnzPerRow.end(), 0);
for (Teuchos::ArrayRCP<int>::const_iterator ri=rowinds.begin(); ri != rowinds.end(); ++ri) {
// count each row index towards its row
++nnzPerRow[*ri-1];
}
if (isSymmetric) {
// count each column toward the corresponding row as well
for (int c=0; c < numCols; ++c) {
// the diagonal was already counted; neglect it, if it exists
for (int i=colptrs[c]-1; i != colptrs[c+1]-1; ++i) {
if (rowinds[i] != c+1) {
++nnzPerRow[c];
++numNZ;
}
}
}
}
// allocate/set new matrix data
svals = Teuchos::arcp<Scalar>(numNZ);
colinds = Teuchos::arcp<GlobalOrdinal>(numNZ);
rowptrs = Teuchos::arcp<int>(numRows+1);
rowptrs[0] = 0;
#ifdef HAVE_TPETRA_DEBUG
Teuchos::ArrayRCP<size_t> nnzPerRow_debug(nnzPerRow.size());
std::copy(nnzPerRow.begin(), nnzPerRow.end(), nnzPerRow_debug.begin());
#endif
for (int j=1; j <= numRows; ++j) {
rowptrs[j] = rowptrs[j-1] + nnzPerRow[j-1];
nnzPerRow[j-1] = 0;
}
// translate from column-oriented to row-oriented
for (int col=0; col<numCols; ++col) {
for (int i=colptrs[col]-1; i != colptrs[col+1]-1; ++i) {
const int row = rowinds[i]-1;
// add entry to (row,col), with value dvals[i]
const size_t entry = rowptrs[row] + nnzPerRow[row];
svals[entry] = Teuchos::as<Scalar>(dvals[i]);
colinds[entry] = Teuchos::as<GlobalOrdinal>(col);
++nnzPerRow[row];
if (isSymmetric && row != col) {
// add entry to (col,row), with value dvals[i]
const size_t symentry = rowptrs[col] + nnzPerRow[col];
svals[symentry] = Teuchos::as<Scalar>(dvals[i]);
colinds[symentry] = Teuchos::as<GlobalOrdinal>(row);
++nnzPerRow[col];
}
}
}
#ifdef HAVE_TPETRA_DEBUG
{
bool isequal = true;
typename Teuchos::ArrayRCP<size_t>::const_iterator it1, it2;
for (it1 = nnzPerRow.begin(), it2 = nnzPerRow_debug.begin(); it1 != nnzPerRow.end(); ++it1, ++it2) {
if (*it1 != *it2) {
isequal = false;
break;
}
}
TEUCHOS_TEST_FOR_EXCEPTION(!isequal || nnzPerRow.size() != nnzPerRow_debug.size(), std::logic_error,
"Tpetra::Utils::readHBMatrix(): Logic error.");
}
#endif
}
//.........这里部分代码省略.........