Chapter 21a Other Library Issues

Size: px
Start display at page:

Download "Chapter 21a Other Library Issues"

Transcription

1 Chapter 21a Other Library Issues Nick Maclaren ix-courses/cplusplus This was written by me, not Bjarne Stroustrup

2 Function Objects These are not the only way to solve the problem But they are the way that C++ does so In some other languages, you can have nested scopes void fred () { int z; void joe () {... = z+3; } } // Not allowed When converting between languages, you often need to use different methodologies to solve the same problem 5

3 Sequence Containers Watch out for vector<bool> - it's anomalous Use <array> when you need an array with a size fixed at compile time otherwise don't bother The STL also has <deque>, <forward_list>, <priority_queue>, <queue> and <stack> Generally, they are not worth bothering with <deque> allows pushing/popping at start as well <forward_list> needs only one pointer, not two The others just add queue and stack restrictions 6

4 Use of Containers I dislike using insert() and erase() on vector This is not because it is unreliable (it isn't) or because it is slow, but because it is unexpected It breaks some invariants of vectors that people will expect False assumptions are one of the main causes of foul bugs Code that is more 'natural' is easier to get right and maintain I much prefer to use vector for vectors and list for lists I recommend leaving optimisation until after you have got the program going and found where the time goes And, even then, optimise only performance-critical code 7

5 The STL's Use of Iterators Why don't I like the STL's use of iterators? As it uses them, they are no safer than C pointers They aren't checked, and mistakes will cause chaos They aren't bound to specific objects, only types You don't have to do the same see exercises 18 and 19 Remember to trap * at position end() Attempting maximum flexibility has its costs It makes debugging much harder It usually makes the code less reliable It adds gotchas, and humans make mistakes 8

6 The STL's Use of Iterators A specific warning: The rules for iterator invalidation are defined but fiendishly complicated If you make ANY change to a container, assume that ALL iterators to it become undefined This includes adding, removing or swapping elements Except as otherwise explicitly specified And even then you need to watch out for C++ version and compiler variation 9

7 Iterators As Such Why don't I like iterators, anyway? They make semantic sense only on 1-D linear sequences There is no canonical ordering for n-d arrays, graph structures (trees, DAG etc.) and so on Their use in unordered maps and sets is a horrible hack The way they are used is very serial, as in while-loops Incompatible with vectorisation or parallelisation And those are the key to future performance Think SSE and multiple cores There are much better approaches, as in Fortran But iterators are what C++ people use 10

8 Example of Problem Try to see what each of these does, but use #include <vector> and not std_lib_facilities.h not and: or: vector<int> p(10,1), q(10,2); vector<int>::iterator r = find(p.begin(),q.end(),2); vector<int>::iterator s = find(p.begin(),q.end(),2); Typically arises when editing to change name Can 'lurk' for years, appearing to work If you check for container match, that error will be trapped But stops you using a few of the more arcane STL facilities 11

9 Other Approaches (1) I much prefer code like the following: template<class T> T::iterator find ( const T & obj, const T::value_type & val) { } T::iterator res = obj.begin(); while (res!= obj.end() && *res!= val) ++res; return res; It's more restrictive (i.e. it uses only the whole array) But it's easier to use and safer Myclass::iterator ptr = find(obj,val); 12

10 Other Approaches (2) But I tend not to do even that for my own classes I prefer to write a member function find() It can can then include class-dependent comparison and checking (especially the latter) It's also even easier to use: Myclass::iterator ptr = obj.find(val); Or even to use indices: int n = obj.find(val); Even the STL does this for things like sorting lists Both of these approaches can be vectorised and parallelised without changing the interface 13

11 The while/for Schism Which is clearer of the following codes? and Myvector::iterator ptr1 = vec1.begin(), ptr2 = vec2.begin(); while (ptr1!= vec.end()) { action(*ptr1,*ptr2); ++ptr1; ++ptr2; } for (int n = 0; n < vec1.size(); ++n) action(vec1[n],vec2[n]); Sometimes I write one, and sometimes the other Do whichever is more natural for your code Also, only the second can be vectorised/parallelised 14

12 A <map> gotcha As the book says, this will add Not there =0 to the map: map<string,int> a; int n = a[ Not there ]; It means that the following won't work: int fred (const map<string,int> & a) { } return a[ Not there ]; I don't love that behaviour much! 15

13 Other Associative Containers The book teaches <map>, <unordered_map> and <set>; ; there is also <unordered_set> Also multi versions, which allow replicated keys Generally, I advise you NOT to use those They are very hard to use correctly This is a generic point, and nothing to do with C++ Most people are far better off creating a simple class, with a value and version number You order them by value and then version number You then write a subclass, which returns an iterator to all entries with a certain value; doing that makes a good exercise 16

14 Unordered Containers These still have iterators I regard this as a horrible aspect, though there are uses It causes unnecessary performance and parallelism problems, and there are better approaches But, with the STL, don't trust the order in any way Two identical sets of keys may have different orders And any add or removal may shuffle the order The only guarantee is the order won't change while: Merely accessing elements Updating elements in place don't even replace them Using query functions like size() 17

15 Other STL Issues The STL containers have multiple ways to do the same thing, but sometimes omit basic function Just create a derived class and add it If you critically need access to its private data: First, stop programming, and think.. Then do one of: Solve your problem another way Use another STL class Use another library Write your own container class Don't import an open source STL class they are foully over-complicated 18

16 The STL and Parallelism It's underspecified and overly restrictive I and others are hoping to get this improved Don't get your hopes up too much The FAIRLY SAFE rules for use in parallel are: You can use separate containers in parallel You can access and update separate elements in place DON'T extend, truncate, insert or erase DON'T even replace them, in general You can replace in <vector>, <array> etc. You can use query functions in parallel with that And NOTHING else! 19

17 STL Algorithms I don't find them useful, except for sort() This ISN'T just because I can easily code even sort() It is because they don't save time or clarify my code Most of them replace just one line of simple code They often need a lot of overhead (e.g. function objects) Software reuse is an excellent principle, and a very bad dogma Pretty well every good engineering principle goes bad when it it is taken beyond the limit of its applicability I will come back to the numeric algorithms later 20

18 Software Reuse Always ask yourself Do I really need to write this facility can't I import it from somewhere? You can always replace it by your own later, if necessary As a general rule, start by reusing if possible But remember that reusing software creates a dependence on its specification and code Write your own only if you have a solid reason to But, IF you have a solid reason, then do so Performance is very rarely a solid reason 21

19 When to Use the STL Always attempt to use the STL, unless: Using it makes your code messier or less clear You need properties that it does not provide, or it is not explicitly specified to do what you want But at least try extending or deriving from it Just coding and hoping is NOT a good strategy Regrettably, this oten includes numerics and parallelism You have tested and tried your code and the performance is unacceptable And there is a clean method to do a LOT better Back to numerics and parallelism, are we? :-) 22

