Appendix A: Source Code

Similar documents
Linked-List Basic Examples. A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links

Computer Science Foundation Exam

Advanced optimizations of cache performance ( 2.2)

Q1 Q2 Q3 Q4 Q5 Q6 Total

Data Structures CHAPTER 11. Review Questions. Multiple-Choice Questions. Exercises. (Solutions to Odd-Numbered Problems)

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each).

SYSC 2006 C Winter 2012

Lecture 6 Sorting and Searching

Advanced Caching Techniques (2) Department of Electrical Engineering Stanford University

CSC 270 Survey of Programming Languages. What is a Pointer?

CSE 143. Linked Lists. Linked Lists. Manipulating Nodes (1) Creating Nodes. Manipulating Nodes (3) Manipulating Nodes (2) CSE 143 1

Data Structures and Algorithms for Engineers

C Programming, Autumn 2013, Exercises for the Second Week

SOFTWARE Ph.D. Qualifying Exam Fall 2017

Example of usage of Prefix Sum Compacting an Array. Example of usage of Prexix Sum Compacting an Array

Pointers, Dynamic Data, and Reference Types

CSCI2467: Systems Programming Concepts

Chapter 2: Memory Hierarchy Design Part 2

Lecture notes for CS Chapter 2, part 1 10/23/18

CP2 Revision. theme: dynamic datatypes & data structures

Lab 4 - Linked Lists

A Shotgun Introduction to C

CSCI 2132 Software Development. Lecture 17: Functions and Recursion

Chapter 2: Memory Hierarchy Design Part 2

Pointers: 2 Operators:

DUKE UNIVERSITY Department of Computer Science. Test 1: CompSci 100

Solution for Data Structure

CS 137 Part 5. Pointers, Arrays, Malloc, Variable Sized Arrays, Vectors. October 25th, 2017

Write a program that creates in the main function two linked lists of characters and fills them with the following values:

CSC D70: Compiler Optimization Prefetching

CS 223: Data Structures and Programming Techniques. Exam 2

CSL 201 Data Structures Mid-Semester Exam minutes

ECE 2400 Computer Systems Programming Fall 2017 Topic 4: C Pointers

Chapter 5 7. num = 0 repeat: if (num is Odd ) print (num is Odd) num = num + 1 until (num < 50) 11. Suppose N is the given integer.

Ashish Gupta, Data JUET, Guna

Pointers. Pointers. Pointers (cont) CS 217

CPSC 213, Summer 2017, Term 2 Midterm Exam Solution Date: July 27, 2017; Instructor: Anthony Estey

Recitation 7 Caches and Blocking. 9 October 2017

Pointers (part 1) What are pointers? EECS We have seen pointers before. scanf( %f, &inches );! 25 September 2017

Pointers. Lecture 1 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 14, 2015

Variables, Pointers, and Arrays

Data Structures and Algorithms. Roberto Sebastiani

Algorithm Efficiency & Sorting. Algorithm efficiency Big-O notation Searching algorithms Sorting algorithms

Section I B COMPUTER SCIENCE SOLUTION

Programming Abstractions

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

Arrays and Pointers: Review and Examples

Parameter passing. Programming in C. Important. Parameter passing... C implements call-by-value parameter passing. UVic SEng 265

Practice question Answers

ECE 190 Final Exam. Practice exam

Pointers as Arguments

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #12

The time and space are the two measure for efficiency of an algorithm.

(6) The specification of a name with its type in a program. (7) Some memory that holds a value of a given type.

CS 223: Data Structures and Programming Techniques. Exam 2. April 19th, 2012

Expressions and Statements. Department of CSE, MIT, Manipal

Programm- & Systemverifikation

[0569] p 0318 garbage

Test 1: CPS 100. Owen Astrachan. February 23, 2000

Pointers and Structure. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

MTH 307/417/515 Final Exam Solutions

Chapter 20: Binary Trees

Arrays. CS10001: Programming & Data Structures. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur

Review of the Lectures 21-26, 30-32

Bentley Rules for Optimizing Work

CS 171: Introduction to Computer Science II. Linked List. Li Xiong

B-Trees. nodes with many children a type node a class for B-trees. an elaborate example the insertion algorithm removing elements

Linked Lists. .. and other linked structures. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

CSL 860: Modern Parallel

2016 Spring COP 3502 Final Exam. Date: 4/28/2016. Name:

Introduction to the Analysis of Algorithms. Algorithm

Computer Science /21/2000

Part XI. Algorithms and Templates. Philip Blakely (LSC) C++ Introduction 314 / 370

Elementary Data Structures: Lists

Dynamic Data Structures

Computer Science Foundation Exam

Pointers. Addresses in Memory. Exam 1 on July 18, :00-11:40am

ANSI C Reserved Words

Binary Trees. Examples:

Computer Science Foundation Exam

Data Structure. Chapter 11. Objectives After studying this chapter, students should be able to: 11-1 ARRAYS

Lesson 12: Recursion, Complexity, Searching and Sorting. Modifications By Mr. Dave Clausen Updated for Java 1_5

