Professional Documents
Culture Documents
IDEAL INSTITUTE
Of Technology, Ghaziabad
(AN ISO 9001 2000 CERTIFIED INSTITUTE)
LAB MANUAL
ADVANCED COMPUTER ARCHITECTURE
(TCS-851)
DEPARTMENT OF COMPUTER
SCIENCE & ENGINEERING
Advanced Computer Architecture Lab (TCS-851)
Page | 1
CN Lab (ECS-651)
INDEX
S. No.
Documents
Page No.
01
02
Syllabus
03
List of Programs
04
05
Program No -01
06
13
07
16
08
09
10
11
12
13
14
19
23
27
30
32
35
37
Page | 2
Lab In-charge
HOD (CS)
GENERAL INSTRUCTIONS
DOs:
1. Switch off mobiles in the lab.
2. Bring your lab record with you.
3. Always come to the lab on time.
4. Maintain silence and be attentive.
5. Keep individual records of observations.
6. Always turn off the computer before leaving the lab.
7. Return all the materials issued to you before leaving
the lab.
8. Read the instruction manual carefully before
performing any experiment.
DONTs:
1. Change current setting.
2. Overcrowed near any equipment.
3. Make any mark on instruction manual.
4. Drag the stool and chair inside the lab.
5. Leave the lab till the class has concluded.
6. Take any material outside the lab with you.
Page | 3
7.
supervision.
SYLLABUS
ADVANCED COMPUTER ARCHITECTURE LAB
(TCS-851)
The following programs should be developed in C language
preferably on UNIX platform.
Programs (3-7) require usage of Parallel Computing APIs:
1. Write a program to execute three POSIX Threads (PThreads)
simultaneously for updating a text file.
2. Write a program for synchronizing POSIX Threads
(PThreads) using (a) Semaphore (b)Mutex
3. Implement the PRAM Algorithm for (a) Parallel Reduction
(b) Prefix Sums (c) Preorder Tree Traversal
4. Implement Parallel Matrix Multiplication using (a) RowColumn oriented Algorithm (b)Block-Oriented Algorithm
5. Implement Solution of Linear Systems using (a) Gaussian
Elimination (b) Jacobi Algorithm
6. Implement (a) Parallel Quick Sort (b) Hyper Quicksort
7. Implement Parallel Fast Fourier Transform Algorithm.
Page | 4
S. No.
Program
No.
1.
Prog.-1
2.
Prog.-2
3.
Prog.-3
4.
Prog.-4
5.
Prog.-5
6.
Prog.-6
7.
Prog.-7
8.
Prog.-8
Beyond Syllabus
9.
Prog.-9
10.
Prog.-10
Page | 5
Lab In-Charge
HOD (CS)
Software
Linux
Page | 6
PROGRAM NO: 01
DEPARTMENT OF COMPUTER
SCIENCE & ENGINEERING
Page | 7
Program No: 1
TITLE- Basics of UNIX command
1.1 Objective 1.2 Theory
1.1 OBJECTIVE: Basics of Unix in terms of commands.
1.2 THEORY:
1.
cat
This is one of the most flexible Unix commands. We can use to create, view and
concatenate files. For our first example we create a three-item English-Spanish dictionary
in a file called "dict."
% cat >dict
red rojo
green verde
blue azul
<control-D>
%
<control-D> stands for "hold the control key down, then tap 'd'". The symbol > tells the
computer that what is typed is to be put into the file dict. To view a file we use cat in a
different way:
2.
chmod
This command is used to change the permissions of a file or directory. For example to
make a file essay.001 readable by everyone, we do this:
% chmod a+r essay.001
To make a file, e.g., a shell script mycommand executable, we do this
Advanced Computer Architecture Lab (TCS-851)
Page | 8
% chmod +x mycommand
Now we can run mycommand as a command.
To check the permissions of a file, use ls -l . For more information on chmod, use man
chmod.
3.
cd
Use cd to change directory. Use pwd to see what directory you are in.
% cd english
% pwd
% /u/ma/jeremy/english
% ls
novel poems
% cd novel
% pwd
% /u/ma/jeremy/english/novel
% ls
ch1 ch2 ch3 journal scrapbook
4.
cp
grep
Use this command to search for information in a file or files. For example, suppose that
we have a file dict whose contents are
red rojo
green verde
blue azul
white blanco
black negro
Then we can look up items in our file like this;
Advanced Computer Architecture Lab (TCS-851)
Page | 9
head
letter2
letter3
maple-assignment1
Note that you have six files. There are some useful variants of the ls command:
% ls l*
letter1 letter2 letter3
%
Note what happened: all the files whose name begins with "l" are listed. The asterisk (*)
is the " wildcard" character. It matches any string.
8.
lpr
This is the standard Unix command for printing a file. It stands for the ancient "line
printer." See
% man lpr
Page | 10
9.
more
More is a command used to read text files. For example, we could do this:
% more poems
The effect of this to let you read the file "poems ". It probably will not fit in one screen,
so you need to know how to "turn pages". Here are the basic commands:
mv
rsh
Use this command if you want to work on a computer different from the one you are
currently working on. One reason to do this is that the remote machine might be faster.
For example, the command
% rsh solitude
Advanced Computer Architecture Lab (TCS-851)
Page | 11
connects you to the machine solitude. This is one of our public workstations and is
fairly fast.
13.
tail
tar
Use create compressed archives of directories and files, and also to extract directories and
files from an archive. Example:
% tar -tvzf foo.tar.gz
displays the file names in the compressed archive foo.tar.gz while
% tar -xvzf foo.tar.gz
extracts the files.
15.
wc
Use this command to count the number of characters, words, and lines in a file. Suppose,
for example, that we have a file dict with contents
red rojo
green verde
blue azul
white blanco
black negro
Then we can do this
% wc dict
5
10
56 tmp
Page | 12
PROGRAM NO: 02
DEPARTMENT OF COMPUTER
SCIENCE & ENGINEERINGPage | 13
Advanced Computer Architecture Lab (TCS-851)
IDEAL INSTITUTE OF TECHNOLOGY, GHAZIABAD
Program No: 2
TITLE Execution of Pthreads
1.1 Objective 1.2 Theory 1.3 Flow chart /Algorithm 1.4. Coding .1.5 Output 1.6
Questions
Page | 14
Creates a new thread, initializes its attributes, and makes it run able.
The pthread_create subroutine creates a new thread and initializes its attributes using the
thread attributes object specified by the attr parameter. The new thread inherits its
creating thread's signal mask; but any pending signal of the creating thread will be
cleared for the new thread.
The new thread is made runnable, and will start executing the start_routine routine, with
the parameter specified by the arg parameter. The arg parameter is a void pointer; it can
reference any kind of data. It is not recommended to cast this pointer into a scalar data
type (int for example), because the casts may not be portable.
The pthread_create subroutine returns the new thread identifier via the thread argument.
The caller can use this thread identifier to perform various operations on the thread. This
identifier should be checked to ensure that the thread was successfully created.
Page | 15
Questions:
Q1:
Q2:
Q3:
PROGRAM NO: 03
DEPARTMENT OF COMPUTER
SCIENCE & ENGINEERINGPage | 16
Advanced Computer Architecture Lab (TCS-851)
IDEAL INSTITUTE OF TECHNOLOGY, GHAZIABAD
Program No: 3
TITLE Synchronization of POSIX thread using Semaphores.
1.1 Objective 1.2 Theory 1.3 Logic 1.4. Coding .1.5 Output 1.6 Questions
1.2 THEORY:
What is a Thread?
Technically, a thread is defined as an independent stream of instructions that can
be scheduled to run as such by the operating system. But what does this mean?
To the software developer, the concept of a procedure that runs independently
from its main program may best describes a thread.
What are Pthreads?
Historically, hardware vendors have implemented their own proprietary versions
of threads. These implementations differed substantially from each other making
it difficult for programmers to develop portable threaded applications.
In order to take full advantage of the capabilities provided by threads, a
standardized programming interface was required. For UNIX systems, this
interface has been specified by the IEEE POSIX 1003.1c standard (1995).
Implementations which adhere to this standard are referred to as POSIX threads,
Page | 17
Synchronization
Synchronization is a problem in timekeeping which requires the coordination of events
to operate a system in unison. The familiar conductor of an orchestra serves to keep the
orchestra in time. Systems operating with all their parts in synchrony are said to be
synchronous or in sync. Some systems may be only approximately synchronized, or
plesiochronous. For some applications relative offsets between events need to be
determined, for others only the order of the event is important.
Synchronization using condition variables
Condition variables provide yet another way for threads to synchronize. While
mutexes implement synchronization by controlling thread access to data,
condition variables allow threads to synchronize based upon the actual value of
data.
1.3 LOGIC:
This simple example code demonstrates the use of several Pthread condition variable
routines. The main routine creates three threads. Two of the threads perform work and
update a "count" variable. The third thread waits until the count variable reaches a
specified value.
This program locks mutex and wait for signal. Note that the pthread_cond_wait
routine will automatically and atomically unlock mutex while it waits. Also, note that if
COUNT_LIMIT is reached before this routine is run by the waiting thread, the loop will
be skipped to prevent pthread_cond_wait from never returning.
Advanced Computer Architecture Lab (TCS-851)
Page | 18
1.4 QUESTIONS:
Q1:
Q2:
ADVANCED
COMPUTER
ARCHITECTURE
Why the synchronization
is necessary in pthreads?
(TCS-851)
Q3:
PROGRAM NO: 04
DEPARTMENT OF COMPUTER
SCIENCE & ENGINEERINGPage | 19
Advanced Computer Architecture Lab (TCS-851)
IDEAL INSTITUTE OF TECHNOLOGY, GHAZIABAD
Program No: 4
TITLE Synchronization of POSIX thread using mutex variable.
1.1 Objective 1.2 Theory 1.3 Logic 1.4. Coding .1.5 Output 1.6 Questions
1.1 OBJECTIVE: Write a Program for synchronizing POSIX thread using Mutex
variable.
1.2 THEORY :
What is a Thread?
Page | 20
interface has been specified by the IEEE POSIX 1003.1c standard (1995).
Implementations which adhere to this standard are referred to as POSIX threads,
or Pthreads. Most hardware vendors now offer Pthreads in addition to their
proprietary API's.
Pthreads are defined as a set of C language programming types and procedure
calls, implemented with a pthread.h header/include file and a thread library though the this library may be part of another library, such as libc.
Synchronization
Synchronization is a problem in timekeeping which requires the coordination of events
to operate a system in unison. The familiar conductor of an orchestra serves to keep the
orchestra in time. Systems operating with all their parts in synchrony are said to be
synchronous or in sync. Some systems may be only approximately synchronized, or
plesiochronous. For some applications relative offsets between events need to be
determined, for others only the order of the event is important.
Mutex variable:
A mutex lock is the simplest form of lock, providing mutually exclusive access (hence
the term mutex) to a shared resource. Threads wanting to access a resource protected
by a mutex lock must first acquire the lock. Only one thread at a time may acquire the
lock. Any other threads attempting to acquire the lock are blocked until the owner
relinquishes it.
Mutex is an abbreviation for "mutual exclusion". Mutex variables are one of the primary
means of implementing thread synchronization and for protecting shared data when
multiple writes occur.
A mutex variable acts like a "lock" protecting access to a shared data resource. The basic
concept of a mutex as used in Pthreads is that only one thread can lock (or own) a mutex
variable at any given time. Thus, even if several threads try to lock a mutex only one
thread will be successful. No other thread can own that mutex until the owning thread
unlocks that mutex. Threads must "take turns" accessing protected data.
1.3 LOGIC:
This program illustrates the use of mutex variables in a threads program that performs a
dot product. The main data is made available to all threads through a globally accessible
structure. Each thread works on a different part of the data. The main thread waits for all
the threads to complete their computations, and then it prints the resulting sum.
The function dot prod is activated when the thread is created. All input to this routine is
obtained from a structure of type DOTDATA and all output from this function is written
into
Page | 21
This structure. The benefit of this approach is apparent for the multi-threaded program:
when a thread is created we pass a single argument to the activated function - typically
this argument
is a thread number. All the other information required by the function is accessed from
the globally accessible structure.
The main program creates threads which do all the work and then print out result upon
completion. Before creating the threads, the input data is created. Since all threads update
a shared structure, we need a mutex for mutual exclusion. The main thread needs to wait
for
all threads to complete, it waits for each one of the threads. We specify a thread attribute
value that allows the main thread to join with the threads it creates. Note also that we free
up handles when they are no longer needed.
1.4 QUESTIONS:
Q1:
Q2:
Q3:
Page | 22
PROGRAM NO: 05
DEPARTMENT OF COMPUTER
SCIENCE & ENGINEERING Page | 23
Advanced Computer Architecture Lab (TCS-851)
IDEAL INSTITUTE OF TECHNOLOGY, GHAZIABAD
Program No: 5
TITLE Linear Systems using Gaussian Elimination
1.1 Objective 1.2 Theory 1.3 Logic 1.4. Coding .1.5 Output 1.6 Questions
1.1 OBJECTIVE: Write a program to find solution of linear system using Gaussian
Elimination.
Page | 24
Matrices are helpful in rewriting a linear system in a very simple form. The algebraic
properties of matrices may then be used to solve systems. First, consider the linear system
Using matrix multiplications, we can rewrite the linear system above as the matrix
equation
As you can see this is far nicer than the equations. But sometimes it is worth to solve the
system directly without going through the matrix form.
As you can see we obtained the same system as before. In fact, we followed the same
elementary operations performed above. In every step the new matrix was exactly the
augmented matrix associated to the new system. This shows that instead of writing the
systems over and over again, it is easy to play around with the elementary row operations
and once we obtain a triangular matrix, write the associated linear system and then solve
it. This is known as Gaussian Elimination.
Gaussian Elimination. Consider a linear system.
1.
Construct the augmented matrix for the system;
2.
Use elementary row operations to transform the augmented matrix into a
triangular one;
3.
Write down the new linear system for which the triangular matrix is the associated
augmented matrix;
Advanced Computer Architecture Lab (TCS-851)
Page | 25
4.
Solve the new system. You may need to assign some parametric values to some
unknowns, and then apply the method of back substitution to solve the new
system.
1.3 LOGIC:
This is the sequential program to solve a linear system Ax = b by using Gaussian
Elimination
Method using scaled column pivoting. In this program
Inputs
A - Matrix A (N by N)
b - Vector b (N by 1)
Outputs
x - Vector x (N by 1)
The given program performs both the forward substitution as well as backward
substation.
1.4 Questions:
Q1:
Q2:
Page | 26
PROGRAM NO: 06
DEPARTMENT OF COMPUTER
SCIENCE & ENGINEERINGPage | 27
Advanced Computer Architecture Lab (TCS-851)
IDEAL INSTITUTE OF TECHNOLOGY, GHAZIABAD
Program No: 6
TITLE Linear Systems using Jacobi method.
1.1 Objective 1.2 Theory 1.3 Logic 1.4. Coding .1.5 Output 1.6 Questions
1.1 OBJECTIVE: Write a program to find solution of linear system using Jacobi
method.
1.2 THEORY:
The Jacobi method is a method of solving a matrix equation on a matrix that has no zeros
along its main diagonal. Each diagonal element is solved for, and an approximate value
plugged in. The process is then iterated until it converges. This algorithm is a strippeddown version of the Jacobi transformation method of matrix digitalization.
The Jacobi method is easily derived by examining each of the equations in the linear
system of equations
in isolation. If, in the th equation
Page | 28
1.3 LOGIC:
We will use the rather simple iterative method, called Jacobi iteration, so a brief review
of that algorithm is in order. Given a system of linear equations, Ax=f, where A is a
symmetric positive definite matrix:
1. Choose matrices D, U, and L, so that A=D-(U+L), D is diagonal, and U and L is
upper and lower triangular.
2. Choose a suitable starting value
3. Calculate
4. Until the error is ``small enough'', repeat the previous step
The question of ``small enough'' is, in addition to being somewhat poorly defined,
difficult to measure, since measuring the error requires knowledge of the exact solution.
Instead, we can measure how close the value of Av is to f. The value Av-f is called the
residue.
1.4 Questions:
Q1:
Q2:
Q3:
Page | 29
PROGRAM NO: 07
DEPARTMENT OF COMPUTER
SCIENCE & ENGINEERING
Page | 30
Program No: 7
TITLE Implementation of parallel Quick sort
1.1 Objective 1.2 Theory & Logic 1.3. Coding .1.4 Output
1.1 OBJECTIVE: Write a program to implement parallel quick sort.
1.2 THEORY& LOGIC:
Parallel Quick sort is a divide-and-conquer algorithm that sorts a sequence by recursively
dividing it into smaller subsequences. Sorting the smaller arrays represents two
completely independent sub problems that can be solved in parallel. Therefore, one way
to parallelize QuickPort is to execute it initially on a single processor; then when the
algorithm performs its recursive calls, assign one of the sub problems to another
processor. Now each of these processors sorts its array by using quick sort and assigns
one of its sub problems to other processors. The algorithm terminates when the arrays
cannot be further partitioned.
1.3 Questions:
Q1:
Q2:
Page | 31
Q3:
PROGRAM NO: 08
DEPARTMENT OF COMPUTER
SCIENCE & ENGINEERING
Page | 32
Program No: 8
TITLE Implementation of Fast Fourier Transformation algorithm
1.1 Objective 1.2 Theory 1.3 Logic 1.4. Coding .1.5 Output1.6 Questions
1.2 THEORY:
The fast Fourier transform (FFT) is a discrete Fourier transform algorithm which reduces
the number of computations needed for points from
to
, where lg is the
base-2 logarithm. If the function to be transformed is not harmonically related to the
sampling frequency, the response of an FFT looks like a sinc function (although the
integrated power is still correct).
FFTs were first discussed by Cooley and Tukey (1965), although Gauss had actually
described the critical factorization step as early as 1805. A discrete Fourier transform can
be computed using an FFT by means of the Danielson-Lanczos lemma if the number of
points is a power of two. If the number of points is not a power of two, a transform
can be performed on sets of points corresponding to the prime factors of which is
Advanced Computer Architecture Lab (TCS-851)
Page | 33
slightly degraded in speed. Prime factorization is slow when the factors are large, but
discrete Fourier transforms can be made fast for
, 3, 4, 5, 7, 8, 11, 13, and 16 .
Fast Fourier transform algorithms generally fall into two classes:
decimation in time, and
decimation in frequency.
The FFT algorithm first rearranges the input elements in bit-reversed order, then builds
the output transform (decimation in time). The basic idea is to break up a transform of
length into two transforms of length
using the identity
1.3 LOGIC:
An example of the fast Fourier transform subroutine with N = 2**M. AR and AI are the
real and imaginary part of data in the input and corresponding Fourier coefficients in the
output. This program rearrange the data to the bit reversed order .This program computes
an in-place complex -to-complex FFT:
x and y are the real and imaginary arrays of 2^m points.
dir = 1 gives forward transform
dir = -1 gives reverse transform
1.4 Questions:
Q1:
Q2:
Q3:
Page | 34
PROGRAM NO: 09
DEPARTMENT OF COMPUTER
SCIENCE & ENGINEERING Page | 35
Advanced Computer Architecture Lab (TCS-851)
IDEAL INSTITUTE OF TECHNOLOGY, GHAZIABAD
Program No: 9
TITLE Newton Forward Method
1.1 Objective 1.2 Theory 1.3 Logic 1.4. Coding .1.5 Output 1.6 Questions
1.3 LOGIC:
Advanced Computer Architecture Lab (TCS-851)
Page | 36
1.
2.
3.
4.
1.4
Questions:
PROGRAM NO: 10
DEPARTMENT OF COMPUTER
SCIENCE & ENGINEERING Page | 37
Advanced Computer Architecture Lab (TCS-851)
IDEAL INSTITUTE OF TECHNOLOGY, GHAZIABAD
Program No: 10
TITLE Lagrange Method
1.1 Objective 1.2 Theory 1.3 Logic 1.4. Coding .1.5 Output 1.6 Questions
1.3 LOGIC :
1. Input the values of xi , f(xi) and value of x for which f(x) is o be calculated.
Advanced Computer Architecture Lab (TCS-851)
Page | 38
Li ( x )
x xj
x xj
j 0 i
j i
1.4 Questions:
Q1:
Q2:
Page | 39