20 The Questions to Ask The following are some of the questions to ask: Will it be simpler and cleaner, or less so? Will it be more reliable, or less so? Will it be more portable, or less so? Will it be more maintainable, or less so? Will it be more efficient, or less so? This is very much the least important question Which ones depend mainly on your requirements Your skill is a secondary consideration seriously 23

21 When to Reuse Almost always, but do NOT include the source Build using the latest version available to you When there is a standard and stable interface BLAS, LAPACK, MPI, etc. Or there is reliable, portable and stable software NAG, FFTW, PCRE etc. Usually, subject to maintenance, portability etc. When your system has a suitable library MKL, ACML, often Boost etc. When there is suitable open source to include Watch out for copyright rules, maintenance etc. 24

22 When NOT to Reuse Even here, debug your code by reusing, if possible When it doesn't meet your requirements AND extending it is more work than rewriting Adding parallelism is one common example When you need a high level of portability And the available software is too restrictive Regrettably, copyright often forces this When it simply doesn't work on your data And you are absolutely certain it's not your bug This is FAR rarer than most people claim 25

23 Calling C Libraries Write proper C++ wrappers and call from them Do NOT plaster C-style calls all over your code Similarly for using external variables And C macros defining constants or functions Headers with fancy macros are a nightmare They can completely break the STL headers Best to keep all C interfaces in separate files Export only proper C++ interfaces This can be non-trivial, but is most needed when it is hardest to do sorry, but that's C for you 26

24 Calling Fortran You have to do it via C, but it can be done BLAS, LAPACK etc. are usually in Fortran 77 I give more details on calling them a later lecture You can do it more cleanly in modern Fortran C++ is not formally supported, and you need to take care There is some information in my Fortran course 27

25 Boost The STL is over-complicated for its function Boost takes this to a whole new level One chapter needs a whole BOOK of documentation It's a collection of contributed libraries They overlap, and vary in quality It's monolithic, with a foul build mechanism Even on an x86 Linux system, it often fails It's usually fairly simple to configure round that Porting it is the stuff of nightmares 28

26 Boost But, a lot of people use it successfully Watch out if you need to collaborate Yes, YOU can install Boost, but can THEY? And is it portable or reliable over time? The C++ standard itself isn't great on that It's a real pain if you just one one facility Each class can drag in dozens of others Your build time can go through the roof And the size of your executables, of course 29

27 Domain-specific Libraries Many areas collaborate through libraries Often used to read and write file formats Not much option, if you want to collaborate Mixing two such libraries can be a right pain Often best done by writing two separate programs I cannot offer any meaningful advice here 30

28 Exercise Exercise 16: Repeat exercise 7, but use a function that takes a container and a value as argument Return the position or -1 if not found, and test all of not found, below the lowest, and above the highest 31

29 Next lecture Numerics 32

Chapter 24a More Numerics and Parallelism

