DSP Lab. Week 2 Matrix multiplication Doug Young Suh Media Lab. Rm401 Last update : September 9, 2015.

Slides:



Advertisements
Similar presentations
Incomplete Structs struct B; struct A { struct B * partner; // other declarations… }; struct B { struct A * partner; // other declarations… };
Advertisements

Numerical Recipes The Art of Scientific Computing (with some applications in computational physics)
Dynamic memory allocation
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Pointer Variables The normal variables hold values. For example, int j; j = 2; Then a reference to j in an expression will be identified with the value.
Programming and Data Structure
C Structures Basics of structures Typedef. Data Hierarchy Byte –8 bits (ASCII character ‘A’ = ) Field –Group of characters (character string “Fred”)
Introduction to Programming Lecture 39. Copy Constructor.
Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
Pointers & Dynamic Memory Allocation Mugurel Ionu Andreica Spring 2012.
By Senem Kumova Metin 1 POINTERS + ARRAYS + STRINGS REVIEW.
Pointer, malloc and realloc 1. Name entered was 6 char, not enough space to put null terminator 2 Array of char.
Agenda  Review: pointer & array  Relationship between pointer & array  Dynamic memory allocation.
C Pointers Systems Programming Concepts. PointersPointers  Pointers and Addresses  Pointers  Using Pointers in Call by Reference  Swap – A Pointer.
C Pointers Systems Programming. Systems Programming: Pointers 2 Systems Programming: 2 PointersPointers  Pointers and Addresses  Pointers  Using Pointers.
Pointers Ethan Cerami Fundamentals of Computer New York University.
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
Pointers CSE 2451 Rong Shi.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 14P. 1Winter Quarter Pointers Lecture 14.
Program structure Four different storage-class specifications: –Automatic (auto): local to a function, normally declared variables are automatic. Does.
POINTERS. 1.a) POINTER EXPRESSIONS Pointer variables can be used in expression If p1 and p2 are properly declared and initialized pointers then following.
Variables and Objects, pointers and addresses: Chapter 3, Slide 1 variables and data objects are data containers with names the value of the variable is.
1 Pointers and Arrays. 2 When an array is declared,  The compiler allocates sufficient amount of storage to contain all the elements of the array in.
CSI2172
DSP Lab. Week 5 complex Doug Young Suh Media Lab. Rm401 Last update : September 16, 2015.
Dynamic memory allocation and Pointers Lecture 4.
Dennis Ritchie 1972 AT & T Bell laboratories (American Telephone and Telegraph) USA 1www.gowreeswar.com.
1 ร. ศ. ดร. สุเทพ มาดารัศมี Understanding Pointers in C Chapter 10 of Programming with C Book.
CSci 125 Lecture 21 Martin van Bommel. Memory Allocation Variable declarations cause compiler to reserve memory to hold values - allocation Global variables.
Week 6: Functions - Part 2 BJ Furman 01OCT2012. The Plan for Today Comments on midterm exam (next week in lab!) Review of functions Scope of identifiers.
Passing Structure to function.  structure to function structure to function  Passing structure to function in C Passing structure to function in C 
Integer Types short month; // half of a machine word int car; // one machine word unsigned long distance; Character Types char c = ‘\0’; // one byte char.
C Programming Lecture 16 Pointers. Pointers b A pointer is simply a variable that, like other variables, provides a name for a location (address) in memory.
Types of Operator Arithmetic operator Relational operator Logical operator Assignment operator Increment or decrement operator(unary) Bitwise operator.
Pointers PART - 2. Pointers Pointers are variables that contain memory addresses as their values. A variable name directly references a value. A pointer.
Arrays, Strings, and Memory. Command Line Arguments #include int main(int argc, char *argv[]) { int i; printf("Arg# Contents\n"); for (i = 0; i < argc;
Data Types Always data types will decide which type of information we are storing into variables In C programming language we are having 3 types of basic.
Week 12 Methods for passing actual parameters to formal parameters.
Lecture 7: Arrays BJ Furman 06OCT2012. The Plan for Today Announcements Review of variables and memory Arrays  What is an array?  How do you declare.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Chapter 1. Experiments and Probabilities Doug Young Suh Media Lab.
DSP Lab. Week 2 Matrix multiplication Doug Young Suh Media Lab. Rm401 Last update : September 9, 2015.
CSE 220 – C Programming Pointers.
Recursion.
Basic notes on pointers in C
Data Type.
Data Type.
DSP Lab. Week 7 CDMA and noise
מיחזור במערכת החינוך.
DSP Lab. Week 1 Drawing sinusoidal waves
Systems Programming Concepts
CS111 Computer Programming
Recursion.
Local Variables, Global Variables and Variable Scope
2-d Arrays.
Introduction to C++ Programming Language
Default Arguments.
Recap Week 2 and 3.
Lecture 2 SCOPE – Local and Global variables
CS111 Computer Programming
Chapter 3 Operators and Expressions
DSP Lab. Week 12 DFT audio Doug Young Suh Media Lab. Rm401
C (and C++) Pointers April 4, 2019.
GPU Lab1 Discussion A MATRIX-MATRIX MULTIPLICATION EXAMPLE.
The Stack.
Data Type.
CS31 Discussion 1H Fall18: week 7
C Pointers Systems Programming.
Pointer Arithmetic By Anand George.
Presentation transcript:

