Advanced BioPSE NCRR Dynamic Compilation Joint Session #1: Advanced BioPSE/SCIRun.

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

Introduction to C++ Templates Speaker: Bill Chapman, C++ developer, financial company in Mid-Manhattan. Can be reached via: ' This.
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Templates in C++. Generic Programming Programming/developing algorithms with the abstraction of types The uses of the abstract type define the necessary.
Review What is a virtual function? What can be achieved with virtual functions? How to define a pure virtual function? What is an abstract class? Can a.
Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Exceptions, Templates, And The Standard Template Library (STL) Chapter 16.
Copyright © 2012 Pearson Education, Inc. Chapter 16: Exceptions, Templates, and the Standard Template Library (STL)
Programming with Objects: Class Libraries and Reusable Code.
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
Java Generics. 2 The Dark Ages: Before Java 5 Java relied only on inclusion polymorphism  A polymorphism code = Using a common superclass Every class.
Chapter 16 Templates. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives  Function Templates  Syntax, defining 
Object Oriented Concepts in Java Objects Inheritance Encapsulation Polymorphism.
Templates. Objectives At the conclusion of this lesson, students should be able to Explain how function templates are used Correctly create a function.
C++ fundamentals.
Introduction to C++ Templates and Exceptions l C++ Function Templates l C++ Class Templates l Exception and Exception Handler.
OOP Languages: Java vs C++
Programming Languages and Paradigms Object-Oriented Programming.
Java and C++, The Difference An introduction Unit - 00.
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAM DESIGN WITH C++ Templates.
CSE 332: C++ Type Programming: Associated Types, Typedefs and Traits A General Look at Type Programming in C++ Associated types (the idea) –Let you associate.
Templates An introduction. Simple Template Functions template T max(T x, T y) { if (x > y) { return x; } else { return y; } } int main(void) { int x =
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Copyright © Curt Hill Generic Classes Template Classes or Container Classes.
CS212: Object Oriented Analysis and Design Lecture 9: Function Overloading in C++
Parameter Passing Mechanisms Reference Parameters § §
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
CSE 332: C++ template examples Concepts and Models Templates impose requirements on type parameters –Types that are plugged in must meet those requirements.
Scientific Computing and Imaging Institute School of Computing University of Utah Scientific Computing and Imaging Institute School of Computing University.
1 CSC241: Object Oriented Programming Lecture No 25.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department.
Overview of C++ Templates
BioPSE Elements NCRR Elements of SCIRun and BioPSE.
Template Lecture 11 Course Name: High Level Programming Language Year : 2010.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Overview of C++ Polymorphism
Variations on Inheritance Object-Oriented Programming Spring
INFSO-RI Enabling Grids for E-sciencE gLite C++ Configurator Practical experience gLite Configuration Meeting, March 1, 2005 Peter.
CINT & Reflex – The Future CINT’s Future Layout Reflex API Work In Progress: Use Reflex to store dictionary data Smaller memory footprint First step to.
Copyright © 2012 Pearson Education, Inc. Chapter 10 Advanced Topics.
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (2/2)
CSE 332: C++ templates and generic programming II Review: Concepts and Models Templates impose requirements on type parameters –Types that are plugged.
Copyright 2006 Pearson Addison-Wesley, 2008, 2012 Joey Paquet 1 Concordia University Department of Computer Science and Software Engineering SOEN6441 –
Introduction to C++ Templates and Exceptions C++ Function Templates C++ Class Templates Exception and Exception Handler.
CSE 332: C++ Overloading Overview of C++ Overloading Overloading occurs when the same operator or function name is used with different signatures Both.
Defining Data Types in C++ Part 2: classes. Quick review of OOP Object: combination of: –data structures (describe object attributes) –functions (describe.
MAITRAYEE MUKERJI Object Oriented Programming in C++
Templates.
Inheritance and Polymorphism
OOP What is problem? Solution? OOP
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Templates.
ATS Application Programming: Java Programming
Joint Session #1: Advanced
CMSC 202 Lesson 22 Templates I.
Reference Parameters.
Chapter 9 Carrano Chapter 10 Small Java
Today’s Objectives 10-Jul-2006 Announcements Quiz #3
Overview of C++ Polymorphism
Function Overloading.
CIS 199 Final Review.
Templates I CMSC 202.
Fundamental Programming
Overview Before You Start Structure of a Module Ports and Datatypes
More C++ Concepts Exception Handling Templates.
Presentation transcript:

Advanced BioPSE NCRR Dynamic Compilation Joint Session #1: Advanced BioPSE/SCIRun

Advanced BioPSE NCRR C++ Background Inheritance Virtual methods Overloaded behavior gen_fld_ptr->interp(Point *p); Each field inherits from base and overloads their own interp appropriate to the field Templates Compile time 'virtual' Interp (Point *p); Compiler provides replacement for FLD with exact field type at compile time

Advanced BioPSE NCRR Field Design Field Design Library Must have uniform interface to Fields Algorithms can be general Coders can expect uniform interface Evaluate the following: Inheritance and virtual methods Template classes implementing field concept

Advanced BioPSE NCRR Templates vs. Virtual Test identical functions configured within a virtual method against a templated configuration. Execution times in seconds

Advanced BioPSE NCRR SCIRun Fields Fields and Meshes are Templated Datatypes that adhere to their concepts TetVolField LatVolField Many more... Modules implement algorithms Multiple Inputs and outputs Essentially algorithms parameterized on their inputs and outputs

Advanced BioPSE NCRR Template Drawbacks Template code tends to propogate All permutations must be known at compile time Not runtime extensible SCIRun modules must discover the type Ports pass all fields as base class type Massive amounts of type identification code Code maintenance nightmare

Advanced BioPSE NCRR Type Discovery Algo dispatch1(FieldHandle field1, callback) { string disp_name = field1->get_type_name(0); if (disp_name == "TetVol") { // test all supported sub types if (field1->get_type_name(1) == "double") { TetVol *f1 = 0; f1 = dynamic_cast *>(field1); if (f1) { return new ModuleAlgorithm >; } } else if { // The same for the rest of the TetVol types. TetVol } } else if (disp_name == "LatticeVol") { // test all supported sub types } else if (disp_name == "ContourField") { // test all supported sub types } else if (disp_name == "TriSurf") { // test all supported sub types } else { cerr << "Error: Field type not supported" << endl; } } TetVol

Advanced BioPSE NCRR Combinations Field Types (4) TetVolField LatVolField TriSurfField CountourField Data Types (9) double int Char float etc... An Algorithm Parameterized on One Field Type Requires 36 Field instantiations And 36 Algorithm Instantiations

Advanced BioPSE NCRR Combinations Parameterized On Two Fields 36 2 = 1296 Versions of the Algorithm Parameterized On Three Fields 36 3 = Versions of the Algorithm SCIRun supports more Field and Data types Very few of these combinations are needed by any one SCIRun application

Advanced BioPSE NCRR Solution We only compile the exact types we need Extend C++ RTTI to determine types using strings Generate C++ code to instantiate correct templates Fork a process to compile the code Dynamically link the resulting shared library Call into the lib to get an instance of the algorithm Call a single virtual function in the algorithm, passing in fields and other required parameters Execute the intended function, which uses dynamic_cast to get the known underlying field type

Advanced BioPSE NCRR Calling the Algorithm Void ShowField::execute() { // Get a Field from input field port. field = (FieldIPort *)get_iport("Field"); field->get(field_handle); // Get the input field's type info. const TypeDescription *td = field_handle->get_type_description(); // Get the Algorithm. CompileInfo *ci = RenderFieldBase::get_compile_info(td); if (! DynamicLoader::scirun_loader().get(*ci, rend_algo)) { error("Could not compile algorithm for ShowField -"); return; } RenderFieldBase *rf = dynamic_cast (rend_algo); // Let the templated algorithm render this field. rf->render(field_handle, /* any other parameters from gui */); // Send results downstream... } No Template Instantiations for the exact algorithm type!

Advanced BioPSE NCRR Summary Customize Compilation Only the algorithms and types you use are compiled They are persistent (only create once) Flexibility/Extensibility Your Fields in your Package compile with existing algorithms. Reduce Code Bloat Won't swamp your compiler Smaller libraries Shorter installation compiles