Chapter 24a More Numerics and Parallelism Chapter 24a More Numerics and Parallelism Nick Maclaren http://www.ucs.cam.ac.uk/docs/course-notes/un ix-courses/cplusplus This was written by me, not Bjarne Stroustrup Numeric Algorithms These are only

More information

Chapter 18 Vectors and Arrays [and more on pointers (nmm) ] Bjarne Stroustrup

Chapter 18 Vectors and Arrays [and more on pointers (nmm) ] Bjarne Stroustrup Chapter 18 Vectors and Arrays [and more on pointers (nmm) ] Bjarne Stroustrup www.stroustrup.com/programming Abstract arrays, pointers, copy semantics, elements access, references Next lecture: parameterization

More information

Message-Passing and MPI Programming

Message-Passing and MPI Programming Message-Passing and MPI Programming More on Point-to-Point 6.1 Introduction N.M. Maclaren nmm1@cam.ac.uk July 2010 These facilities are the most complicated so far, but you may well want to use them. There

More information

Chapter 17 vector and Free Store. Bjarne Stroustrup

Chapter 17 vector and Free Store. Bjarne Stroustrup Chapter 17 vector and Free Store Bjarne Stroustrup www.stroustrup.com/programming Overview Vector revisited How are they implemented? Pointers and free store Allocation (new) Access Arrays and subscripting:

More information

Introduction to OpenMP

Introduction to OpenMP 1.1 Minimal SPMD Introduction to OpenMP Simple SPMD etc. N.M. Maclaren Computing Service nmm1@cam.ac.uk ext. 34761 August 2011 SPMD proper is a superset of SIMD, and we are now going to cover some of the

More information

Introduction to OpenMP. Tasks. N.M. Maclaren September 2017

Introduction to OpenMP. Tasks. N.M. Maclaren September 2017 2 OpenMP Tasks 2.1 Introduction Introduction to OpenMP Tasks N.M. Maclaren nmm1@cam.ac.uk September 2017 These were introduced by OpenMP 3.0 and use a slightly different parallelism model from the previous

More information

Introduction to the Course

Introduction to the Course Introduction to the Course Nick Maclaren http://www.ucs.cam.ac.uk/docs/course-notes/unix- courses/cplusplus Some of the slides in this lecture are the copyright of Bjarne Stroustrup, but they are not marked

More information

Introduction to OpenMP

Introduction to OpenMP Introduction to OpenMP p. 1/?? Introduction to OpenMP Simple SPMD etc. Nick Maclaren nmm1@cam.ac.uk September 2017 Introduction to OpenMP p. 2/?? Terminology I am badly abusing the term SPMD tough The

More information

Introduction to OpenMP

Introduction to OpenMP Introduction to OpenMP p. 1/?? Introduction to OpenMP Synchronisation Nick Maclaren Computing Service nmm1@cam.ac.uk, ext. 34761 June 2011 Introduction to OpenMP p. 2/?? Summary Facilities here are relevant

More information

Programming with MPI

Programming with MPI Programming with MPI p. 1/?? Programming with MPI One-sided Communication Nick Maclaren nmm1@cam.ac.uk October 2010 Programming with MPI p. 2/?? What Is It? This corresponds to what is often called RDMA

More information

Programming with MPI

Programming with MPI Programming with MPI p. 1/?? Programming with MPI Point-to-Point Transfers Nick Maclaren nmm1@cam.ac.uk May 2008 Programming with MPI p. 2/?? Digression Most books and courses teach point--to--point first

More information

Introduction to OpenMP

Introduction to OpenMP Introduction to OpenMP p. 1/?? Introduction to OpenMP Tasks Nick Maclaren nmm1@cam.ac.uk September 2017 Introduction to OpenMP p. 2/?? OpenMP Tasks In OpenMP 3.0 with a slightly different model A form

More information

Message-Passing and MPI Programming

Message-Passing and MPI Programming Message-Passing and MPI Programming More on Collectives N.M. Maclaren Computing Service nmm1@cam.ac.uk ext. 34761 July 2010 5.1 Introduction There are two important facilities we have not covered yet;

More information

Programming with MPI

Programming with MPI Programming with MPI p. 1/?? Programming with MPI Miscellaneous Guidelines Nick Maclaren Computing Service nmm1@cam.ac.uk, ext. 34761 March 2010 Programming with MPI p. 2/?? Summary This is a miscellaneous

More information

Chapter 5 Errors. Bjarne Stroustrup

Chapter 5 Errors. Bjarne Stroustrup Chapter 5 Errors Bjarne Stroustrup www.stroustrup.com/programming Abstract When we program, we have to deal with errors. Our most basic aim is correctness, but we must deal with incomplete problem specifications,

More information

Programming with MPI

Programming with MPI Programming with MPI p. 1/?? Programming with MPI Composite Types and Language Standards Nick Maclaren Computing Service nmm1@cam.ac.uk, ext. 34761 March 2008 Programming with MPI p. 2/?? Composite Types

