ICC++ Language Denition. Andrew A. Chien and Uday S. Reddy 1. May 25, 1995

Similar documents
The Compositional C++ Language. Denition. Abstract. This document gives a concise denition of the syntax and semantics

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

Outline. Computer Science 331. Information Hiding. What This Lecture is About. Data Structures, Abstract Data Types, and Their Implementations

Short Notes of CS201

CS201 - Introduction to Programming Glossary By

Compositional C++ Page 1 of 17


American National Standards Institute Reply to: Josee Lajoie

Intro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a.

CSE 230 Intermediate Programming in C and C++ Functions

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Synchronization SPL/2010 SPL/20 1

Absolute C++ Walter Savitch

Ch. 11: References & the Copy-Constructor. - continued -

Chapter 6 Introduction to Defining Classes

Lexical Considerations

A Short Summary of Javali

The S-Expression Design Language (SEDL) James C. Corbett. September 1, Introduction. 2 Origins of SEDL 2. 3 The Language SEDL 2.

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

1 Lexical Considerations

R/3 System Object-Oriented Concepts of ABAP

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

G Programming Languages Spring 2010 Lecture 13. Robert Grimm, New York University

Review of the C Programming Language

Generating Continuation Passing Style Code for the Co-op Language

Ch. 12: Operator Overloading

Java Primer 1: Types, Classes and Operators

Object-Oriented Design (OOD) and C++

Introduction to Programming Using Java (98-388)

A taxonomy of race. D. P. Helmbold, C. E. McDowell. September 28, University of California, Santa Cruz. Santa Cruz, CA

Introduce C# as Object Oriented programming language. Explain, tokens,

MaanavaN.Com CS1203 OBJECT ORIENTED PROGRAMMING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Chapter 7. - FORTRAN I control statements were based directly on IBM 704 hardware

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Cpt S 122 Data Structures. Introduction to C++ Part II

C++ Coding Standards. 101 Rules, Guidelines, and Best Practices. Herb Sutter Andrei Alexandrescu. Boston. 'Y.'YAddison-Wesley

C++11/14 Rocks. Clang Edition. Alex Korban

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

What is a Class Diagram? A diagram that shows a set of classes, interfaces, and collaborations and their relationships

What is a Class Diagram? Class Diagram. Why do we need Class Diagram? Class - Notation. Class - Semantic 04/11/51

Outline. 1 About the course

Object-Oriented Programming

Review of the C Programming Language for Principles of Operating Systems

Fundamental Concepts and Definitions

Algorithmic "imperative" language

Chapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures

Module 10 Inheritance, Virtual Functions, and Polymorphism

Semantic Analysis. CSE 307 Principles of Programming Languages Stony Brook University

Forward declaration of enumerations

Java: introduction to object-oriented features

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP

Object Oriented Design

Problem Solving with C++

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