CS 310 Advanced Data Structures and Algorithms

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

FOR Loop. FOR Loop has three parts:initialization,condition,increment. Syntax. for(initialization;condition;increment){ body;

Storage class and Scope:

INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator

Dynamic Memory Allocation

Agenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011

Data Structures And Algorithms

C++ ARRAYS POINTERS POINTER ARITHMETIC. Problem Solving with Computers-I

Lab 5 - Linked Lists Git Tag: Lab5Submission

Arrays in C. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur. Basic Concept

CS 2461: Computer Architecture 1

PERFORMANCE OPTIMISATION

Introduction to Scientific Computing and Problem Solving

Arrays. An array is a collection of several elements of the same type. An array variable is declared as array name[size]

Intermediate Programming, Spring 2017*

Arrays and Pointers (part 1)

Data Abstractions. National Chiao Tung University Chun-Jen Tsai 05/23/2012

Transcription:

vector.c and vectors a[] and c[] to yield s2 */ for (int i = 0; i < SIZE_N; i++) for (int i = 0; i < SIZE_N; i++) vector_fused.c and vectors a[] and c[] to yield s2 with loop fusion */ vector_prefetch.c and vectors a[] and c[] to yield s2 with prefetch */ prefetch(c[i+50]); Appendix A: Source Code

vector_fused_prefetch.c and vectors a[] and c[] to yield s2 fused loops with prefetch */ prefetch(c[i+50]); vector2.c vectors a[] and b[] to yield sums s1[] and s2[] */ for (int i = START1; i < END1; i++) s1[i - START1] = a[i] + b[i]; for (int i = START2; i < END2; i++) s2[i - START2] = a[i] + b[i];

vector2_fused.c vectors a[] and b[] to yield sums s1[] and s2[] with loop fusion */ for (int i = START1; i < START2; i++) for (int i = START2; i < END1; i++){ for (int i = END1; i < END2; i++) vector2_prefetch.c vectors a[] and b[] to yield sums s1[] and s2[] */ for (int i = START1; i < END1; i++){ s1[i - START1] = a[i] + b[i]; for (int i = START2; i < END2; i++){ s2[i - START2] = a[i] + b[i];

vector2_fused_prefetch.c vectors a[] and b[] to yield sums s1[] and s2[] with loop fusion and prefetch */ for (int i = START1; i < START2; i++){ prefetch(a[i + 50]); prefetch(b[i + 50]); for (int i = START2; i < END1; i++){ prefetch(a[i + 50]); prefetch(b[i + 50]); for (int i = END1; i < END2; i++){ prefetch(a[i + 50]); prefetch(b[i + 50]); vector3.c vectors a[] and b[] to yield s1[] */ 0 for (int i = 0; i < SIZE_N; i += 10000) vector3_merged.c vectors a[] and b[] to yield s1[] with merged arrays */ 0 struct vector_ab_type{ int a; int b; vector_ab[size_n]; for (int i = 0; i < SIZE_N; i += 10000) s1[i] = vector_ab[i].a + vector_ab[i].a;

vector3_prefetch.c vectors a[] and b[] to yield s1[] */ 0 for (int i = 0; i < SIZE_N; i += 10000){ vector3_merged_prefetch.c vectors a[] and b[] to yield s1[] with merged arrays */ 0 struct vector_ab_type{ int a; int b; vector_ab[size_n]; for (int i = 0; i < SIZE_N; i += 10000){ prefetch(vector_ab[i+50]); s1[i] = vector_ab[i].a + vector_ab[i].a; linkedlist.c /*copies elements out of a linked list into an array */ #define SIZE 10000000 struct linked{ *linked next; *linked start; /*code to fill list here assume a 10,000,000 null-terminated list */ *linked temp = start; int a[size], index=0; while (temp->next) { a[index++] = temp->data; temp = temp->next;

linkedlist_prefetch.c /*copies elements out of a linked list into an array with prefetching */ #define SIZE 10000000 struct linked{ *linked next; *linked start; /*code to fill list here assume a 10,000,000 null-terminated list */ *linked temp = start, temp2 = start; int a[size], index=0; for (int i = 0; i < 100; i++) temp2 = temp2->next; while (temp->next){ a[index++] = temp->data; temp = temp->next; /*be careful not to dereference NULL pointers */ if (temp2->next){ temp2 = temp2->next; prefetch(temp2->next); binarytree.c /*searches a binary tree */ struct node{ *node left, right; *node top; /*cost function that returns a pointer to the next node and flags if it's done searching*/ *node next_node(*node current, int value, int & found); /*code to fill tree here */ *node temp = top; int search_value, found=0; do{ temp = next_node(temp, search_value, found); until (found);

binarytree_prefetch.c /*searches a binary tree speculatively prefetches */ struct node{ *node left, right; *node top; /*cost function that returns a pointer to the next node and flags if it's done searching*/ *node next_node(*node current, int value, int & found); /*code to fill tree here */ *node temp = top; int search_value, found=0; do{ if (temp->left) prefetch(temp->left); if (temp->right) prefetch(temp->right); temp = next_node(temp, search_value, found); until (found);