DSP Lab. Week 2 Matrix multiplication Doug Young Suh Media Lab. Rm401 Last update : September 9, 2015

Matrix multiplication MediaLab, Kyunghee University2

Pointer (address) RAM 상의 주소 한번 건너뛰는 byte 수는 type 에 따라 다르다. int 4, short 2, char 1  sizeof(??) 예 ) int a, A[4], *aa; short b,*bb; aa = A+2; A[0] = 3; A[1] = -3; A[2] = 2; A[3] = 1; A[4] = 7; // error!! aa[-1] = 5; aa[1] = 3; // *(aa+1) = 3; 과 같다. bb = (short *)(aa-1) + 1; *(bb+3) = 5; // 어떻게 되나 ? MediaLab, Kyunghee University3 RAM &a A A+1 aa bb 0

Function int set3( ); void main( ){ …. int a; a = set3( ); …. } int set3( ){ return 3; } MediaLab, Kyunghee University4 void set3(int * ); void main( ){ …. int a; set3(&a); …. } void set3(int *b ){ *b = 3; return; } int a; // global void set3( ); void main( ){ …. set3( ); …. } void set3( ){ a = 3; return; } void set3(int * ); void main( ){ …. int *a, x; a = &x; set3(a); …. } void set3(int *b ){ *b = 3; return; } a 에 3 이라는 값을 넣는 함수

C-program (pointer and function) 1. #include 2. #include 3. int matrixMultiplication(int *, int *, int *,int, int, int); 4. float ff; // global variable 5. int main(){ 6. int *A,*B,*C, m,n,p; 7. m=2; n=3, p=2; 8. A = new int[m*n]; B = new int[n*p]; C = new int[m*p]; 9. A[0] = 2;A[1] = 3;A[2] = 4; *(A+n) = 5;A[n*1+1] = 6;A[5] = 7; 10. B[0] = 2; B[1] = 3; B[2] = 5; B[3] = 7; B[4] = 1; *(B+p*2+1) = 3; 11. matrixMultiplication(A, B, C, m, n, p); 12. printf("A\n"); 13. for(int mm=0;mm<m;mm++){ printf("\n"); for(int nn=0;nn<n;nn++) printf(" %3d",A[mm*n+nn]); } 14. return 1; 15. }// end of main 16. int matrixMultiplication(int *a, int *b, int *c,int m, int n, int p){ 17. int dum; 18. for(int j = 0; j<m; j++) 19. for(int k = 0; k<p; k++){ 20. dum = 0; 21. for(int l=0;l<n;l++) dum += a[j*n+l] * b[l*p+k]; 22. c[j*p+k] = dum; 23. } 24. return 1; 25. } MediaLab, Kyunghee University5 main 이라는 function 꼭 하나는 있 어야 … 내가 만든 function 선언 Return type 주고받는 data types

Week 2 assignment MediaLab, Kyunghee University6 // mA  mA’ swap ii and jj-th column void swapcol(int n, int m, int *mA, int *mAd, int ii, int jj); void swapcol(int n, int m, int *mA, int ii, int jj);