More information

Programming with MPI

Programming with MPI Programming with MPI p. 1/?? Programming with MPI Miscellaneous Guidelines Nick Maclaren nmm1@cam.ac.uk March 2010 Programming with MPI p. 2/?? Summary This is a miscellaneous set of practical points Over--simplifies

More information

Software Design and Development

Software Design and Development Software Design and Development p. 1/?? Software Design and Development Introduction and Principles Nick Maclaren nmm1@cam.ac.uk September 2017 Software Design and Development p. 2/?? Apologia There is

More information

static CS106L Spring 2009 Handout #21 May 12, 2009 Introduction

static CS106L Spring 2009 Handout #21 May 12, 2009 Introduction CS106L Spring 2009 Handout #21 May 12, 2009 static Introduction Most of the time, you'll design classes so that any two instances of that class are independent. That is, if you have two objects one and

More information

1 of 5 5/11/2006 12:10 AM CS 61A Spring 2006 Midterm 2 solutions 1. Box and pointer. Note: Please draw actual boxes, as in the book and the lectures, not XX and X/ as in these ASCII-art solutions. Also,

More information

Message-Passing and MPI Programming

Message-Passing and MPI Programming Message-Passing and MPI Programming 5.1 Introduction More on Datatypes and Collectives N.M. Maclaren nmm1@cam.ac.uk July 2010 There are a few important facilities we have not covered yet; they are less

More information

G52CPP C++ Programming Lecture 20

G52CPP C++ Programming Lecture 20 G52CPP C++ Programming Lecture 20 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Wrapping up Slicing Problem Smart pointers More C++ things Exams 2 The slicing problem 3 Objects are not

More information

Introduction to OpenMP

Introduction to OpenMP Introduction to OpenMP p. 1/?? Introduction to OpenMP More Syntax and SIMD Nick Maclaren nmm1@cam.ac.uk September 2017 Introduction to OpenMP p. 2/?? C/C++ Parallel for (1) I said that I would give the

More information

Message-Passing and MPI Programming

Message-Passing and MPI Programming Message-Passing and MPI Programming Communicators etc. N.M. Maclaren nmm1@cam.ac.uk July 2010 7.1 Basic Concepts A group is a set of process identifiers; programs view them as integers in the range 0...(size-1),

More information

CSCI-1200 Data Structures Fall 2018 Lecture 22 Hash Tables, part 2 & Priority Queues, part 1

CSCI-1200 Data Structures Fall 2018 Lecture 22 Hash Tables, part 2 & Priority Queues, part 1 Review from Lecture 21 CSCI-1200 Data Structures Fall 2018 Lecture 22 Hash Tables, part 2 & Priority Queues, part 1 the single most important data structure known to mankind Hash Tables, Hash Functions,

More information

Programming with MPI

Programming with MPI Programming with MPI p. 1/?? Programming with MPI Debugging, Performance and Tuning Nick Maclaren Computing Service nmm1@cam.ac.uk, ext. 34761 March 2008 Programming with MPI p. 2/?? Available Implementations

More information

PPP Style Guide Stroustrup 1/29/2010. PPP Style Guide. Bjarne Stroustrup

PPP Style Guide Stroustrup 1/29/2010. PPP Style Guide. Bjarne Stroustrup PPP Style Guide Bjarne Stroustrup Introduction All major real-world software projects have a house style ( coding guide-lines, project standard or whatever they are called) to ensure clarity and consistency.

More information

Introduction to Modern Fortran

Introduction to Modern Fortran Introduction to Modern Fortran p. 1/?? Introduction to Modern Fortran Advanced Use Of Procedures Nick Maclaren nmm1@cam.ac.uk March 2014 Introduction to Modern Fortran p. 2/?? Summary We have omitted some

More information

COEN244: Class & function templates

COEN244: Class & function templates COEN244: Class & function templates Aishy Amer Electrical & Computer Engineering Templates Function Templates Class Templates Outline Templates and inheritance Introduction to C++ Standard Template Library

More information

A function is a named piece of code that performs a specific task. Sometimes functions are called methods, procedures, or subroutines (like in LC-3).

A function is a named piece of code that performs a specific task. Sometimes functions are called methods, procedures, or subroutines (like in LC-3). CIT Intro to Computer Systems Lecture # (//) Functions As you probably know from your other programming courses, a key part of any modern programming language is the ability to create separate functions

More information

When we program, we have to deal with errors. Our most basic aim is correctness, but we must

When we program, we have to deal with errors. Our most basic aim is correctness, but we must Chapter 5 Errors When we program, we have to deal with errors. Our most basic aim is correctness, but we must deal with incomplete problem specifications, incomplete programs, and our own errors. When

More information

Programming with Haiku

Programming with Haiku Programming with Haiku Lesson 2 Written by DarkWyrm All material 2010 DarkWyrm In our first lesson, we learned about how to generalize type handling using templates and some of the incredibly flexible

More information

These are notes for the third lecture; if statements and loops.

These are notes for the third lecture; if statements and loops. These are notes for the third lecture; if statements and loops. 1 Yeah, this is going to be the second slide in a lot of lectures. 2 - Dominant language for desktop application development - Most modern

More information

QUIZ Friends class Y;

QUIZ Friends class Y; QUIZ Friends class Y; Is a forward declaration neeed here? QUIZ Friends QUIZ Friends - CONCLUSION Forward (a.k.a. incomplete) declarations are needed only when we declare member functions as friends. They

More information

The Stack, Free Store, and Global Namespace

The Stack, Free Store, and Global Namespace Pointers This tutorial is my attempt at clarifying pointers for anyone still confused about them. Pointers are notoriously hard to grasp, so I thought I'd take a shot at explaining them. The more information

More information

Introduction to OpenMP

Introduction to OpenMP Introduction to OpenMP p. 1/?? Introduction to OpenMP Intermediate OpenMP Nick Maclaren nmm1@cam.ac.uk September 2017 Introduction to OpenMP p. 2/?? Summary This is a miscellaneous collection of facilities

More information

Const Correctness. Ali Malik

Const Correctness. Ali Malik Const Correctness Ali Malik malikali@stanford.edu Game Plan Recap Const Everything Prep for Next Time Announcements Recap Recap: References Another name for an already existing object. int x = 15; int

More information

printf( Please enter another number: ); scanf( %d, &num2);

printf( Please enter another number: ); scanf( %d, &num2); CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

More information

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between MITOCW Lecture 10A [MUSIC PLAYING] PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between all these high-level languages like Lisp and the query

More information

1 Getting used to Python

1 Getting used to Python 1 Getting used to Python We assume you know how to program in some language, but are new to Python. We'll use Java as an informal running comparative example. Here are what we think are the most important

More information

Late Binding; OOP as a Racket Pattern

Late Binding; OOP as a Racket Pattern Late Binding; OOP as a Racket Pattern Today Dynamic dispatch aka late binding aka virtual method calls Call to self.m2() in method m1 defined in class C can resolve to a method m2 defined in a subclass

More information

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module Basic Class Design Goal of OOP: Reduce complexity of software development by keeping details, and especially changes to details, from spreading throughout the entire program. Actually, the same goal as

More information

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file? QUIZ on Ch.5 Why is it sometimes not a good idea to place the private part of the interface in a header file? Example projects where we don t want the implementation visible to the client programmer: The

More information

So on the survey, someone mentioned they wanted to work on heaps, and someone else mentioned they wanted to work on balanced binary search trees.

So on the survey, someone mentioned they wanted to work on heaps, and someone else mentioned they wanted to work on balanced binary search trees. So on the survey, someone mentioned they wanted to work on heaps, and someone else mentioned they wanted to work on balanced binary search trees. According to the 161 schedule, heaps were last week, hashing

More information

Performance Evaluation

Performance Evaluation Performance Evaluation Chapter 4 A Complicated Queuing System (Acknowledgement: These slides have been prepared by Prof. Dr. Holger Karl) 1 Goal of this chapter! Understand implementation issues and solutions

More information

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead. Chapter 9: Rules Chapter 1:Style and Program Organization Rule 1-1: Organize programs for readability, just as you would expect an author to organize a book. Rule 1-2: Divide each module up into a public

More information

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++ CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 19 Introduction to C++ C++ C++ is an enormous language: All of C Classes and objects (kind of like Java, some crucial differences) Many

More information

Programming. Dr Ben Dudson University of York

Programming. Dr Ben Dudson University of York Programming Dr Ben Dudson University of York Outline Last lecture covered the basics of programming and IDL This lecture will cover More advanced IDL and plotting Fortran and C++ Programming techniques

More information

Chapter 5 Errors. Hyunyoung Lee. Based on slides by Bjarne Stroustrup.

Chapter 5 Errors. Hyunyoung Lee. Based on slides by Bjarne Stroustrup. Chapter 5 Errors Hyunyoung Lee Based on slides by Bjarne Stroustrup www.stroustrup.com/programming 1 Abstract When we program, we have to deal with errors. Our most basic aim is correctness, but we must

More information

Chapter 3 Objects, types, and values. Bjarne Stroustrup

Chapter 3 Objects, types, and values. Bjarne Stroustrup Chapter 3 Objects, types, and values Bjarne Stroustrup www.stroustrup.com/programming Overview Strings and string I/O Integers and integer I/O Types and objects Type safety 3 Input and output // read first

More information

Introduction to OpenMP

Introduction to OpenMP Introduction to OpenMP p. 1/?? Introduction to OpenMP Basics and Simple SIMD Nick Maclaren nmm1@cam.ac.uk September 2017 Introduction to OpenMP p. 2/?? Terminology I am abusing the term SIMD tough Strictly,

More information

CSE 100: C++ TEMPLATES AND ITERATORS

CSE 100: C++ TEMPLATES AND ITERATORS CSE 100: C++ TEMPLATES AND ITERATORS Announcements iclickers: Please register at ted.ucsd.edu. Start ASAP!! For PA1 (Due next week). 10/6 grading and 10/8 regrading How is Assignment 1 going? A. I haven

More information

Introduction to OpenMP

Introduction to OpenMP Introduction to OpenMP Intermediate OpenMP N.M. Maclaren Computing Service nmm1@cam.ac.uk ext. 34761 August 2011 1.1 Summary This is a miscellaneous collection of facilities, most of which are potentially

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

Programming with MPI

Programming with MPI Programming with MPI p. 1/?? Programming with MPI More on Datatypes and Collectives Nick Maclaren nmm1@cam.ac.uk May 2008 Programming with MPI p. 2/?? Less Basic Collective Use A few important facilities

More information

Learning to Provide Modern Solutions

Learning to Provide Modern Solutions 1 Learning to Provide Modern Solutions Over the course of this book, you will learn to enhance your existing applications to modernize the output of the system. To do this, we ll take advantage of the

More information

TDDD38 - Advanced programming in C++

TDDD38 - Advanced programming in C++ TDDD38 - Advanced programming in C++ Course introduction Eric Elfving Department of Computer and information science 1 What is TDDD38 Syllabus Organization Exam Literature Plan 2 What is C++? History Design

More information

2 ADT Programming User-defined abstract data types

2 ADT Programming User-defined abstract data types Preview 2 ADT Programming User-defined abstract data types user-defined data types in C++: classes constructors and destructors const accessor functions, and inline functions special initialization construct

More information

Introduction to OpenMP

Introduction to OpenMP Introduction to OpenMP p. 1/?? Introduction to OpenMP More Syntax and SIMD Nick Maclaren Computing Service nmm1@cam.ac.uk, ext. 34761 June 2011 Introduction to OpenMP p. 2/?? C/C++ Parallel for (1) I said

More information

Linked Lists. What is a Linked List?

Linked Lists. What is a Linked List? Linked Lists Along with arrays, linked lists form the basis for pretty much every other data stucture out there. This makes learning and understand linked lists very important. They are also usually the

More information

Azon Master Class. By Ryan Stevenson Guidebook #5 WordPress Usage

Azon Master Class. By Ryan Stevenson   Guidebook #5 WordPress Usage Azon Master Class By Ryan Stevenson https://ryanstevensonplugins.com/ Guidebook #5 WordPress Usage Table of Contents 1. Widget Setup & Usage 2. WordPress Menu System 3. Categories, Posts & Tags 4. WordPress

More information

CS 161 Computer Security

CS 161 Computer Security Wagner Spring 2014 CS 161 Computer Security 1/27 Reasoning About Code Often functions make certain assumptions about their arguments, and it is the caller s responsibility to make sure those assumptions

More information

How Computers Handle Numbers

How Computers Handle Numbers How Computers Handle Numbers p. 1/?? How Computers Handle Numbers Some of the Sordid Details Nick Maclaren July 2009 How Computers Handle Numbers p. 2/?? This Is Now Later Explanations of a few of the

More information

Exercise 6.2 A generic container class

Exercise 6.2 A generic container class Exercise 6.2 A generic container class The goal of this exercise is to write a class Array that mimics the behavior of a C++ array, but provides more intelligent memory management a) Start with the input

More information

Debugging. CSE 2231 Supplement A Annatala Wolf

Debugging. CSE 2231 Supplement A Annatala Wolf Debugging CSE 2231 Supplement A Annatala Wolf Testing is not debugging! The purpose of testing is to detect the existence of errors, not to identify precisely where the errors came from. Error messages

More information

Kernel driver maintenance : Upstream vs. Industry

Kernel driver maintenance : Upstream vs. Industry 1 Kernel driver maintenance : Upstream vs. Industry Brice Goglin RMLL Talence - 2010/07/08 Industry contributing to the Linux kernel? 2 Linux developed by people on their free time? 750,000 lines changed

More information

7.1 Some Sordid Details

7.1 Some Sordid Details Introduction to OpenMP Critical Guidelines N.M. Maclaren nmm1@cam.ac.uk October 2018 7.1 Some Sordid Details 7.1.1 Apologia and Refrain The previous lectures were an oversimplification, and roughly translate

More information

Overview of C Feabhas Ltd 2012

Overview of C Feabhas Ltd 2012 1 2 Copying objects may not be the best solution in many situations. In such cases we typically just want to transfer data from one object to another, rather than make an (expensive, and then discarded)

More information

Math Modeling in Java: An S-I Compartment Model

Math Modeling in Java: An S-I Compartment Model 1 Math Modeling in Java: An S-I Compartment Model Basic Concepts What is a compartment model? A compartment model is one in which a population is modeled by treating its members as if they are separated

