Overview Before You Start Structure of a Module Ports and Datatypes

Slides:



Advertisements
Similar presentations
Sml2java a source to source translator Justin Koser, Haakon Larsen, Jeffrey Vaughan PLI 2003 DP-COOL.
Advertisements

OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
pa 1 Porting BETA to ROTOR ROTOR Projects Presentation Day, June by Peter Andersen.
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.
C++ Basics Variables, Identifiers, Assignments, Input/Output.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 Chapter Three Using Methods. 2 Objectives Learn how to write methods with no arguments and no return value Learn about implementation hiding and how.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Programming with Objects: Class Libraries and Reusable Code.
Advanced Object-Oriented Programming Features
C++ fundamentals.
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
OOP Languages: Java vs C++
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
A First Program Using C#
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
An Object-Oriented Approach to Programming Logic and Design
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
By Sidhant Garg.  C was developed between by Dennis Ritchie at Bell Laboratories for use with the Unix Operating System.  Unlike previously.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
 200 Total Points ◦ 74 Points Writing Programs ◦ 60 Points Tracing Algorithms and determining results ◦ 36 Points Short Answer ◦ 30 Points Multiple Choice.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
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.
C++ Tutorial Hany Samuel and Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright © 2006 by Douglas.
Advanced BioPSE NCRR Dynamic Compilation Joint Session #1: Advanced BioPSE/SCIRun.
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 8: Class Relationships Data Abstraction & Problem Solving.
Scientific Computing and Imaging Institute School of Computing University of Utah Scientific Computing and Imaging Institute School of Computing University.
C++ / G4MICE Course Session 2 Basic C++ types. Control and Looping Functions in C Function/method signatures and scope.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Porting a large scale enterprise application from Tcl/Tk 8.4 to 8.5 Prashant Thakre, Tushar Gupta {prashant_thakre, Gaurav Bansal.
M1G Introduction to Programming 2 5. Completing the program.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Introduction to Object-Oriented Programming Lesson 2.
More about Java Classes Writing your own Java Classes More about constructors and creating objects.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Classes, Interfaces and Packages
11 Introduction to Object Oriented Programming (Continued) Cats.
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.
Chapter 16 Templates Copyright © 2008 Pearson Addison-Wesley. All rights reserved.
CSE 332: C++ templates and generic programming II Review: Concepts and Models Templates impose requirements on type parameters –Types that are plugged.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Names and Attributes Names are a key programming language feature
3 Introduction to Classes and Objects.
C++ Templates.
Templates.
Chapter 3: Using Methods, Classes, and Objects
Introduction to C Programming Language
Templates.
Lecture 9 Concepts of Programming Languages
Lecture 13 Writing Classes Richard Gesick.
CS 2308 Final Exam Review.
OOP and ADTs Chapter 14 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved.
Chapter 8: Class Relationships
Overview of C++ Polymorphism
Object Oriented Programming in java
Lab4 problems More about templates Some STL
SPL – PS1 Introduction to C++.
Lecture 9 Concepts of Programming Languages
Object-Oriented Programming and class Design
Threads and concurrency / Safety
Presentation transcript:

Overview Before You Start Structure of a Module Ports and Datatypes Component Wizard GUI’s Dynamic Compilation

Before You Start Design Your Function Coding Standard A Module is a Function Inputs and Outputs User Input (GUI Variables) Dataflow Coding Standard Standards Advice SCIRun/doc/Developer/Guide/coding_standard.html

Module Structure Support Files .cc file sub.mk .xml file .tcl file .h file (optional)

Ports and Datatypes Ports Datatypes LockingHandles Generation number Memory Management Sending Data Cache Results Datatypes Fields, Matrix, SceneGraph Detach (Dataflow) Properties

Component Wizard Adding a Module

Component Wizard

Component Wizard Edit a Port Name Namespace

Component Wizard Package Category Path

Component Wizard New Package? New Category? Reconfiguring.

Component Wizard After Compiling

Component Wizard Your Skeleton GUI

GUI’s TCL itcl blt Use Simple GUI as a Pattern GuiVars

GUI’s itcl_class SCIRun_Fields_SelectField { inherit Module constructor {config} { set name SelectField global $this-stampvalue global $this-runmode set_defaults } method set_defaults {} { set $this-stampvalue 100 set $this-runmode 0 # 0 nothing 1 accumulate 2 replace } method replace {} { set $this-runmode 2 $this-c needexecute } method accumulate {} { set $this-runmode 1 $this-c needexecute }

GUI’s method ui {} { set w .ui[modname] if {[winfo exists $w]} { raise $w return } toplevel $w frame $w.row1 frame $w.row3 frame $w.row4 pack $w.row1 $w.row3 $w.row4 -side top -e y -f both -padx 5 -pady 5 label $w.row1.value_label -text "Selection Value" entry $w.row1.value -textvariable $this-stampvalue pack $w.row1.value_label $w.row1.value -side left button $w.row3.execute -text "Replace" -command "$this replace" pack $w.row3.execute -side top -e n -f both button $w.row4.execute -text "Accumulate" -command "$this accumulate" pack $w.row4.execute -side top -e n -f both }

GUI’s GuiVars Values to from C side tcl_command(...) Initialize C++ side constructor synchs with tcl name tcl side sets the initial value my_var.reset() my_var.get() tcl_command(...) $this-c “needexecute”

Dynamic Compilation Motivation SCIRun::Field Code Explosion Extensibility Maintenance

Dynamic Compilation Field Types (4) TetVol, LatticeVol, ContourField, TriSurf Supported Data Types (9) double, int, char, unsigned char, short, unsigned short, bool, Vector, and Tensor An Algorithm Parameterized on One Field Type Requires 36 Field instantiations And 36 Algorithm Instantiations Parameterized On Two Fields 362 = 1296 Versions of the Algorithm Parameterized On Three Fields 363 = 46656 Versions of the Algorithm Actual implementation supports more Field and Data types Very few of these combinations are needed by any one person or application

template<class Field> RenderField : public RenderFieldBase Algorithm Structure Algorithm Base Class Inherits from common base class Defines the pure virtual interface needed by a module Provides a static CompileInfo Templated Algorithm Implements the pure virtual interface in the base class Potentially specialized for specific field type template<class Field> RenderField : public RenderFieldBase virtual void render(FieldBase&)=0;

TypeDescription TypeDescription object augments RTTI Holds: Strings that describe object’s exact type Namespace string Path to the .h file that declares the object Has a recursive structure Example: foo<bar, foobar<int> >; Bloat. Template code tends to force more and more template code, surrounding it.

CompileInfo Similar info as a TypeDescription Algorithm is not instantiated, so cannot yet be queried Start with a CompileInfo from Algorithm base class Augmented with information from all pertinent TypeDescription objects for the specific types involved Passed to DynamicLoader, which creates the proper type The exact type of an algorithm is composed of the algorithm and a data type. The TypeDescription can be queried from a field type for example, but the algorithm cannot be queried until an instance exists. The CompileInfo has the information required to compile an exact algorithm.

DynamicLoader Returns Requested Algorithm Writes C++ instantiation code Compile shared library, using SCIRun makefiles Load shared library (dlopen) Return Instance of Algorithm (Cached for next use) Synchronization code such that Only 1 thread can compile at a time per algorithm Multiple algorithms can compile and load at the same time This is the object that either writes a .cc file, compiles, loads, and returns the requested algorithm, or simply returns the previously compiled algorithm. Using make helps keep code up to date, and allows compilation costs to be amortized over multiple runs.

No template instantiations for the exact algorithm type Calling Module 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<RenderFieldBase*>(rend_algo); // Let the templated algorithm render this field. rf->render(field_handle, /* any other parameters from gui */); // Send results downstream... }   The input type is known here as a field, could be any of our templated types. We query the TypeDescription from field, then feed this to the Algorithm base class to get the CompileInfo. Now we are ready to ask the DynamicLoader for an instance of the algorithm. We are returned a pointer to the base class, but underneath is the algorithm parameterized on the exact field type. Using the virtual entry to the algorithms real work, we execute the algorithm. This is a single virtual method call. Note also that there is no instantiation here, the only instantiation is in the dynamically loaded library. No template instantiations for the exact algorithm type

Example //! ConvertTetBase supports the dynamically loadable algorithm concept. //! when dynamically loaded the user will dynamically cast to a //! ConvertTetBase from the DynamicAlgoBase they will have a pointer to. class ConvertTetBase : public DynamicAlgoBase { public: virtual FieldHandle convert_quadratic(FieldHandle in) = 0; virtual ~ConvertTetBase(); static const string& get_h_file_path(); static string dyn_file_name(const TypeDescription *td) { // add no extension. return template_class_name() + "." + td->get_filename() + "."; } static const string base_class_name() { static string name("ConvertTetBase"); return name; } static const string template_class_name() { static string name("ConvertTet"); return name; } //! support the dynamically compiled algorithm concept static CompileInfo *get_compile_info(const TypeDescription *td); };

Example template <class Fld> class ConvertTet : public ConvertTetBase { public: //! virtual interface. virtual FieldHandle convert_quadratic(FieldHandle in); }; template <class Fld> FieldHandle ConvertTet<Fld>::convert_quadratic(FieldHandle ifh) { Fld *fld = dynamic_cast<Fld*>(ifh.get_rep()); ASSERT(fld != 0); typedef typename Fld::value_type val_t; FieldHandle fh(QuadraticTetVolField<val_t>::create_from(*fld)); return fh; }

Summary Concepts Ports and Datatypes Modules (Component Wizard) Templated Algorithms Dynamic Loading