Workshop on Grid Application Programming 19th-21st July 2004, Edinburgh, 1 Hartmut Kaiser The C Implementation of the GAT OO Specification Hartmut Kaiser.

Slides:



Advertisements
Similar presentations
Chapter 18 Vectors and Arrays
Advertisements

Dynamic Allocation and Linked Lists. Dynamic memory allocation in C C uses the functions malloc() and free() to implement dynamic allocation. malloc is.
CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
MPI Message Passing Interface
Chapter 18 Vectors and Arrays John Keyser’s Modification of Slides by Bjarne Stroustrup
The C ++ Language BY Shery khan. The C++ Language Bjarne Stroupstrup, the language’s creator C++ was designed to provide Simula’s facilities for program.
Introduction to Programming Lecture 39. Copy Constructor.
C++ Programming Languages
Debugging: Catching Bugs ( I ) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
CS414 C Programming Tutorial Ben Atkin
Classes Separating interface from implementation
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
CS 61C L4 Structs (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #4: Strings & Structs
Unix Network Programming Part 2: Elementary Sockets Jani Peusaari.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles C/C++ Emery Berger and Mark Corner University of Massachusetts.
Dynamic Allocation and Linked Lists. Dynamic memory allocation in C C uses the functions malloc() and free() to implement dynamic allocation. malloc is.
CSE 332: C++ templates and generic programming I Motivation for Generic Programming in C++ We’ve looked at procedural programming –Reuse of code by packaging.
Intro to Generic Programming Templates and Vectors.
POSIX: Files Introduction to Operating Systems: Discussion 1 Read Solaris System Interface Guide: Ch. 5.1 Basic File I/O.
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
Classes Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd Spetember 2006.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look.
LECTURE LECTURE 17 More on Templates 20 An abstract recipe for producing concrete code.
Lecture 22 Miscellaneous Topics 4 + Memory Allocation.
Copy Control Joe Meehean. More Class Responsibilities When making a new type (i.e., class) we must specify what happens when it is: Copied Assigned Destroyed.
Status of SQL and XML I/O Sergey Linev, GSI, Darmstadt, Germany.
Recap, Test 1 prep, Composition and Inheritance. Dates Test 1 – 12 th of March Assignment 1 – 20 th of March.
CS 11 C track: lecture 5 Last week: pointers This week: Pointer arithmetic Arrays and pointers Dynamic memory allocation The stack and the heap.
P Object type and wrapper classes p Object methods p Generic classes p Interfaces and iterators Generic Programming Data Structures and Other Objects Using.
1 Inheritance We are modeling the operation of a transportation company that uses trains and trucks to transfer goods. A suitable class hierarchy for the.
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
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.
1 Inheritance. 2 Why use inheritance?  The most important aspect of inheritance is that it expresses a relationship between the new class and the base.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures C++ Review Part-I.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
CPSC 252 The Big Three Page 1 The “Big Three” Every class that has data members pointing to dynamically allocated memory must implement these three methods:
Object-Oriented Programming Chapter Chapter
Topics memory alignment and structures typedef for struct names bitwise & for viewing bits malloc and free (dynamic storage in C) new and delete (dynamic.
Digging into the GAT API Comparing C, C++ and Python API‘s Hartmut Kaiser
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 4 is due Nov. 20 (next Friday). After today you should know everything you need for assignment.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 12 – C: structs, linked lists, and casts.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
Engineering Classes. Objectives At the conclusion of this lesson, students should be able to: Explain why it is important to correctly manage dynamically.
1 Introduction to Object Oriented Programming Chapter 10.
Real world OS programming Nezer J. Zaidenberg.  Create process/thread  File and directory I/O  I/O multiplexing  Sync and locking  Access system.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 4 is due Nov. 20 (this Friday). Today: –Templates. –STL –Smart Pointers.
Advanced BioPSE NCRR Programming Conventions and Standards J. Davison de St. Germain Chief Software Engineer SCI Institute December 2003 J.
ENEE150 – 0102 ANDREW GOFFIN Abstract Data Types.
Kelly Davis Monitoring and Event System Kelly Davis AEI.
Pyragen A PYTHON WRAPPER GENERATOR TO APPLICATION CORE LIBRARIES Fernando PEREIRA, Christian THEIS - HSE/RP EDMS tech note:
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Abstract classes only used as base class from which other classes can be inherit cannot be used to instantiate any objects are incomplete Classes that.
Motivation for Generic Programming in C++
C++ Catastrophes “if C allows you to shoot yourself in the foot, then C++ is giving you a machine gun!” James Prince.
7. Inheritance and Polymorphism
Review: Two Programming Paradigms
C++, OBJECT ORIENTED PROGRAMMING
CSCI206 - Computer Organization & Programming
Chapter 2 Objects and Classes
Overview of Memory Layout in C++
Object Oriented Programming (OOP) Lecture No. 9
Destructors, Copy Constructors & Copy Assignment Operators
Destructors, Copy Constructors & Copy Assignment Operators
SPL – PS3 C++ Classes.
Presentation transcript:

Workshop on Grid Application Programming 19th-21st July 2004, Edinburgh, 1 Hartmut Kaiser The C Implementation of the GAT OO Specification Hartmut Kaiser MPI for Gravitational Physics, Albert-Einstein-Institut, Golm

Hartmut Kaiser Workshop on Grid Application Programming 19th-21st July 2004, Edinburgh, 2 Outline Design Principles Object orientation Derivation, Interfaces, Genericity Memory Management Object lifetime, Instance tracking, Allocation responsibilities Const Correctness Error Handling Portability Open Source Open problems

Hartmut Kaiser Workshop on Grid Application Programming 19th-21st July 2004, Edinburgh, 3 Object Orientation GAT Specification is object oriented What’s an ‘Object’ Some data and a set of related functions Representation in C Internal struct GATFile_S { /*…*/ } ; External typedef struct GATFile_S *GATFile; Constructor/Destructor GATFile_Create(), GATFile_Destroy() Naming convention GATResult GATFile_Copy(GATFile, /*…*/);

Hartmut Kaiser Workshop on Grid Application Programming 19th-21st July 2004, Edinburgh, 4 Derivation Every GAT object type has to be derived from the GATObject What’s ‘Derivation’ Reuse of common functionality Conversion from and to GATObject should be possible Representation in C Every GAT object type has a common set of functions with an identical signature GATType GATFile_GetType(GATFile_const); GATResult GATFile_Destroy(GATFile *); GATResult GATFile_Clone(GATFile_const, GATFile *); GATResult GATFile_GetInterface(GATFile_const, void **); GATResult GATFile_Equals(GATFile_const, GATFile_const, GATBool *);

Hartmut Kaiser Workshop on Grid Application Programming 19th-21st July 2004, Edinburgh, 5 Derivation Conversion from any GAT type to GATObject should be possible, since all these ‘derived’ from GATObject. Conversion from GATObject to the corresponding GAT type should be possible as well. Representation in C For every GAT type the following functions exist: Succeeds always: GATObject GATFile_ToGATObject(GATFile); GATObject_constGATFile_ToGATObject_const(GATFile_const); Succeeds only, if type matches: GATFile GATObject_ToGATFile(GATObject); GATFile_const GATObject_ToGATFile_const(GATObject_const);

Hartmut Kaiser Workshop on Grid Application Programming 19th-21st July 2004, Edinburgh, 6 Interfaces Certain GAT object types have to implement different interfaces ( GATStreamable, GATMonitorable ) What’s an interface A set of related functions, which may be called even not knowing the type of the object Representation in C Emulation of virtual functions. Every object has a table of function pointers, one table for each interface GetInterface(): helper function to get at the different function pointer tables

Hartmut Kaiser Workshop on Grid Application Programming 19th-21st July 2004, Edinburgh, 7 GATFile Memory Layout

Hartmut Kaiser Workshop on Grid Application Programming 19th-21st July 2004, Edinburgh, 8 Genericity Possibility to call a function for an arbitrary GAT type not knowing the concrete type Representation in C For every interface function exist Concrete function implementation for every GAT type, which realises this interface GATResult GATFile_Serialise(GATFile file, GATObject stream, GATBool cleardirty); Generic function allowing to call the type specific function GATResult GATSerialisable_Serialise(GATObject object, GATObject stream, GATBool cleardirty);

Hartmut Kaiser Workshop on Grid Application Programming 19th-21st July 2004, Edinburgh, 9 Memory Management All GAT object types have a …_Create() function, which returns a new instance of this type. All GAT object types have a …_Destroy function, which frees all associated memory. You are responsible to call …_Destroy! for all objects you’ve created GATFile file = GATFile_Create(location); … /* do something useful with ‘file’ */ GATFile_Destroy(&file); for all non const objects you get back from the engine GATPipe pipe = NULL; GATEndpoint_Connect(endpoint, &pipe); … /* do something useful with ‘pipe’ */ GATPipe_Destry(&pipe);

Hartmut Kaiser Workshop on Grid Application Programming 19th-21st July 2004, Edinburgh, 10 Memory Management The GAT objects returned from the engine are handles! (well actually pointers, but …) typedef struct GATFile_S * GATFile; You’re free to copy around those ‘objects’ without performance harm. But watch out! Don’t free any of these objects while you’re holding copies of it, which you still want to use. Never free a GATObject with free(). If you are using casting functions (as GATObject_ToGATFile ) please note, that the result refers to the same object, so don’t free twice.

Hartmut Kaiser Workshop on Grid Application Programming 19th-21st July 2004, Edinburgh, 11 Const correctness Const correctness introduced wherever possible Helps to enforce semantics, especially for memory management You’ll have to free by yourself all objects and memory blocks given back from the engine, which are not const Objects and memory blocks which are const are controlled by the GAT engine, you don’t want to free these Representation in C First temptation to have: GATFile and GATFile const but this doesn’t give, what we want As a result we’ve got: typedef struct GATFile_S * GATFile; typedef struct GATFile_S const * GATFile_const;

Hartmut Kaiser Workshop on Grid Application Programming 19th-21st July 2004, Edinburgh, 12 Error Handling Every method (except constructor, destructor and certain simple accessors) return a GATResult value Is a structured 32 bit unsigned int: Every CPI based object has additional error tracking inside the associated GATContext: Allows to print an error traceback of the full error history GATContext_GetCurrentStatus(context, &status); GATStatus_ErrorTrace(status);

Hartmut Kaiser Workshop on Grid Application Programming 19th-21st July 2004, Edinburgh, 13 Error Handling (Explicit) #include GATResult RemoteFile_GetFile (GATContext context, char const *source_url, char const *target_url) { GATResult rc = GAT_FAIL; GATStatus status = NULL; GATLocation source = GATLocation_Create (source_url); GATLocation target = GATLocation_Create (target_url); GATFile file = GATFile_Create (context, source, NULL); if (NULL == source || NULL == target || NULL == file) { GATCreateStatus(“RemoteFile_GetFile”, &status, GAT_MEMORYFAILURE, context, __FILE__, __LINE__); return GATContext_SetCurrentStatus (context, &status); } rc = GATFile_Copy(file, target, GATFileMode_Overwrite); if (GAT_FAILED(rc)) { GATCreateStatus(“RemoteFile_GetFile”, &status, rc, context, __FILE__, __LINE__); return GATContext_SetCurrentStatus (context, &status); } GATFile_Destroy (&file); GATLocation_Destroy (&target); GATLocation_Destroy (&source); return GAT_SUCCEEDED; }

Hartmut Kaiser Workshop on Grid Application Programming 19th-21st July 2004, Edinburgh, 14 Error Handling (macros) #include GATResult RemoteFile_GetFile (GATContext context, char const *source_url, char const *target_url) { GAT_USES_STATUS(“RemoteFile_GetFile”, context); GATLocation source = GATLocation_Create (source_url); GATLocation target = GATLocation_Create (target_url); GATFile file = GATFile_Create (context, source, NULL); if (NULL == source || NULL == target || NULL == file) { GAT_CREATE_STATUS(GAT_MEMRORYFAILURE); } else { GAT_CREATE_STATUS(GATFile_Copy(file, target, GATFileMode_Overwrite)); } GATFile_Destroy (&file); GATLocation_Destroy (&target); GATLocation_Destroy (&source); return GAT_RETURN_STATUS(); }

Hartmut Kaiser Workshop on Grid Application Programming 19th-21st July 2004, Edinburgh, 15 Portability All you need is a C compiler and a POSIX conformant library. Dynamic (shared) library support is helpful GAT was compiled on a wide variety of systems Linux, IRIX etc. Windows (Cygwin and native) Macintosh …

Hartmut Kaiser Workshop on Grid Application Programming 19th-21st July 2004, Edinburgh, 16 Open Source Available at CVS access at cvs co wp-1

Hartmut Kaiser Workshop on Grid Application Programming 19th-21st July 2004, Edinburgh, 17 Open problems Memory management is very tedious User has to do a lot by himself Track all GAT object instance copies Free all GAT object instances Call constructor and destructor Error handling is complicated (even with macros) Always check for error codes, cluttered code. All of these problems are solved by the C++ wrapper Asynchronicity is (almost) completely missing Engine is not thread safe as of today