More information

Parallel Programming (1)

Parallel Programming (1) Parallel Programming (1) p. 1/?? Parallel Programming (1) Introduction and Scripting Nick Maclaren nmm1@cam.ac.uk February 2014 Parallel Programming (1) p. 2/?? Introduction (1) This is a single three--session

More information

// Initially NULL, points to the dynamically allocated array of bytes. uint8_t *data;

// Initially NULL, points to the dynamically allocated array of bytes. uint8_t *data; Creating a Data Type in C Bytes For this assignment, you will use the struct mechanism in C to implement a data type that represents an array of bytes. This data structure could be used kind of like a

More information

Chapter 17 vector and Free Store

Chapter 17 vector and Free Store Chapter 17 vector and Free Store Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/~hkaiser/fall_2010/csc1253.html Slides adapted from: Bjarne Stroustrup, Programming Principles and Practice using

More information

Free Downloads C++ Coding Standards: 101 Rules, Guidelines, And Best Practices

Free Downloads C++ Coding Standards: 101 Rules, Guidelines, And Best Practices Free Downloads C++ Coding Standards: 101 Rules, Guidelines, And Best Practices Consistent, high-quality coding standards improve software quality, reduce time-to-market, promote teamwork, eliminate time

More information

Introduction to Modern Fortran

Introduction to Modern Fortran Introduction to Modern Fortran p. 1/?? Introduction to Modern Fortran More About I/O and Files Nick Maclaren Computing Service nmm1@cam.ac.uk, ext. 34761 November 2007 Introduction to Modern Fortran p.

More information

CSCI-1200 Data Structures Spring 2018 Lecture 14 Associative Containers (Maps), Part 1 (and Problem Solving Too)

CSCI-1200 Data Structures Spring 2018 Lecture 14 Associative Containers (Maps), Part 1 (and Problem Solving Too) CSCI-1200 Data Structures Spring 2018 Lecture 14 Associative Containers (Maps), Part 1 (and Problem Solving Too) HW6 NOTE: Do not use the STL map or STL pair for HW6. (It s okay to use them for the contest.)

More information

Lecturer: William W.Y. Hsu. Programming Languages

Lecturer: William W.Y. Hsu. Programming Languages Lecturer: William W.Y. Hsu Programming Languages Chapter 9 Data Abstraction and Object Orientation 3 Object-Oriented Programming Control or PROCESS abstraction is a very old idea (subroutines!), though

More information

CE221 Programming in C++ Part 1 Introduction

CE221 Programming in C++ Part 1 Introduction CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab

More information

Documentation Nick Parlante, 1996.Free for non-commerical use.

Documentation Nick Parlante, 1996.Free for non-commerical use. Documentation Nick Parlante, 1996.Free for non-commerical use. A program expresses an algorithm to the computer. A program is clear or "readable" if it also does a good job of communicating the algorithm

More information

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

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE? 1. Describe History of C++? The C++ programming language has a history going back to 1979, when Bjarne Stroustrup was doing work for his Ph.D. thesis. One of the languages Stroustrup had the opportunity

More information

Chapter 11 Customizing I/O

Chapter 11 Customizing I/O Chapter 11 Customizing I/O Bjarne Stroustrup www.stroustup.com/programming Overview Input and output Numeric output Integer Floating point File modes Binary I/O Positioning String streams Line-oriented

More information

Week - 01 Lecture - 04 Downloading and installing Python

Week - 01 Lecture - 04 Downloading and installing Python Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 01 Lecture - 04 Downloading and

More information

(8 1) Container Classes & Class Templates D & D Chapter 18. Instructor - Andrew S. O Fallon CptS 122 (October 8, 2018) Washington State University

(8 1) Container Classes & Class Templates D & D Chapter 18. Instructor - Andrew S. O Fallon CptS 122 (October 8, 2018) Washington State University (8 1) Container Classes & Class Templates D & D Chapter 18 Instructor - Andrew S. O Fallon CptS 122 (October 8, 2018) Washington State University Key Concepts Class and block scope Access and utility functions

More information

I m sure you have been annoyed at least once by having to type out types like this:

I m sure you have been annoyed at least once by having to type out types like this: Type Inference The first thing I m going to talk about is type inference. C++11 provides mechanisms which make the compiler deduce the types of expressions. These features allow you to make your code more

More information

Read & Download (PDF Kindle) Data Structures And Other Objects Using C++ (4th Edition)

Read & Download (PDF Kindle) Data Structures And Other Objects Using C++ (4th Edition) Read & Download (PDF Kindle) Data Structures And Other Objects Using C++ (4th Edition) Data Structures and Other Objects Using C++ takes a gentle approach to the data structures course in C++. Providing

More information

JUnit Test Patterns in Rational XDE

JUnit Test Patterns in Rational XDE Copyright Rational Software 2002 http://www.therationaledge.com/content/oct_02/t_junittestpatternsxde_fh.jsp JUnit Test Patterns in Rational XDE by Frank Hagenson Independent Consultant Northern Ireland

More information

Function Templates. Consider the following function:

Function Templates. Consider the following function: Function Templates Consider the following function: void swap (int& a, int& b) { int tmp = a; a = b; b = tmp; Swapping integers. This function let's you swap the contents of two integer variables. But

More information

Programming Languages. Streams Wrapup, Memoization, Type Systems, and Some Monty Python

Programming Languages. Streams Wrapup, Memoization, Type Systems, and Some Monty Python Programming Languages Streams Wrapup, Memoization, Type Systems, and Some Monty Python Quick Review of Constructing Streams Usually two ways to construct a stream. Method 1: Use a function that takes a(n)

More information

CS 32. Lecture 5: Templates

CS 32. Lecture 5: Templates CS 32 Lecture 5: Templates Vectors Sort of like what you remember from Physics but sort of not Can have many components Usually called entries Like Python lists Array vs. Vector What s the difference?

More information

OpenACC Course. Office Hour #2 Q&A

OpenACC Course. Office Hour #2 Q&A OpenACC Course Office Hour #2 Q&A Q1: How many threads does each GPU core have? A: GPU cores execute arithmetic instructions. Each core can execute one single precision floating point instruction per cycle

More information

Overview. Rationale Division of labour between script and C++ Choice of language(s) Interfacing to C++ Performance, memory

Overview. Rationale Division of labour between script and C++ Choice of language(s) Interfacing to C++ Performance, memory SCRIPTING Overview Rationale Division of labour between script and C++ Choice of language(s) Interfacing to C++ Reflection Bindings Serialization Performance, memory Rationale C++ isn't the best choice

More information

CMSC 341 Lecture 6 Templates, Stacks & Queues. Based on slides by Shawn Lupoli & Katherine Gibson at UMBC

CMSC 341 Lecture 6 Templates, Stacks & Queues. Based on slides by Shawn Lupoli & Katherine Gibson at UMBC CMSC 341 Lecture 6 Templates, Stacks & Queues Based on slides by Shawn Lupoli & Katherine Gibson at UMBC Today s Topics Data types in C++ Overloading functions Templates How to implement them Possible

More information

Proofwriting Checklist

Proofwriting Checklist CS103 Winter 2019 Proofwriting Checklist Cynthia Lee Keith Schwarz Over the years, we ve found many common proofwriting errors that can easily be spotted once you know how to look for them. In this handout,

More information

Guide to First-Order Logic Translations

Guide to First-Order Logic Translations Guide to First-Order Logic Translations Hi everybody! In last Friday's lecture, we talked about how to translate statements from English into frst-order logic. Translating into logic is a skill that takes

More information

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

C++ Coding Standards. 101 Rules, Guidelines, and Best Practices. Herb Sutter Andrei Alexandrescu. Boston. 'Y.'YAddison-Wesley C++ Coding Standards 101 Rules, Guidelines, and Best Practices Herb Sutter Andrei Alexandrescu 'Y.'YAddison-Wesley Boston Contents Prefaee xi Organizational and Poliey Issues 1 o. Don't sweat the small

More information

Lambda Correctness and Usability Issues

Lambda Correctness and Usability Issues Doc No: WG21 N3424 =.16 12-0114 Date: 2012-09-23 Reply to: Herb Sutter (hsutter@microsoft.com) Subgroup: EWG Evolution Lambda Correctness and Usability Issues Herb Sutter Lambda functions are a hit they

More information

Manage Music Iphone 5

Manage Music Iphone 5 How To Make Itunes Update Manually Manage Music Iphone 5 A computer (Windows or Mac), An iphone, ipad, or ipod, The USB cable that came Check the Manually manage music and videos box under "Options" (in.

More information

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture 15 Branching : IF ELSE Statement We are looking

More information

Session 4b: Review of Program Quality

Session 4b: Review of Program Quality Session 4b: Review of Program Quality What makes one program "better" than another? COMP 170 -- Fall, 2013 Mr. Weisert What is a good program? Suppose we give the same assignment to two programmers (or

More information

CS11 Advanced C++ Fall Lecture 7

CS11 Advanced C++ Fall Lecture 7 CS11 Advanced C++ Fall 2006-2007 Lecture 7 Today s Topics Explicit casting in C++ mutable keyword and const Template specialization Template subclassing Explicit Casts in C and C++ C has one explicit cast

More information

CS193D Handout 10 Winter 2005/2006 January 23, 2006 Pimp Your Classes

CS193D Handout 10 Winter 2005/2006 January 23, 2006 Pimp Your Classes CS193D Handout 10 Winter 2005/2006 January 23, 2006 Pimp Your Classes See also: The middle part of Chapter 9 (194-208), Chapter 12 Pretty much any Object-Oriented Language lets you create data members

More information