SAMOS: an Active Object{Oriented Database System. Stella Gatziu, Klaus R. Dittrich. Database Technology Research Group

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Extending SystemVerilog Data Types to Nets

1. Every program must have at least one class declaration. (*) 2. Every class declared in a program must have a distinct identifier.

Object Oriented Programming. Solved MCQs - Part 2

Acknowledgments 2

The language should have few implementation dependencies and should be simple, so that interactions between language features do not give unexpected b

Lexical Considerations

The Procedure Abstraction

Intermediate Code Generation

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

Tutorial 6. Y. Bernat. Object Oriented Programming 2, Spring Y. Bernat Tutorial 6

IBS Software Services Technical Interview Questions. Q1. What is the difference between declaration and definition?

Semantic Analysis and Type Checking

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

Chapter 7:: Data Types. Mid-Term Test. Mid-Term Test (cont.) Administrative Notes

Inheritance (Chapter 7)

5. Semantic Analysis!

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments

A Linear-C Implementation of Dijkstra's Algorithm. Chung-Hsing Hsu and Donald Smith and Saul Levy. Department of Computer Science. Rutgers University

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

The PCAT Programming Language Reference Manual

Topics in Object-Oriented Design Patterns

Institut fur Informatik, Universitat Klagenfurt. Institut fur Informatik, Universitat Linz. Institut fur Witschaftsinformatik, Universitat Linz

2 Addressing the Inheritance Anomaly One of the major issues in correctly connecting task communication mechanisms and the object-oriented paradigm is

I BSc(IT) [ Batch] Semester II Core: Object Oriented Programming With C plus plus - 212A Multiple Choice Questions.

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

C# Programming in the.net Framework

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

Ch02. True/False Indicate whether the statement is true or false.

Object-Oriented Principles and Practice / C++

Chapter 17: Nested Classes

C++ (Non for C Programmer) (BT307) 40 Hours

The New C Standard (Excerpted material)

2 3. Syllabus Time Event 9:00{10:00 morning lecture 10:00{10:30 morning break 10:30{12:30 morning practical session 12:30{1:30 lunch break 1:30{2:00 a

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms

Implementing Subprograms

Outline. User-dened types Categories. Constructors. Constructors. 4. Classes. Concrete classes. Default constructor. Default constructor

Learning Objectives. C++ For Artists 2003 Rick Miller All Rights Reserved xli

Object Oriented Issues in VDM++

CS201 Latest Solved MCQs

James Newkirk

Purpose of Review. Review some basic C++ Familiarize us with Weiss s style Introduce specific constructs useful for implementing data structures

Jukka Julku Multicore programming: Low-level libraries. Outline. Processes and threads TBB MPI UPC. Examples

Transcription:

ICC++ Language Denition Andrew A. Chien and Uday S. Reddy 1 May 25, 1995 Preface ICC++ is a new dialect of C++ designed to support the writing of both sequential and parallel programs. Because of the signicant investment of programmers and vendors in language skills and tools in C++, one of the major goals is to minimize the dierences with C++. Consequently, this document focuses on the essential elements of ICC++ and how they dier from C++. We describe the concurrency model, object collections (an extension of arrays), and nally discuss the programming restrictions which are recommended to increase the eectiveness of program optimization. In general, the reader should assume that C++ features not discussed are incorporated. This description is not a complete language manual; it is intended to convey the essence of the language design. Some motivation for the design of language features is included but are necessarily terse. For a more complete description, see the \ICC++ Language Reference Manual." 1 Concurrency To introduce concurrency, the programmer relaxes the sequential order of a program, specifying a partial order between statements. In ICC++, partial orders are specied using conc blocks. 2 The denition of conc preserves a sequential view of local variables, and expresses concurrency with respect to shared objects. Syntax: conc f S 1 ;... ; Sn; g Denes a partial order on the statements: Si Sj () i < j and Si ) Sj where Si )Sj indicates that statement Sj is dependent on Si. Statements in a conc block are executed such that if Si )Sj, then Si will be executed completely before Sj is begun. Sj is dependent on Si if 1. any identier which appears in both Si and Sj is assigned in one of them, 1 The authors gratefully acknowledge the contribution of many others to the language design, notably John Plevyak, Vijay Karamcheti, and Julian Dolby. Others who have been involved include Professors Sam Kamin, Sanjay Kale, and Prith Banerjee. In addition, Rob Hasker, Howard Huang, Steven Parkes, and T.K. Lakshman have contributed to the design eort. Any aws in this document or language design are solely the responsibility of the authors. 2 Alternatively the conc declarations can be viewed as pragmas on the blocks, directing the compiler to allow these statements to be reordered or executed in parallel subject to the following rules. 1

2. if Si contains a jump statement. The rst rule ensures that basic data dependences on local variables are enforced. It also allows object operations (via pointers or refs) such as a->b(); a->c(); to execute concurrently. How this concurrency is controlled is discussed in Section 2. Jump statements (as dened in The Annotated C++ Reference Manual) in the second rule gives traditional C++ control ow operations such as continue and break natural semantics, serializing the conc block if they are executed. A conc block exits after all statements within it have returned. As in C++, nested blocks are treated as statements. 2 Objects and Concurrency While the introduction of parallelism is a control structure issue, control of concurrency is a critical issue for encapsulation. In order to support sharing patterns required by dynamic and reference based data structures, ICC++ extends C++ objects with implicit concurrency control. Concurrent objects in ICC++ are dened and created in a fashion similar to C++: class Set { int member_count; integral Element my_elements[]; void insert(thing); ; Set aset; where Element is a previously-dened class. The code above denes a class with an int eld, an Element array eld, and an insert operation, then creates an instance of the class, aset. The integral annotation indicates that my elements[] should be considered part of the object's state for the purposes of concurrency control (see below). Member variables are read and written via accessor functions (dened automatically), so member variable access also fall under this concurrency control. For example, for an instance variable a of type B, there are accessor functions a(void) and void operator.a=(b). Declaring member variables as private makes these accessor functions private. At present accessors cannot be overridden, but this may change in future language revisions. ICC++ calls constructors as in C++, but destructors are more complex. For auto variables, destructors are called when the variable goes out of scope. But, because ICC++ provides automatic storage management, destructors for all other objects are called only when an object is garbage collected (i.e. delete may not cause the destructor to be called immediately). 2.1 Concurrency Control ICC++ constrains the execution of method invocations on an object so that intermediate states created within a member function are not visible. Such method invocations are executed concurrently but in such a way that the eect on the member variables is as if the methods operated one after another. The integral declaration extends this notion of consistency to include the state declared integral. For example, if two insert operations on a Set updated the my elements[] array, those updates would not be interleaved. Syntactively recursive calls (i.e. calls on this) to member functions are allowed and may expose intermediate states. However, such situations are routinely managed by programmers in sequential programs, so no additional language support is provided. friend functions are considered as members of all the objects for which they are friends, 2

and thus can be used to procedurally compose operations on several objects into a single consistent operation. In a distributed memory setting, such multi-object operations can be expensive, so they should be used carefully. 2.2 Concurrency Guarantees In a concurrent language, a programmer must be able to reason about concurrency to ensure progress. ICC++ guarantees that all member function invocations for which the order of execution explicitly cannot aect nal object state (determined by trivial examination of the methods) are guaranteed to execute in parallel. 3 Specic examples for which concurrency is guaranteed include two methods which share no member variables and those that employ read-only sharing of member variables. For syntactically recursive calls, order independence is based on textual inclusion of recursively called methods. Note that these concurrency control rules apply to uses of objects pointed to by integral member variables as well. 3 Collections Collections are an important organizing structure for parallel programs because they form a convenient and natural basis for expression of parallelism as well as the distribution of data. ICC++ extends C++ arrays to produce collections. Collections are objects that encapsulate a set of elements (collection elements), and additional collection state. This integration enables arrays to be manipulated as objects (allowing collection member functions, for example). Because elements are aware that they are part of a collection, they can help implement its composite behavior. In ICC++, object collections are dened as are standard classes, but with a [] appended to the end of a class name. 4 Member variables and member functions can be dened for the element or collection. Collection members are explicitly qualied by the collection type. Each collection element has a private set of the element members, and the collection members form a separate object which is shared across all elements. For example: class Counter[] { int count; int Counter[]::total; ; int thecount(void) { return count; int Counter[]::thetotal(void) { return total; Counter mycounter[10]; Denes a collection type Counter[] and an element type Counter, exposing distinct names for the element and collection types. The elements each have one member variable count and there is one collection member variable total. There are also two member functions: a collection member function, thetotal(), and an element member function, thecount(). Notice that count, an element member variable is scoped within element member function thecount(), and total is 3 Write races that deposit the same value are a tricky case, but ICC++ does not guarantee concurrency for such cases. 4 For compatibility, one can still dene array-style collections implicitly. However, if additional collection member functions or variables are required, an explicit declaration must be used. 3

scoped with the collection member function thetotal(). However, element member variables are not available in collection member functions, nor are collection member variables available within element member functions. The natural consequence of this scoping rule and the serialization model for objects is that element member functions can execute on distinct elements concurrently, and furthermore, element and collection member functions can also execute concurrently. 3.1 Predened Member Functions The member functions below are dened on all collections and their elements. For nested collections (collections of collections), both sets of methods are dened for the types other than the outermost collection and innermost element. Collection member functions: [ ] The subscripting operator indexes elements of the collection. When applied with no argument, an arbitrary element in the collection is returned. size Returns the number of elements in the collection. nearest Returns the nearest element in the collection Element member functions: elementtype[ ]::this In an object of type elementtype, returns a pointer to the enclosing collection. index Returns the element's index within the collection. 3.2 Derivation Collections can inherit from standard classes as well as from other collections. Nested collections can inherit from nested collections of equal or lesser order. For example, a collection can inherit from an ordinary C++ class. Then, the element type is a subclass of the standard class. As shown in Figure 1, the DistAccumulator[] collection is derived from the Accumulator class, and the DistAverage[] collection is derived from the DistAccumulator[] collection type. 3.3 Templates Templates can be exploited to reuse collection structure, much as they are used with ordinary classes. The example below denes a numerical collection with a range of arithmetic functions. The last two lines are collection declarations, and the lattermost assumes that a complex class has been dened elsewhere. Of course, more complex collections can also be dened. template <class T> class Numerical[] : public T { Numerical[]::global_sum(); Numerical[]::min(); ; Numerical<float> X[50]; Numerical<complex> Y[50]; 3.4 Compatibility with Arrays Collections in ICC++ support all of the functionality of built-in C++ arrays. They can be implicitly or explicitly dened, indexed, and passed around. As discussed in Section 4, they cannot be 4

class Accumulator { int total; int sum(void) { return total; int accumulate(int i) { return (total += i); ; class DistAccumulator[] : public Accumulator { int DistAccumulator[]::sum(void) { int subtotal = 0; for(int i = 0; i < size; i++) subtotal += (*this)[i].sum(); return subtotal; int DistAccumulator[]::accumulate(int i) { return (*this)[].accumulate(i); ; // into an arbitrary element class DistAverage[] : public DistAccumulator[] { int count; int collect(int i) { accumulate(i); // Element method, accumulates value count++; // count the nr of items int DistAverage[]::average(void) { int count = 0; conc for(int i = 0; i < size; i++) count += (*this)[i].count; return sum()/count; int DistAverage[]::collect(int i) { (*this)[].collect(i); ; Figure 1: Derivation with Collections 5

represented by pointers (must be declared as collections), and consequently, pointer arithmetic is not a meaningful operation, array subscripting must be used instead. 3.5 Concurrent Loops Each of the C++ looping constructs can be modied by conc: conc for, conc while, and conc do while. Because looping constructs form a natural basis for expressing parallelism, ICC++ employs a simple semantics which exposes cross-iteration concurrency. conc for(a;b;c){ d; conc while (b){ d; c; conc do {d; c; while b; Figure 2: Concurrent looping constructs. For each cases, adding conc indicates a parallel loop. Loop carried dependences are respected for scalar variables; others { array dependences and those through pointer structures { must be enforced explicitly by the programmer. Generally, loops with such dependences will be written as serial loops. Subject to the minimal serialization required to enforce the scalar inter-iteration dependences, the loop iterations may all execute concurrently. However, there are no concurrency guarantees, a sequential execution must be acceptable. As in sequential loops in C++, continue and break skip the remainder of the iteration in which they are executed and exit the loop respectively. This feature allows parallel loops with more complex control ow to be parallelized optimistically. 4 Restrictions for Program Optimization ICC++ supports much of C++, but with several restrictions to enable program analysis, optimization, and automatic storage management. These restrictions have the aect of hiding the underlying storage model from the programmer, and are similar to those proposed by Ellis and Detlefs, but are less restrictive. 5 The following C++ features are disallowed: 1. Interconverting arrays and pointers 2. Pointers to simple types (int, oat, char, etc.), with the exception of those needed for interfacing to external C libraries 3. Unsafe casts 4. Union types 5 Ellis and Detlefs, Safe Ecient Garbage Collection for C++, DEC Systems Research Center Technical Report 102, July 1993. 6

Note that C++ forbids pointer arithmetic on pointers, except within the connes of an array, and ICC++ prohibits the use of pointers to refer to arrays, therefore pointer arithmetic is eectively disallowed. Union types should be represented via derivation. ICC++ allows casts that it can check at compile or runtime, but forbids those that are reinterpretations of memory. In terms of the new cast syntax adopted in the C++ draft standard, this means that static cast<t> is allowed, but some of the casts will be checked at runtime and hence may generate runtime errors. dynamic cast<t*> is permitted and checked at runtime. const cast<t> is also permitted, but reinterpret cast<t> is excluded. 6 5 Advanced Concurrent Programming Features spawn s; creates a new thread, executing the statement s, and the spawn statement completes immediately. s can be any ICC++ statement. Identiers of simple type become read-only in s, preventing unsynchronized interaction between the spawning and the spawned threads. The spawned and spawning threads are scheduled fairly. return s; The return statement is similar to that in C++ returning a value to the current function's caller and resuming execution of that caller. If there is no return, the compiler will automatically insert one if the procedure function does not use reply in any way. void reply( ); // is the return type of the function ICC++ provides a reply function with prototype shown above for each user-dened function. reply returns a value to the function's caller, but does not terminate execution of the current function, allowing caller/callee concurrency. Since reply is a function, a pointer to it can be captured and passed out of the function. Reply functions can be used to delegate responsibility for producing an answer. For example, to support an explicit continuation passing style, programmers can use void functions for each such continuation passing call, and spawn to generate concurrency. For example, spawn reply(forward call(...)) implements tail forwarding where forward call(...) executes and its return value is used as the return value of the current function. 6 Performance Pragmas ICC++ also provides a variety of performance pragmas which allow the programmer to communicate information to the compiler and to control the behavior of the runtime system. Examples include map-aggregate, and new-local which provide placement control for collections and individual objects respectively. local(a,b) tests the relative position of two objects. Additional performance pragmas are being explored for object caching and consistency, as well as for controlling compiler speculation. 6 See The Design and Evolution of C++ for a detailed discussion of the new cast syntax. 7