Teuchos: Utilities for Developers & Users November 4 th, 1:15-4:30pm Roscoe Bartlett Mike Heroux Kris Kampshoff Kevin Long Paul Sexton Heidi Thornquist.

Slides:



Advertisements
Similar presentations
Chapter 17 vector and Free Store Bjarne Stroustrup
Advertisements

Chapter 17 vector and Free Store John Keyser’s Modifications of Slides By Bjarne Stroustrup
Unions The storage referenced by a union variable can hold data of different types subject to the restriction that at any one time, the storage holds data.
Next Generation Iterative Solvers: Belos & Anasazi Next Generation Iterative Solvers: Belos & Anasazi November 3 rd, 9:30-10:30am Mike Heroux Ulrich Hetmaniuk.
Informática II Prof. Dr. Gustavo Patiño MJ
6/10/2015C++ for Java Programmers1 Pointers and References Timothy Budd.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
Classes, Objects, Arrays, Collections and Autoboxing Dr. Andrew Wallace PhD BEng(hons) EurIng
C++ Exceptions STL Vector. Example int Quotient (int numer, int denom} { if (denom != 0) return (numer/denom); else //What to do?? }
Review C++ exception handling mechanism Try-throw-catch block How does it work What is exception specification? What if a exception is not caught?
Page 1 Trilinos Software Engineering Technologies and Integration Capability Area Overview Roscoe A. Bartlett Department.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Purpose  This training course describes how to configure the the C/C++ compiler options.
Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company, for the United States Department of Energy’s National Nuclear.
PyTrilinos: A Python Interface to Trilinos Bill Spotz Sandia National Laboratories Reproducible Research in Computational Geophysics August 31, 2006.
Page 1 Trilinos Software Engineering Technologies and Integration Capability Area Overview Roscoe A. Bartlett Department.
Natalia Yastrebova What is Coverity? Each developer should answer to some very simple, yet difficult to answer questions: How do I find new.
Page 1 Trilinos Software Engineering Technologies and Integration Numerical Algorithm Interoperability and Vertical Integration –Abstract Numerical Algorithms.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
Defining and Converting Data Copyright Kip Irvine, 2003 Last Update: 11/4/2003.
Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company, for the United States Department of Energy’s National Nuclear.
Pointers OVERVIEW.
CS Midterm Study Guide Fall General topics Definitions and rules Technical names of things Syntax of C++ constructs Meaning of C++ constructs.
C++ Memory Overview 4 major memory segments Key differences from Java
Amesos Sparse Direct Solver Package Tim Davis, Mike Heroux, Rob Hoekstra, Marzio Sala, Ken Stanley, Heidi Thornquist, Jim Willenbring Trilinos Users Group.
SPL – Practical Session 2 Topics: – C++ Memory Management – Pointers.
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
Danny Dunlavy, Andy Salinger Sandia National Laboratories Albuquerque, New Mexico, USA SIAM Parallel Processing February 23, 2006 SAND C Sandia.
Copyright 2005, The Ohio State University 1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation.
Types in programming languages1 What are types, and why do we need them?
Review Binary Numbers Bit : 0 or 1 Byte: 8 bites 256 different values 2 8 KB : 1024 bytes 2 10 bytes MB : 1024 * 1024 bytes 2 10 * 2 10 (2 20 ) bytes GB.
Scalable Linear Algebra Capability Area Michael A. Heroux Sandia National Laboratories Sandia is a multiprogram laboratory operated by Sandia Corporation,
Copyright Curt Hill Variables What are they? Why do we need them?
New Features in ML 2004 Trilinos Users Group Meeting November 2-4, 2004 Jonathan Hu, Ray Tuminaro, Marzio Sala, Michael Gee, Haim Waisman Sandia is a multiprogram.
1 Stratimikos Unified Wrapper to Trilinos Linear Solvers and Preconditioners Roscoe A. Bartlett Department of Optimization & Uncertainty Estimation Sandia.
Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company, for the United States Department of Energy’s National Nuclear.
Teuchos: Utilities for Developers & Users November 2nd, 3:30-4:30pm Roscoe Bartlett Mike Heroux Kris Kampshoff Kevin Long Paul Sexton Heidi.
Thyra For Developers Roscoe A. Bartlett Department of Optimization & Uncertainty Estimation Sandia National Laboratories Trilinos Users Group Meeting (Developers.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
An Overview of Belos and Anasazi October 16 th, 11-12am Heidi Thornquist Teri Barth Rich Lehoucq Mike Heroux Computational Mathematics and Algorithms Sandia.
CSE 332: C++ Statements C++ Statements In C++ statements are basic units of execution –Each ends with ; (can use expressions to compute values) –Statements.
C++ for Java Programmers Chapter 2. Fundamental Daty Types Timothy Budd.
System Programming Practical Session 7 C++ Memory Handling.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
CSE 332: C++ pointers, arrays, and references Overview of Pointers and References Often need to refer to another object –Without making a copy of the object.
1 Recall that... char str [ 8 ]; str is the base address of the array. We say str is a pointer because its value is an address. It is a pointer constant.
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
CSE 332: C++ STL iterators What is an Iterator? An iterator must be able to do 2 main things –Point to the start of a range of elements (in a container)
1 Homework Continue with K&R Chapter 5 –Skipping sections for now –Not covering section 5.12 Continue on HW5.
Java Programming Language Lecture27- An Introduction.
APS105 Malloc and 2D Arrays (text Ch6.4, Ch10.2).
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
Chapter 6 CS 3370 – C++ Functions.
C Interview Questions Prepared By:.
A bit of C programming Lecture 3 Uli Raich.
Pointers and Memory Overview
C Basics.
Trilinos Software Engineering Technologies and Integration
Pointers, Dynamic Data, and Reference Types
Variables Title slide variables.
Homework Continue with K&R Chapter 5 Skipping sections for now
Pointers, Dynamic Data, and Reference Types
SPL – PS1 Introduction to C++.
SPL – PS2 C++ Memory Handling.
Presentation transcript:

Teuchos: Utilities for Developers & Users November 4 th, 1:15-4:30pm Roscoe Bartlett Mike Heroux Kris Kampshoff Kevin Long Paul Sexton Heidi Thornquist Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company, for the United States Department of Energy under contract DE-AC04-94AL85000.

What is Teuchos (TEF-hos)?  Lightweight, portable utility package  What’s new?  First release in Trilinos 4.0  Templated BLAS/LAPACK interface  Templated serial dense matrix / vector  Timing classes  Templated parameter list  Numeric traits mechanisms ( ordinal / scalar )  Memory management: Reference-counted pointers Pre-allocated workspace  Exception handling  Command-line parsing  “Extended” utilities: XML parsing MPI communicators / traits Users Developers

Templated Parameter List  Design based on NOX parameter list  Adopted by Amesos, ML, Ifpack, AztecOO, …  Parameters can be numeric datatypes, pointers to vectors or functions, and other parameter lists. // Empty parameter list Teuchos::ParameterList My_List; // Setting parameters My_List.set("Max Iters", 1550); My_List.set("Tolerance", 1e-10); My_List.set("Solver", "GMRES"); // Create sublist Teuchos::ParameterList& Prec_List = My_List.sublist("Preconditioner"); // Setting parameters in sublist Prec_List.set("Type", "ILU"); Prec_List.set("Drop Tolerance", 1e-3);  Parameters can be input and retrieved with templated “set” and “get” methods, as well as helper functions.  Parameter lists can be queried for attributes. // Has a solver been chosen? bool solver_defined = My_List.isParameter(“Solver”); // Has a preconditioner been chosen? bool prec_defined = My_List.isSublist(“Preconditioner”); // Has a double-precision drop tolerance been chosen? (Helper function) bool drop_tol = Teuchos::isParameterType (Prec_List, “Drop Tolerance”); ReturnType foo_solver( Teuchos::ParameterList& solverPL,… ) { // Getting parameters int max_iters = solverPL.template get("Max Iters"); std::string solver = getParameter(solverPL, “Solver”) double tol = solverPL.get("Tolerance", 1e-8); // Get sublist ( same as making sublist ) Teuchos::ParameterList precPL = solverPL.sublist("Preconditioner"); … return Ok; }  Parameters can be input and retrieved with templated “set” and “get” methods, as well as helper functions.

Numeric Traits Mechanisms  Assumed: addition, subtraction, multiplication, and division  OrdinalTraits  zero & one  int & long int  ScalarTraits  zero, one, magnitude type, absolute value, conjugate, square root, random number generator, …  std::numeric_limits  float, double, complex, and complex  Required: none, a compile-time check is performed.  Arbitrary precision arithmetic Generic programming technique that uses templated interfaces to define the standard behavior of datatypes.

Teuchos Templated BLAS Example template ScalarTraits ::magnitudeType BLAS ::NRM2 const OrdinalType n, const ScalarType* x, const OrdinalType incx) const { OrdinalType izero = OrdinalTraits ::zero(); OrdinalType ione = OrdinalTraits ::one(); ScalarType result = ScalarTraits ::zero(); OrdinalType i, ix = izero; if ( n > izero ) { // Set the initial index. if (incx < izero) { ix = (-n+ione)*incx; } for(i = izero; i < n; i++) { result += ScalarTraits ::conjugate(x[ix]) * x[ix]; ix += incx; } return ScalarTraits ::squareroot(result); } } /* end NRM2 */ double DNRM2( const int n, const double* x, const int incx) { int i, ix = 0; double result 0.0; if ( n > 0 ) { // Set the initial index. if (incx < 0) { ix = (-n+1)*incx; } for(i = 0; i < n; ++i) { result += x[ix] * x[ix]; ix += incx; } result = std::sqrt(result); } return result; } /* end NRM2 */

Arbitrary Precision Libraries ARPREC & GNU MP  ARPREC (Bailey, et. al.)  uses arrays of 64-bit floating-point numbers to represent high- precision floating-point numbers.  provides support for datatypes with differing precision levels.  --enable-teuchos-arprec  GNU MP  uses fullwords, arbitrary precision mantissa, and limited precision exponent to represent high-precision floating-point numbers.  platform specific kernels written in assembly language perform common inner-loop functions.  provides support for datatypes with differing precision levels.  --enable-teuchos-gmp  What about communication of arbitrary precision variables?

Primitive Type Traits  A traits class for decomposing an object into an array of primitive objects  ARPREC: primitive type = double  GNU MP: primitive type = int, byte(?)  Can be used in communicating more complex datatypes  Essential for Tpetra, TSFCore, …  Platform dependent issues here...

Memory Management Teuchos::RefCountPtr  Reference-counted pointers  combat seg faults, memory leaks, headaches...  RefCountPtr Intro Paper: $(TRILINOS_HOME)/doc/RefCountPtr/RefCountPtrBeginnersGuideSAND.tex RefCountPtr a_null_ptr, // Create a reference-counted NULL pointer. a_ptr2 = rcp(new A), // Initialize reference-counted pointers. a_ptr3 = rcp(new A); // "" A *ra_ptr2 = new A, // Initialize non-reference counted pointers. *ra_ptr3 = new A; // "" a_ptr2 = rcp(ra_ptr3); // Assign from a raw pointer (only do this once!) a_ptr3 = a_ptr1; // Assign one smart pointer to another. a_ptr2->f(); // Access a member of A using -> ra_ptr2->f(); // "" *a_ptr2 = *a_ptr3; // Dereference the objects and assign. *ra_ptr2 = *ra_ptr3; // "" // Get the raw C++ pointer. A* true_ptr = a_ptr1.get();

Memory Management Teuchos::Workspace  Pre-allocated workspace (Teuchos::WorkspaceStore)  Avoid calls to new/delete with arrays of un-initialized or default initialized objects as automatic variables on the stack (global).  Calls new/delete by default.  Very useful in codes/functions/methods that are commonly used and riddled with creation/destruction of arrays: int* index = new int[ num_vecs ]; #include “Teuchos_Workspace.hpp” int main( int argc, char* argc[] ) { size = 100; Teuchos::set_default_workspace_store( Teuchos::rcp(new Teuchos::WorkspaceStoreInitializeable(10*size))); Teuchos::WorkspaceStore *wss_(Teuchos::get_default_workspace_store().get()); Teuchos::Workspace b(wss_,size,false); Teuchos::Workspace index(wss_,size,false); return 0; }

Memory Management Teuchos::Workspace Memory block size = 100 Number of call loops = Timing raw new and delete for temporaries... time = sec Timing std::vector for temporaries... time = sec Timing std::valarray for temporaries... time = sec Timing Teuchos::Workspace for temporaries... time = sec *** Statistics for automatic array workspace: Number of megabytes of preallocated workspace = Number of megabytes needed = Number of allocations using preallocated workspace = Number of dynamic allocations beyond preallocated workspace = 0 Relative time (lower is better): raw new/delete = std::vector = std::valarray = Teuchos::Workspace = 1

Exception Handling TEST_FOR_EXCEPTION( n > 100, std::out_of_range, "Error, n = " << n << is bad" ); /home/bob/project/src/my_source_file.cpp:225: n > 100: Error, n = 125 is bad  TEST_FOR_EXCEPTION macro:  Macro for throwing an exception with breakpointing: #define TEST_FOR_EXCEPTION( throw_exception_test, Exception, msg ) #define TEST_FOR_EXCEPT( throw_exception_test )  DEVELOPER’S NOTE:  If there is an error with this macro... Did you use “-DHAVE_CONFIG_H” in your makefile? Consider using “trilinos_make_macros.mak”

Teuchos::Command Line Processor  Basic command line parser for input from (argc,argv[])  Facilitates organization of configurable executables/examples  Creates help string for command line options  Command line options can be standard data types / enumerated lists  Let’s look at an example...

Teuchos::CommandLineProcessor Example #include “Teuchos_CommandLineProcessor.hpp” int main(int argc, char* argv[] ) { // Creating an empty command line processor looks like: Teuchos::CommandLineProcessor My_CLP; // Set an integer command line option. int NumIters = 1550; My_CLP.setOption("iterations", &NumIters, "Number of iterations"); // Set a boolean command line option. bool Precondition; My_CLP.setOption("precondition","no-precondition", &Precondition,"Preconditioning flag");... // Allow an unrecognized option to be ignored (warning is printed) My_CLP.recogniseAllOptions(true); // Throw and exception if an option found is not recognized or My_CLP.throwExceptions(false); Teuchos::CommandLineProcessor::EParseCommandLineReturn parseReturn= My_CLP.parse( argc, argv ); if (parseReturn != PARSE_SUCCESSFUL) return 1; return 0; } $./CLP_example.exe --help Usage:./CLP_example [options] options: --help Prints this help message --pause-for-debugging Pauses for user input to allow attaching a debugger --iterations int Number of iterations (default: --iterations=1550) --tolerance double Tolerance (default: --tolerance=1e-10) --solver string Linear solver (default: --solver="GMRES") --precondition bool Preconditioning flag --no-precondition (default: --no-precondition) --speed enum Speed of our solver Valid options: "slow", "medium", "fast" (default: --speed="medium")

Teuchos Developers Overview  Parameter list is easy to use and quickly being adopted by most Trilinos packages.  Templated tools libraries are essential for the development of templated solver libraries.  Numeric traits mechanism allows the use of arbitrary datatypes in templated code.  Templated BLAS/LAPACK wrappers and SDM allow easy integration of arbitrary precision for high-precision kernels.  Teuchos tools provide portable solutions for developers.  See Teuchos website for more info: