programming laboratory-iii - wordpress.com · to understand how to connect beagle bone black ... to...

57
T.E. Computer Engineering Programming Laboratory - III Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4 PROGRAMMING LABORATORY-III Subject Code: 310254 Prepared By: Prof. Anand N. Gharu 2016 17

Upload: nguyencong

Post on 21-Jun-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

PROGRAMMING LABORATORY-III

Subject Code: 310254

Prepared By:

Prof. Anand N. Gharu

2016 – 17

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

PVG's COLLEGE OF ENGINEERING, NASHIK

Department Computer Engineering

Class: TE (Computer) Semester and Year: II & 2016-17

Subject: Programming Laboratory – IV PR: 50 OR: 50

Sr.

No Assignment Name

Group A:

1 Develop an application using Beagle bone Black/ ARM Cortex A5 development board to

simulate the operations of LIFT.

2 Develop an application using Beaglebone Black/ ARM Cortex A5 development board to

simulate the working of signal lights.

3 Implement an calculator (64 bit Binary Multiplication) application using concurrent lisp.

4

A. Design mathematical model of the Application/system using set theory, algebraic

system, relations and functions, Deterministic and Non-Deterministic entities.

B. Analyze requirements from the Problem statement, mathematical model, Domain

requirements and identify Functional, Nonfunctional, Actors, Use cases for the

application/system. Create usecase diagram, activity diagram/swim lane diagram for

each usecase.

C. Design the architecture for the system/application using package diagram ,

deployment diagram. Design classes using class diagram.

D. Design the behavior of the system/application using state machine diagram and

sequence diagram.

5 Create Project plan, SRS, Design document and Test Plan for one group-C assignment from

embedded operating system or Concurrent and Distributed Programming.

6 Write an application to parse input text file concurrently and compare the result of

concurrent parsing with serial parsing ( Use concurrent YACC parser)

Group B:

1 Write an application to and demonstrate the change in BeagleBoard/ ARM Cortex A5

/Microprocessor /CPU frequency or square wave of programmable frequency.

2 Implement a Parallel Quick Sort algorithm using NVIDIA GPU or equivalent ARM board

3 Implement a Parallel ODD-Even Sort algorithm using GPU or ARM equivalent.

4 Implement n-ary search algorithm using OPENMP

5 Develop a network based application by setting IP address on BeagleBoard/ARM Cortex

A5.

6 Implement a Multi-threading application for echo server using socket programming in Java.

7 Implement Reader-Writer problem using OPENMP

Group C:

1 Develop Robotics (stepper motor) Application using Beagle Board.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Assignment No: A-1

Aim:

Develop an application using Beagle bone Black/ ARM Cortex A5 development board to

simulate the operations of LIFT.

Objective:

To understand how to connect beagle bone black development board to Computer System.

To understand the lift operation by accessing data from beaglebone black development board

using Cloud 9 IDE.

Theory:

What is Beaglebone Black Development Board?

In robotics, the most popular embedded systems start with Raspberry Pi, and continue

with Arduino, BeagleBone, and a few others in a small proportion. Like other embedded

computer controllers, the BeagleBone Black come packed with a bunch of free software for

development to start making things right out of the box. The BBB has advantages as well as

disadvantages compared with other single board computers. The ARM architecture that forms

the basis for processor provides a huge advantage in almost anything that’s battery powered, it

has 512 MB DDR3, built-in ADC, on-board storage, and many options for GPIO pins. As

disadvantages, I can include the default operating system preinstalled on BBB, and a small

community for embedded systems compared with Raspberry Pi or Arduino.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

The low cost Beaglebone Black was initially intended for academic use where is

required an easy accessibility to extensive technology. Built with powerful features for

embedded systems, the Black becomes quickly a single board computer used by experienced

hobbyists and hackers focused on a wide range of applications including automation, education,

arts, or for industrial use.

With a price under $50, the credit-card sized computer includes a 1GHz ARM Cortex-

A8 processor, a pair of PRU 32-bit RISC CPUs, 512MB of RAM, 2GB of built-in storage space,

and a MicroSD slot to expand the capacity of the memory.For connectivity the SBC support

USB, Ethernet, micro-HDMI connections, while for your electronics project are available 2 x 46

pin headers.The standard version of BBB comes preinstalled with the Ångström Linux operating

system, and it should be a system able to start making things right out of the box. The

preinstalled operating system is only one from many features that make from Beaglebone Black

a smarter embedded system compared with Raspberry Pi.

Another feature capable of increasing the speed of prototyping things is the browser-

based applications that allow you to access the GUI and control the board right from the

browser. Before starting browsing inside the Black, you have to link the board to the Internet,

plug in a keyboard and a mouse via USB, and connect the board via the HDMI port to a

monitor.The GUI allows you to control all the functions of the computer while you can access a

database with programming lessons and start to develop applications.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Operating Systems for Beaglebone Black

The embedded system from Texas Instruments comes preinstalled with the Ångström

Linux operating system and has support for other popular distribution including Debian,

Android, or Ubuntu. The Ångström Linux operating system runs from the on-board eMMC

memory, and in addition to the eMMC, you can boot directly from the MicroSD card.

Ångström Linux – it’s the preferred operating system for Black and customized for embedded

devices. It may be found in several versions, and depending on how long you purchased the

BBB, you can check and install the latest version.

Debian – it’s one of the most popular operating system for embedded systems with support for

many architectures. The Debian OS can be found on Raspberry Pi and many more single board

computers with a large usage in robotics. The best solution to use Debian on Black is to run the

customized image for the BeagleBone boards.

Android – Android is a very popular operating system for mobile devices such as smartphones

and tablets. Based on the Linux kernel, the Android is a good operating system compatible with

embedded systems and able to support a wide range of applications. At this moment, you can

run on Black the Android 4.2.2 Jelly Bean version using a memory card with at least 4GB

storage space.

Ubuntu – you can run on BeagleBone Black a custom version of Ubuntu, which is available in

several versions with a wide range of improvements for more recent versions.

Programming in Beagle Bone

The BeagleBone Black can be programmed using one of these programming languages:

BoneScript (JavaScript)

Python

Perl

C/C++

Bash

You have several options to connect to the BeagleBone Black:

Serial port (J1)

ssh using USB cable

Keyboard and display

VNC (Virtual Network Connection)

WebBrowser (Cloud9)

Steps To connect Beaglebone Black

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Step 1:- Plug in your Beagle via USB

Use the provided USB cable to plug your Beagle into your computer. This will both power the

board and provide a development interface. BeagleBone Black will boot Linux from the on-

board 2GB eMMC. Either BeagleBone Black or original BeagleBone may also boot from a

microSD card. Original BeagleBone is provided with a pre-configured 4GB microSD card.

BeagleBone or BeagleBone Black will operate as a flash drive providing you with a local copy

of the documentation and drivers. Note that this interface may not be used to re-configure the

microSD card with a new image, but may be used to update the boot parameters using the

uEnv.txt file.

You'll see the PWR LED lit steadily. Within 10 seconds, you should see the other LEDs

blinking in their default configurations.

USR0 is configured at boot to blink in a heartbeat pattern

USR1 is configured at boot to light during microSD card accesses

USR2 is configured at boot to light during CPU activity

USR3 is configured at boot to light during eMMC accesses

Step 2:- Install drivers

Install the drivers for your operating system to give you network-over-USB access to your

Beagle. Additional drivers give you serial access to your board.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Operating

System USB Drivers Comments

Windows

(64-bit) 64-bit installer

If in doubt, try the 64-bit installer first.

Note #1: Windows Driver Certification warning may pop up

two or three times. Click "Ignore", "Install" or "Run"

Note #2: To check if you're running 32 or 64-bit Windows see

this: http://support.microsoft.com/kb/827218.

Note #3: On systems without the latest service release, you

may get an error (0xc000007b). In that case, please install the

following and retry: http://www.microsoft.com/en-

us/download/confirmation.aspx?id=13523.

Note #4: You may need to reboot Windows.

Windows

(32-bit) 32-bit installer

Mac OS X Network

Serial Install both sets of drivers.

Linux mkudevrule.sh

Driver installation isn't required, but you might find a few

udev rules helpful.

Note: Additional FTDI USB to serial/JTAG information and drivers are available

fromhttp://www.ftdichip.com/Drivers/VCP.htm.

Note: Additional USB to virtual Ethernet information and drivers are available

from http://www.linux-usb.org/gadget/and http://joshuawise.com/horndis.

Step 3: - Browse to your Beagle

Using either Chrome or Firefox (Internet Explorer will NOT work), browse to the web server

running on your board. It will load a presentation showing you the capabilities of the board. Use

the arrow keys on your keyboard to navigate the presentation.

Older software images require you to EJECT the BEAGLE_BONE drive to start the network.

With the latest software image, that step is no longer required.

Troubleshooting

One option to browse your board is to use this node-webkit based application (currently limited

to Windows machines):beaglebone-getting-started.zip.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Virtual machines are not recommended when using the direct USB connection. It is

recommended you use only network connections to your board if you are using a virtual

machine.

When using 'ssh' with the provided image, the username is 'root' and the password is blank.

Boot your board off of the SD card

Insert SD card into your (powered-down) board, hold down the USER/BOOT button (if using

Black) and apply power, either by the USB cable or 5V adapter.

Conclusion:

Hence, we have completely connected the system with beaglebone black development

board to demonstrate Lift Operation.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Assignment No: A-2

Aim:

Develop an application using Beaglebone Black/ ARM Cortex A5 development board to

simulate the working of signal lights.

Objective:

To understand how to connect beaglebone black development board to system through IDE.

To simulate the working of signal lights.

Theory:

BoneScript is a JavaScript library to simplify learning how to perform physical computing tasks

using your embedded Linux. This web page is able to interact with your board to provide an

interactive tutorial.

Example

var b = require('bonescript');

b.pinMode('USR0', b.OUTPUT);

b.pinMode('USR1', b.OUTPUT);

b.pinMode('USR2', b.OUTPUT);

b.pinMode('USR3', b.OUTPUT);

b.digitalWrite('USR0', b.HIGH);

b.digitalWrite('USR1', b.HIGH);

b.digitalWrite('USR2', b.HIGH);

b.digitalWrite('USR3', b.HIGH);

setTimeout(restore, 2000);

Running the above example will cause all of your LEDs to light up at once for a couple of

seconds.

Step A: Close any open file tabs

Step B: Click the "+" in the top-right to create a new file.

step C: Cut and paste the following code into the new tab:

var b = require('bonescript');

var state = b.LOW;

b.pinMode("USR0", b.OUTPUT);

b.pinMode("USR1", b.OUTPUT);

b.pinMode("USR2", b.OUTPUT);

b.pinMode("USR3", b.OUTPUT);

setInterval(toggle, 1000);

function toggle() {

if(state == b.LOW) state = b.HIGH;

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

else state = b.LOW;

b.digitalWrite("USR3", state);

}

Step D: Save the file by clicking the disk icon and giving the file a name with the .js extension.

Step E: Run the code by selecting the arrow to the right of "run" (or "debug") in the toolbar to

pull down the list of files to run and select your new file.

Step F: Observe the BeagleBone USR3 LED blinking steadily about 5 times a second.

Step G: Stop the code by clicking "stop" in the toolbar.

Autorun

Once you've finished developing your JavaScript application, you can have it start upon boot-up

by simply dropping it into the 'autorun' subfolder.

The systemdbonescript-autorun.service runs at start-up and uses the

/usr/lib/node_modules/bonescript/autorun.js script to automatically detect when .js files are in

this directory and invoke them as separate processes with node.js. When the files are changed or

moved, the script will kill the processes.

Conclusion:-

In this assignment we are connecting the beaglebone black with the system and using

bone scripting over IDE we can develop the simulation of signals.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Assignment No: A-3

Aim:

Implement an calculator (64 bit Binary Multiplication) application using concurrent lisp.

Objective:

1. To understand the concurrent lisp

2. To construct 64 bit binary multiplication.

Theory:-

Lisp:-

The name LISP derives from "LISt Processing". Linked lists are one of Lisp language's major

data structures, and Lisp source code is itself made up of lists. As a result, Lisp programs can

manipulate source code as a data structure, giving rise to the macro systems that allow

programmers to create new syntax or new domain-specific languages embedded in Lisp.

Lisp (historically, LISP) is a family of computer programming languages with a long history and

a distinctive, fully parenthesized Polish prefix notation Originally specified in 1958, Lisp is the

second-oldest high-level programming language in widespread use today; only Fortran is older

(by one year). Like Fortran, Lisp has changed a great deal since its early days, and a number of

dialects have existed over its history. Today, the most widely known general-purpose Lisp

dialects are Common Lisp and Scheme.

The interchangeability of code and data also gives Lisp its instantly recognizable syntax.

All program code is written as s-expressions, or parenthesized lists. A function call or syntactic

form is written as a list with the function or operator's name first, and the arguments following;

for instance, a function f that takes three arguments might be called using (f arg1 arg2 arg3).

Concurrent lisp:-

Multiprocessor computers are readily available. Most personal computers already have

specialized multiprocessor systems with additional processors handling features such a as

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

graphics or sound. To better use the power inherent in multiprocessor systems, languages with

concurrent tasking must be developed.

The concept of concurrent programming also serves us well on single processor systems.

Many programming projects are best thought of as multitasking jobs, perhaps with intertask

communication. A familiar example of multitasking is the MS-DOS print facility, which copies

a file to the line printer while the computer is being used for other tasks. In a single processor

environment, the concurrent tasks are interleaved (time shared).

concurrent LISP interpreter (CLI) based on a construct that allows simultaneous

evaluation of a list of LISP forms; see Listing One. CLI also allows for intertask

communication. The native language for CLI is Gold Hill Computers' Golden Common LISP;

other full-featured LISPs should allow a parallel .

SBCL:-

Steel Bank Common Lisp (SBCL) is a high performance Common Lisp compiler. It is

open source / free software, with a permissive license. In addition to the compiler and runtime

system for ANSI Common Lisp, it provides an interactive environment including a debugger, a

statistical profiler, a code coverage tool, and many other extensions.

SBCL runs on a number of POSIX platforms, and experimentally on Windows. See the

download page for supported platforms, and getting started guide for additional help.

(make-thread (lambda () (write-line "Hello, world")))

— Structure: sb-thread:thread

Class precedence list: thread, structure-object, t

Thread type. Do not rely on threads being structs as it may change in future versions.

— Variable: sb-thread:*current-thread*

Bound in each thread to the thread itself.

— Function: sb-thread:make-thread function &key name

Create a new thread of name that runs function. When the function returns the thread

exits.

— Function: sb-thread:thread-alive-p thread

Check if thread is running.

— Function: sb-thread:list-all-threads

Return a list of the live threads.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

— Condition: sb-thread:interrupt-thread-error

Class precedence list: interrupt-thread-error, error, serious-condition, condition, t

Interrupting thread failed.

— Function: sb-thread:interrupt-thread-error-thread condition

The thread that was not interrupted.

— Function: sb-thread:interrupt-thread thread function

Interrupt the live thread and make it run function. A moderate degree of care is expected

for use of interrupt-thread, due to its nature: if you interrupt a thread that was holding important

locks then do something that turns out to need those locks, you probably won't like the effect.

— Function: sb-thread:terminate-thread thread

Terminate the thread identified by thread, by causing it to run sb-ext:quit - the usual

cleanup forms will be evaluated

Conclusion:-

In this assignment we have developed concurrent 64-bit matrix multiplication using

concurrent LISP.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Assignment No: A-4

Aim:

A. Design mathematical model of the Application/system using set theory, algebraic

system, relations and functions, Deterministic and Non-Deterministic entities.

B. Analyze requirements from the Problem statement, mathematical model, Domain

requirements and identify Functional, Nonfunctional, Actors, Use cases for the

application/system. Create usecase diagram, activity diagram/swim lane diagram for

each usecase.

C. Design the architecture for the system/application using package diagram , deployment

diagram. Design classes using class diagram.

D. Design the behavior of the system/application using state machine diagram and sequence

diagram.

Objectives:

1. To understand the mathematical model for Application.

2. To understand the UML Diagrams with respect to architecture and behavior.

Theory:

What is mathematical Modelling?

A mathematical model is a description of a system using mathematical concepts and language.

The process of developing a mathematical model is termed mathematical modeling.

Mathematical models are used not only in the natural sciences (such as physics, biology, earth

science, meteorology) and engineering disciplines (e.g. computer science, artificial intelligence),

but also in the social sciences (Such as economics, psychology, sociology and political

science); physicists, engineers, statisticians, operations research analysts and economists use

mathematical models most extensively. A model may help to explain a system and to study the

effects of different components, and to make predictions about behavior. Mathematical models

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

can take many forms, including but not limited to dynamical systems, statistical

models, differential equations, or game theoretic models. These and other types of models can

overlap, with a given model involving a variety of abstract structures. In general, mathematical

models may include logical models, as far as logic is taken as a part of mathematics. In many

cases, the quality of a scientific field depends on how well the mathematical models developed

on the theoretical side agree with results of repeatable experiments. Lack of agreement between

theoretical mathematical models and experimental measurements often leads to important

advances as better theories are developed. Mathematical models can take many forms, including

but not limited to dynamical systems, statistical models, differential equations, or game theoretic

models. These and other types of models can overlap, with a given model involving a variety of

abstract structures. There are six basic groups of variables: decision variables, input variables,

state variables, exogenous variables, random variables, and output variables. Since there can be

many variables of each type, the variables are generally represented by vectors. Mathematical

modeling problems are often classified into black box or white box models, according to how

much a priori information is available of the system. A black-box model is a system of which

there is no a priori information available. A white-box model (also called glass box or clear box)

is a system where all necessary information is available. Practically all systems are somewhere

between the black-box and white-box models, so this concept only works as an intuitive guide

for approach. Usually it is preferable to use as much a priori information as possible to make the

model more accurate.

Set Theory:-

Set theory begins with a fundamental binary relation between an object o and a set A. If o is

a member (or element) of A, write o belongs to A. Since sets are objects, the membership

relation can relate sets as well.

A derived binary relation between two sets is the subset relation, also called set inclusion. If all

the members of set A are also members of set B, then A is a subset of B. For example, {1,2} is a

subset of {1,2,3} , but {1,4} is not. From this definition, it is clear that a set is a subset of itself;

for cases where one wishes to rule this out, the term proper subset is defined. A is called

a proper subset of B if and only if A is a subset of B, but B is not a subset of A.

Just as arithmetic features binary operations on numbers, set theory features binary operations

on sets. The:

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Union of the sets A and B, denoted A ∪ B, is the set of all objects that are a member

of A, or B, or both. The union of {1, 2, 3} and {2, 3, 4} is the set {1, 2, 3, 4} .

Intersection of the sets A and B, denoted A ∩ B, is the set of all objects that are members

of both A and B. The intersection of {1, 2, 3} and {2, 3, 4} is the set {2, 3} .

Set difference of U and A, denoted U \ A, is the set of all members of U that are not

members of A. The set difference {1,2,3} \ {2,3,4} is {1} , while, conversely, the set

difference {2,3,4} \ {1,2,3} is {4} . When A is a subset of U, the set difference U \ A is also

called the complement of A in U. In this case, if the choice of U is clear from the context,

the notation Ac is sometimes used instead of U \ A, particularly if U is a universal set as in

the study of Venn diagrams.

Symmetric difference of sets A and B, denoted A △ B or A ⊖ B, is the set of all objects

that are a member of exactly one of A and B (elements which are in one of the sets, but not

in both). For instance, for the sets {1,2,3} and {2,3,4} , the symmetric difference set

is {1,4} . It is the set difference of the union and the intersection,(A ∪ B) \

(A ∩ B) or (A \ B) ∪ (B \ A).

Cartesian product of A and B, denoted A × B, is the set whose members are all

possible ordered pairs (a,b) where a is a member of A and b is a member of B. The cartesian

product of {1, 2} and {red, white} is {(1, red), (1, white), (2, red), (2, white)}.

Power set of a set A is the set whose members are all possible subsets of A. For example,

the power set of {1, 2} is {{}, {1}, {2}, {1, 2}}.

Some basic sets of central importance are the empty set (the unique set containing no elements),

the set of natural numbers, and the set of real numbers.

Relations & Functions:-

Relation: A relation is simply a set of ordered pairs.

The first elements in the ordered pairs (the x-values), form the domain. The second elements

in the ordered pairs (the y-values), form the range. Only the elements "used" by the relation

constitute the range.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

This mapping shows a relation from set A into set

B.

This relation consists of the ordered pairs

(1,2), (3,2), (5,7), and (9,8).

• The domain is the set {1, 3, 5, 9}.

• The range is the set {2, 7, 8}.

(Notice that 3, 5 and 6 are not part of

the range.)

• The range is the dependent variable.

The following are examples of relations. Notice that a vertical line may intersect a relation in

more than one location.

This set of 5 points is a

relation.

{(1,2), (2, 4), (3, 5), (2, 6), (1,

-3)}

Notice that vertical lines may

intersect

more than one point at a time.

This parabola is also a relation.

Notice that a vertical line can

intersect this graph twice.

If we impose the following rule on a relation, it becomes a function.

Function: A function is a set of ordered a pair in which eachx-element has only ONE y-

element associated with it.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

The relations shown above are NOT functions because certain

x-elements are paired with more than one unique y-element.

The first relation shown above can be altered to become a

function by removing the ordered pairs where the x-

coordinate is repeated. It will not matter which "repeat" is

removed.

function: {(1,2), (2,4), (3,5)}

The graph at the right shows that a vertical line now intersects

only ONE point in our new function.

Vertical line test: each vertical line drawn through the graph will

intersect a function in only one location.

UML Diagrams:-

There are two broad categories of diagrams and then are again divided into sub-categories:

Structural Diagrams

Behavioral Diagrams

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Structural Diagrams:

The structural diagrams represent the static aspect of the system. These static aspects represent

those parts of a diagram which forms the main structure and therefore stable.

These static parts are represents by classes, interfaces, objects, components and nodes. The four

structural diagrams are:

Class diagram

Object diagram

Component diagram

Deployment diagram

Class Diagram:

Class diagrams are the most common diagrams used in UML. Class diagram consists of classes,

interfaces, associations and collaboration.

Class diagrams basically represent the object oriented view of a system which is static in nature.

Active class is used in a class diagram to represent the concurrency of the system.

Class diagram represents the object orientation of a system. So it is generally used for

development purpose. This is the most widely used diagram at the time of system construction.

Object Diagram:

Object diagrams can be described as an instance of class diagram. So these diagrams are more

close to real life scenarios where we implement a system.

Object diagrams are a set of objects and their relationships just like class diagrams and also

represent the static view of the system.

The usage of object diagrams is similar to class diagrams but they are used to build prototype of

a system from practical perspective.

Component Diagram:

Component diagrams represent a set of components and their relationships. These components

consist of classes, interfaces or collaborations.

So Component diagrams represent the implementation view of a system.

During design phase software artifacts (classes, interfaces etc) of a system are arranged in

different groups depending upon their relationship. Now these groups are known as components.

Finally, component diagrams are used to visualize the implementation.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Deployment Diagram:

Deployment diagrams are a set of nodes and their relationships. These nodes are physical

entities where the components are deployed.

Deployment diagrams are used for visualizing deployment view of a system. This is generally

used by the deployment team.

Behavioral Diagrams:

Any system can have two aspects, static and dynamic. So a model is considered as complete

when both the aspects are covered fully.

Behavioral diagrams basically capture the dynamic aspect of a system. Dynamic aspect can be

further described as the changing/moving parts of a system.

UML has the following five types of behavioral diagrams:

Use case diagram

Sequence diagram

Collaboration diagram

Statechart diagram

Activity diagram

Use case Diagram:

Use case diagrams are a set of use cases, actors and their relationships. They represent the use

case view of a system.

A use case represents a particular functionality of a system.

So use case diagram is used to describe the relationships among the functionalities and their

internal/external controllers. These controllers are known as actors.

Sequence Diagram:

A sequence diagram is an interaction diagram. From the name it is clear that the diagram deals

with some sequences, which are the sequence of messages flowing from one object to another.

Interaction among the components of a system is very important from implementation and

execution perspective.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

So Sequence diagram is used to visualize the sequence of calls in a system to perform a specific

functionality.

Collaboration Diagram:

Collaboration diagram is another form of interaction diagram. It represents the structural

organization of a system and the messages sent/received. Structural organization consists of

objects and links.

The purpose of collaboration diagram is similar to sequence diagram. But the specific purpose

of collaboration diagram is to visualize the organization of objects and their interaction.

Statechart Diagram:

Any real time system is expected to be reacted by some kind of internal/external events. These

events are responsible for state change of the system.

Statechart diagram is used to represent the event driven state change of a system. It basically

describes the state change of a class, interface etc.

State chart diagram is used to visualize the reaction of a system by internal/external factors.

Activity Diagram:

Activity diagram describes the flow of control in a system. So it consists of activities and links.

The flow can be sequential, concurrent or branched.

Activities are nothing but the functions of a system. Numbers of activity diagrams are prepared

to capture the entire flow in a system.

Activity diagrams are used to visualize the flow of controls in a system. This is prepared to have

an idea of how the system will work when executed.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Example Diagrams:-

Class Diagram:

UML Class Diagram with Relationships

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Component Diagram

Simple Component Diagram with Interfaces

Deployment Diagram

UML Deployment Diagram

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Object Diagram

UML Object Diagram Example

Package Diagram

Package Diagram in UML

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Composite Structure Diagram

A simple Composite Structure Diagram

Use Case Diagram

Most known diagram type of the behavioral UML diagrams, Use case diagrams gives a

graphic overview of the actors involved in a system, different functions needed by those actors

and how these different functions are interacted.

Use Case diagram showing Actors and main processes

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Activity Diagram

Activity Diagrams with start, end, processes and decision points

State Machine Diagram

State Machine diagram in UML, sometime referred to as State or State chart diagram

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Sequence Diagram

Sequence Diagrams in UML shows the interaction between two processes

Conclusion:-

From above discussion we can construct the mathematical model by using the concept

of set theory, relation & functions and also can depict the system using UML diagrams

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Assignment No: A-5

Aim:

Create Project plan, SRS, Design document and Test Plan for one group-C assignment from

embedded operating system or Concurrent and Distributed Programming.

Objective:

1. To understand the Software Requirement Specification.

2. To construct the test plan for any given application.

Theory:

Project Planning:-

Step 1: Project Goals

A project is successful when the needs of the stakeholders have been met. A stakeholder is

anybody directly or indirectly impacted by the project.

As a first step, it is important to identify the stakeholders in your project. It is not always easy to

identify the stakeholders of a project, particularly those impacted indirectly. Examples of

stakeholders are:

The project sponsor.

The customer who receives the deliverables.

The users of the project outputs.

The project manager and project team.

Once you understand who the stakeholders are, the next step is to find out their needs. The best

way to do this is by conducting stakeholder interviews. Take time during the interviews to draw

out the true needs that create real benefits. Often stakeholders will talk about needs that aren't

relevant and don't deliver benefits. These can be recorded and set as a low priority.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

The next step, once you have conducted all the interviews, and have a comprehensive list of

needs is to priorities them. From the prioritized list, create a set of goals that can be easily

measured. A technique for doing this is to review them against the SMART principle. This way

it will be easy to know when a goal has been achieved.

Once you have established a clear set of goals, they should be recorded in the project plan. It can

be useful to also include the needs and expectations of your stakeholders.

This is the most difficult part of the planning process completed. It's time to move on and look

at the project deliverables.

Step 2: Project Deliverables

Using the goals you have defined in step 1, create a list of things the project needs to deliver in

order to meet those goals. Specify when and how each item must be delivered.

Add the deliverables to the project plan with an estimated delivery date. More accurate delivery

dates will be established during the scheduling phase, which is next.

Step 3: Project Schedule

Create a list of tasks that need to be carried out for each deliverable identified in step 2. For each

task identify the following:

The amount of effort (hours or days) required to complete the task.

The resource that will carryout the task.

Once you have established the amount of effort for each task, you can workout the effort

required for each deliverable, and an accurate delivery date. Update your deliverables section

with the more accurate delivery dates.

At this point in the planning, you could choose to use a software package such as Microsoft

Project to create your project schedule. Alternatively, use one of the many free templates

available. Input all of the deliverables, tasks, durations and the resources who will complete

each task.

A common problem discovered at this point, is when a project has an imposed delivery deadline

from the sponsor that is not realistic based on your estimates. If you discover this is the case,

you must contact the sponsor immediately. The options you have in this situation are:

Renegotiate the deadline (project delay).

Employ additional resources (increased cost).

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Reduce the scope of the project (less delivered).

Use the project schedule to justify pursuing one of these options.

Step 4: Supporting Plans

This section deals with plans you should create as part of the planning process. These can be

included directly in the plan.

Human Resource Plan

Identify by name, the individuals and organisations with a leading role in the project. For each,

describe their roles and responsibilities on the project.

Next, describe the number and type of people needed to carryout the project. For each resource

detail start dates, estimated duration and the method you will use for obtaining them.

Create a single sheet containing this information.

Communications Plan

Create a document showing who needs to be kept informed about the project and how they will

receive the information. The most common mechanism is a weekly or monthly progress report,

describing how the project is performing, milestones achieved and work planned for the next

period.

Risk Management Plan

Risk management is an important part of project management. Although often overlooked, it is

important to identify as many risks to your project as possible, and be prepared if something bad

happens.

Here are some examples of common project risks:

Time and cost estimates too optimistic.

Customer review and feedback cycle too slow.

Unexpected budget cuts.

Unclear roles and responsibilities.

Stakeholder input is not sought, or their needs are not properly understood.

Stakeholders changing requirements after the project has started.

A stakeholder adding new requirements after the project has started.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Poor communication resulting in misunderstandings, quality problems and rework.

Lack of resource commitment.

Risks can be tracked using a simple risk log. Add each risk you have identified to your risk log;

write down what you will do in the event it occurs, and what you will do to prevent it from

occurring. Review your risk log on a regular basis, adding new risks as they occur during the life

of the project. Remember, when risks are ignored they don't go away.

Software Requirement Specification:-

A software requirements specification (SRS) is a description of a software system to be

developed, laying outfunctional and non-functional requirements, and may include a set of use

cases that describe interactions the users will have with the software.

Software requirements specification establishes the basis for agreement between customers and

contractors or suppliers (in market-driven projects, these roles may be played by the marketing

and development divisions) on what the software product is to do as well as what it is not

expected to do. Software requirements specification permits a rigorous assessment of

requirements before design can begin and reduces later redesign. It should also provide a

realistic basis for estimating product costs, risks, and schedules

The software requirements specification document enlists enough and necessary requirements

that are required for the project development To derive the requirements we need to have clear

and thorough understanding of the products to be developed or being developed. This is

achieved and refined with detailed and continuous communications with the project team and

customer till the completion of the software.

The SRS may be one of a contract deliverable Data Item Descriptions or have other forms of

organizationally-mandated content. An example organization of an SRS is as follows:

Introduction

Purpose

Definitions

System overview

References

Overall description

Product perspective

System Interfaces

User Interfaces

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Hardware interfaces

Software interfaces

Communication Interfaces

Memory Constraints

Operations

Site Adaptation Requirements

Product functions

User characteristics

Constraints, assumptions and dependencies

Specific requirements

External interface requirements

Functional requirements

Performance requirements

Design constraints

Standards Compliance

Logical database requirement

Software System attributes

Reliability

Availability

Security

Maintainability

Portability

Other requirements

Test Plan:-

1. Test Plan is a document that is the point of reference based on which testing is carried

out within the QA team.

2. It is also a document we share with the Business Analysts, Project Managers, Dev team

and the other teams. This is to enhance the level of transparency into the QA team’s

working to the external teams.

3. It is documented by the QA manager/QA lead based on the inputs from the QA team

members.

4. Test Planning is typically allocated 1/3rd

of the time it takes for the entire QA

engagement. The other 1/3rd

is for Test Designing and rest is for Test Execution.

5. Test plan is not static and is updated on an on demand basis.

6. The more detailed and comprehensive the Test plan, the more successful the testing

activity.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Conclusion:-

With the help of above document we can create the Project Plan and test plan for any

documents for designing we can use the Unified Modeling Language Diagrams.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Assignment No: A-6

Aim:

Write an application to parse input text file concurrently and compare the result of concurrent

parsing with serial parsing ( Use concurrent YACC parser)

Problem statement:

To parse input text file concurrently and compare the result of concurrent parsing with serial

parsing.

Theory:

Compilation steps: following diagram shows the compilation steps.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

The patterns in the above diagram is a file you create with a text editor. Lex will read

your patterns and generate C code for a lexical analyzer or scanner. The lexical analyzer

matches strings in the input, based on your patterns, and converts the strings to tokens. Tokens

are numerical representations of strings, and simplify processing. When the lexical analyzer

finds identifiers in the input stream it enters them in a symbol table. The symbol table may also

contain other information such as data type (integer or real) and location of each variable in

memory. All subsequent references to identifiers refer to the appropriate symbol table index.

The grammar in the above diagram is a text file you create with a text edtior. Yacc will read

your grammar and generate C code for a syntax analyzer or parser. The syntax analyzer uses

grammar rules that allow it to analyze tokens from the lexical analyzer and create a syntax tree.

The syntax tree imposes a hierarchical structure the tokens. For example, operator precedence

and associatively are apparent in the syntax tree. The next step, code generation, does a depth-

first walk of the syntax tree to generate code. Some compilers produce machine code, while

others, as shown above, output assembly language.

Lex Theory

During the first phase the compiler reads the input and converts strings in the source to

tokens. With regular expressions we can specify patterns to lex so it can generate code that will

allow it to scan and match strings in the input. Each pattern specified in the input to lex has an

associated action. Typically an action returns a token that represents the matched string for

subsequent use by the parser. Initially we will simply print the matched string rather than return

a token value. The following represents a simple pattern, composed of a regular expression,

that scans for identifiers. Lex will read this pattern and produce C code for a lexical analyzer

that scans for identifiers. letter(letter|digit)*

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Table 1. Pattern matching

Yacc Theory

Grammars for yacc are described using a variant of Backus Naur Form (BNF). This technique,

pioneered by John Backus and Peter Naur, was used to describe ALGOL60. A BNF grammar

can be used to express context-free languages. Most constructs in modern programming for an

expression that multiplies and adds numbers is E -> E + E E -> E * E E -> id

Three productions have been specified. Terms that appear on the left-hand side (lhs) of a

production, such as E (expression) are nonterminals. Terms such as id (identifier) are terminals

(tokens returned by lex) and only appear on the right-hand side (rhs) of a production. This

grammar specifies that an expression may be the sum of two expressions, the product of two

expressions, or an identifier. We can use this grammar to generate expressions: E -> E * E (r2) -> E * z (r3) -> E + E * z (r1) -> E + y * z (r3) -> x + y * z (r3)

At each step we expanded a term and replace the lhs of a production with the corresponding rhs.

The numbers on the right indicate which rule applied. To parse an expression we need to do the

reverse operation. Instead of starting with a single nonterminal (start symbol) and generating an

expression from a grammar we need to reduce an expression to a single nonterminal. This is

known as bottom-up or shift-reduce parsing and uses a stack for storing terms.

Procedure Run Program for serial parsing:

1. $lex abc.l 2. $yacc –d abc.y

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

3. $gcc y.tab.c lex.yy.c 4. $./a.out file1.txt

Figure 2. Building a Compiler with Lex/Yacc

Procedure Run Program for concurrent parsing:

1. $lex abc.l 2. $yacc –d abc.y 3. $gcc y.tab.c lex.yy.c –ll 4. $gcc openmp.c –fopenmp –o p 5. ./p file1.txt file2.txt file3.txt

Figure 1:Package diagram

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

figure 2:Activity diagram with fork

figure 4:Sequence diagram

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

figure 5:Deployment diagram

figure 6: Use Case diagram

Conclusion:

Thus, we have successfully learned how to parse input text file concurrently using

concurrent yacc parser.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Assignment No: B-1

Title of Assignment: PWM

Problem Definition:

Write an application to and demonstrate the change in BeagleBoard/ ARM Cortex A5

/Microprocessor /CPU frequency or square wave of programmable frequency.

Perquisite: Beaglebone Black, minicom

Learning Objective: To simulate the operations of LIFT on BBB.

Relevant Theory / Literature Survey:

Introduction

The element14 BeagleBone Black is identical in technical design and functionality as

the specified BeagleBoard.org product (BeagleBone Black) and runs on the version of the

software provided by BeagleBoard.org to element14. General support for this board is available

from the BeagleBoard.org community.

Pulse Width Modulation (or PWM) is a technique for controlling power. We also use

it here to control the brightness of each of the LEDs. The diagram below shows the signal from one of the GPIO pins on the BBB.

Every 1/5000 of a second, the PWM output will produce a pulse from 3.3V down to 0V.

The length of this pulse is controlled by the 'set_duty_cycle' function. If the output is high for 90% of the time then the load will get 90% of the power delivered to it.

We cannot see the LEDs turning on and off at that speed, so to us, it just looks like the

brightness is different.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

Configuring Pin 13 on P8 Header for PWM

The BBB was specifically designed to be a dynamic piece of hardware, enabling third-party

developers to create their own custom configurations and extensions known as capes. The board

is so flexible, it can change its hardware configuration at runtime using an in-kernel mechanism

known as the Cape Manager in conjunction with Device Tree Overlays.The Device Tree

consists of a set of human readable text files known as DTS files that end in the ―.dts‖

extension. DTS files can be edited using a simple text editor to set the configuration for a

particular pin. These source files then get compiled into DTB files, a binary format ending in the

―.dtbo‖ extension. This process creates what are known as device tree fragments or overlays.

The kernels Cape Manager can then dynamically load and unload the DTB files post-boot as

well as at runtime to set the hardware configuration.

1 root@beaglebone:/lib/firmware# ls *pwm* 2 am33xx_pwm-00A0.dtbo 3 am33xx_pwm-00A0.dts 4 bone_pwm_P8_13-00A0.dtbo 5 bone_pwm_P8_13-00A0.dts 6 ...

All we need to do is load them using the Cape Manager, but first, lets get acquainted with a very

useful command that will help us determine if our overlays were properly loaded:

1 root@beaglebone:~# more /sys/devices/bone_capemgr.8/slots 2 0: 54:PF--- 3 1: 55:PF--- 4 2: 56:PF--- 5 3: 57:PF--- 6 4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G 7 5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI

Out of the box, the BBB shows the above slots. Lets add two more slots to configure pin 13 on

header P8 for PWM by executing the following commands:

1 root@beaglebone:~# echo am33xx_pwm > /sys/devices/bone_capemgr.8/slots 2 root@beaglebone:~# echo bone_pwm_P8_13 > /sys/devices/bone_capemgr.8/slots

To confirm the overlays loaded properly we run the slots command again:

1 root@beaglebone:~# more /sys/devices/bone_capemgr.8/slots 2 0: 54:PF---

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASIK - 4

3 1: 55:PF--- 4 2: 56:PF--- 5 3: 57:PF--- 6 4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G 7 5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI 8 7: ff:P-O-L Override Board Name,00A0,Override Manuf,am33xx_pwm 9 8: ff:P-O-L Override Board Name,00A0,Override Manuf,bone_pwm_P8_13

Our board is now configured for PWM on pin13 of the P8 header! Before we move on,

however, it’s worth noting these changes are not permanent. If you power off the board, the

PWM slots we just added will disappear. Thankfully, we don’t have to repeat the above steps

each time we power up the board. The Cape Manager supports a method to load the overlays at

boot time by adding the following argument to the ―uEnv.txt‖ file:

1 capemgr.enable_partno=am33xx_pwm,bone_pwm_P8_13

Make sure to append the argument in a single line like this:

1 root@beaglebone:~# more /media/BEAGLEBONE/uEnv.txt 2 optargs=quiet drm.debug=7 capemgr.enable_partno=am33xx_pwm,bone_pwm_P8_13

Conclusion :

Thus, we have demonstrated the change in BeagleBoard/ ARM Cortex A5

/Microprocessor /CPU frequency

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, Nasik - 4

Assignment No: B-2

Aim: Implement a Parallel Quick Sort algorithm using NVIDIA GPU or equivalent ARM board.

Theory: Quicksort is a very efficient sorting algorithm invented by C.A.R. Hoare. It has two

phases:

the partition phase and the sort phase.

As we will see, most of the work is done in the partition phase - it works out where to divide the

work. The sort phase simply sorts the two smaller problems that are generated in the partition phase. This makes Quicksort a good example of the divide and conquer strategy for solving problems.

(You've already seen an example of this approach in thebinary search procedure.) In quicksort, we

divide the array of items to be sorted into two partitions and then call the quicksort procedure

recursively to sort the two partitions, ie we divide the problem into two smaller ones and conquer by

solving the smaller ones. The conquer part of the quicksort routine looks like this: quicksort( void *a, int low, int high )

{ int pivot; /* Termination condition! */ if ( high >

low ) { pivot = partition( a, low, high ); quicksort( a,

low, pivot-1 ); quicksort( a, pivot+1, high );

} }

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, Nasik - 4

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, Nasik - 4

Conclusion:-

In this assignment we are connecting the beaglebone black with the system and using bone

Micro embedded IDE we can develop the Quick Sort.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, Nasik - 4

Assignment No: B-3

Aim: Implement a Parallel ODD-Even Sort algorithm using GPU or ARM equivalent.

Objective:

To understand how to connect beagle bone black development board to Computer System. Understand the meaning of Odd Even Transposition sort Understand a method for carrying out odd even transposition sort in parallel.

Apply odd even transposition sort algorithm to sort a list of numbers

Theory:

Odd-Even Transposition Sort: Odd-Even Transposition Sort is a parallel sorting algorithm. It is based on the Bubble Sort technique

of comparing two numbers and switching them if the first is greater than the second, to achieve a left

to right ascending ordering. So what if each number were a PE, (Processing Element)? Each number

would look to it's right neighbor and if it were greater, it would switch them. If every PE is doing

this in parallel, there is going to be chaos because there will be multiple writes of different data to

the same memory location. Chaos without Synchronization

The solution is to break the problem into two phases per iteration. In phase one, a PE says, "am I odd

or even?" if it is odd, it is active and if it is even, it stands down this phase. The odd PEs look to their

right and switch if necessary. In phase two, the same happens but with the even PEs being active. By

doing this, there are no concurrent writes to the same memory location. Example:

Iteration Phase PE1 PE2 PE3 PE4 PE5 1 1 4 5 2 1 3

1 2 4 5 1 2 3

2 1 4 1 5 2 3

2 2 1 4 2 5 3

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, Nasik - 4

3 1 1 2 4 3 5

3 2 1 2 3 4 5

Analysis:

Odd-Even Transposition Sort only requires n/2 iterations of the dual phase sort, compared to n passes

through the array with Bubble Sort. This algorithm has excellent load balancing because every

processor is used once per iteration. Assuming our array of n elements to sort is very large, we will be

working with many virtual processors on the same processor to emulate one PE per element. To

optimize the code further, one may use a Quick Sort or similar sort on each physical processor to sort

the elements it is responsible for. Code examples are avaliable in our class Parallaxis manual,

Parallaxis-III: A Language for Structured Data-Parallel Programming, by Thomas Braunl. Example Let n=4 and a= < 5,2,1,4 > According to the algorithm i varies from 1 to 2. The processors are P 0, P 1, P 2 and P 3 . Let i=1 Since 0 is even, process P 0 will compare even vertices with its successor and exchange if

necessary. That is, a becomes < 2,5,1,4 > P 1 will compare odd vertices with its successor and

exchange if necessary. That is, a becomes < 2,1,5,4 > P 2 will make a as < 1,2,4,5 > and P 3 will

retain a. Next i becomes 2 but no change in a. Hence the final sequence is < 1,2,4,5 >

2.3 Algorithm for Odd Even Transposition Sort Procedure OddEvenTransposition(1D Mesh Processor Array)

begin for i= 1 to n/2 do

begin for all P k k varies from 0 to n-1 do

begin if j < n-1 and j % 2 not equal to 0 then

temp= successor(a)

successor(a)=maximum(a,t)

a=minimum(a,t) endif if j % 2 equal to 0 then

temp=successor(a)

successor(a)=maximum(a,t)

a=minimum(a,t)

endif end

end end

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, Nasik - 4

Conclusion:-

In this assignment we are connecting the Beaglebone Black with the system and using

bone Micro embedded IDE we can develop the parallel odd-even sort algorithm.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, Nasik - 4

Assignment No: B-4

Aim:

Implement concurrent n-ary search algorithm using OPENMP

Objective

1. To understand the OPENMP.

2. To construct Concurrent n-ary search algorithm.

Theory:- Openmp :-

OpenMP (Open Multi-Processing) is an API that supports multi-platform shared memory

multiprocessing programming in C, C++, and Fortran,[4] on most processor architectures and

operating systems, including Solaris, AIX, HP-UX, Linux, Mac OS X, and Windows platforms. It

consists of a set of compiler directives, library routines, and environment variables that influence run-

time behavior.

OpenMP is managed by the nonprofit technology consortium OpenMP Architecture Review Board (or

OpenMP ARB), jointly defined by a group of major computer hardware and software vendors,

including AMD, IBM, Intel, Cray, HP, Fujitsu, Nvidia, NEC, Red Hat, Texas Instruments, Oracle

Corporation, and more.

OpenMP uses a portable, scalable model that gives programmers a simple and flexible interface for

developing parallel applications for platforms ranging from the standard desktop computer to the

supercomputer.

An application built with the hybrid model of parallel programming can run on a computer cluster

using both OpenMP and Message Passing Interface (MPI), or more transparently through the use of

OpenMP extensions[citation needed] for non-shared memory systems.

OpenMP is an implementation of multithreading, a method of parallelizing whereby a master thread (a

series of instructions executed consecutively) forks a specified number of slave threads and the system

divides a task among them. The threads then run concurrently, with the runtime environment

allocating threads to different processors.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, Nasik - 4

The section of code that is meant to run in parallel is marked accordingly, with a preprocessor

directive that will cause the threads to form before the section is executed. Each thread has an id

attached to it which can be obtained using a function (called omp_get_thread_num()). The thread id is

an integer, and the master thread has an id of 0. After the execution of the parallelized code, the

threads join back into the master thread, which continues onward to the end of the program.n-ary

search algorithm:-

In graph theory, a k-ary tree is a rooted tree in which each node has no more than k children. It is also

sometimes known as a k-way tree, an N-ary tree, or an M-ary tree. A binary tree is the

For storing k-ary trees

Arrays

k-ary trees can also be stored in breadth-first order as an implicit data structure in arrays, and if the

tree is a complete k-ary tree, this method wastes no space. In this compact arrangement, if a node has

an index i, its c-th child is found at index , while its parent (if any) is found at index

(assuming the root has index zero). This method benefits from more compact storage and

better locality of reference, particularly during a preorder traversal

Conclusion:-

In this assignment we are developed concurrent n-ary serch algorithm using OPENMP

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, Nasik - 4

Assignment No: B-6

Aim: Implement a Multi-threading application for echo server using socket programming in JAVA.

Objective:

To study a Multi-threading application for echo server using socket programming in JAVA.

Theory :

Socket Programming :

Socket programming is useful for building client-server applications.

The server :

Creates a socket with some port number (>1023):

ServerSocketechoServer = new ServerSocket(6789);

Waits for client connection :

Socket clientSocket = echoServer.accept();

Gets input/output streams :

BufferedReader is = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));

PrintStreamos = new PrintStream(clientSocket.getOutputStream());

Exchanges information with the client :

String line = is.readLine();

os.println( "Echo: " + line );

Clean up :

is.close(); os.close();

clientSocket.close(); echoServer.close();

The client :

Creates a socket with the same port number :

Socket clientSocket = new Socket( "localhost", 6789 );

Gets input/output streams.

Exchanges information with the server.

Clean up.

ECHO Server

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, Nasik - 4

What is it and what is it for?

An "echo server" is a server that does nothing more than sending back whatever is sent to it.

Hence the name: echo What can you use it for? Whatever you feel like. Practical applications could be

network and connectivity testing and troubleshooting. Assume you've build a rather complex network

with VLANs and subnets, and really strick firewalls between those subnets, and you're beginning to

wonder if a client on one segment of the network will still be able to connect to your web server,

database server, ... on some other segment. A ping or a traceroute will establish if the server (IP

address) can be reached but does not tell you if an application will be able to connect to the desired on

the server and whether a reply from the server will be able to reach the client again.

This "echo server" can be set up to listen on any desired (tcp) port to simulate whatever

application you want to run (e.g. web server = port 80, Microsoft SQL Server = port 1433, etc.). From

the client machine, you can then telnet to this port. When a telnet connection has been established,

everything

you type will be echoed back to your screen, indicating that the telnet client and the echo server can

talk to each other : you've established connectivity at the application level.

In a similar way, you can use this echo server to troubleshoot networks, test a firewall (e.g. "if I ha

server listening on port 123, will my firewall allow connections to it?) and so on.

Echo server:

1. The client reads a line from its standard input and writes that line to the server.

2. The server reads a line from its network input and echoes the line back to the client over the

network.

3. The client reads the echoed line from the network and prints it on its standard output.

Multithreaded Server Advantages:

The advantages of a multithreaded server compared to a single threaded server are summed up below:

Less time is spent outside the accept() call.

Long running client requests do not block the whole server.

In a single threaded server long running requests may make the server unresponsive for a long period.

This is not true for a multithreaded server, unless the long-running request takes up all CPU time

and/or network bandwidth.

Conclusion:

Hence we have studied a Multi-threading application for echo server using socket

programming in JAVA.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, Nasik - 4

Assignment No: B-7

Aim :

Implement Reader-Writer problem using OPENMP.

Objective :

To study a Reader-Writer problem using OPENMP.

Theory :

OpenMP :

An Application Program Interface (API) that may be used to explicitly direct multithreaded,

shared memory parallelism

Comprised of three primary API components :

Compiler Directives

Runtime Library Routines

Environment Variables

An abbreviation for :

Short version: Open Multi-Processing

Long version: Open specifications for Multi-Processing via collaborative work between

interested parties from the hardware and software industry, government and

academia.

Goals of OpenMP :

Standardization :

Provide a standard among a variety of shared memory architectures/platforms

Jointly defined and endorsed by a group of major computer hardware and software vendors

Lean and Mean :

Establish a simple and limited set of directives for programming shared memory machines.

Significant parallelism can be implemented by using just 3 or 4 directives.

This goal is becoming less meaningful with each new release, apparently.

Ease of Use :

Provide capability to incrementally parallelize a serial program, unlike message-passing libraries

which typically require an all or nothing approach

Provide the capability to implement both coarse-grain and fine-grain parallelism

Portability :

The API is specified for C/C++ and Fortran

Public forum for API and membership

59

Most major platforms have been implemented including Unix/Linux platforms and Windows

Reader Writer Problem :

Consider the exercise 3 from the previous exercise sheet, i.e. the reader-writer problem.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, Nasik - 4

Implement the theoretical solutions that you have got for it in an OpenMP program read -write.c,

where the threads compete for one resource a buffer and have alternate access to this resource.

The writer threads try to fill the buffer with random numbers, while the reader threads read

numbers from the buffer and print them to the console. Beware that the writer threads can‟t fill

the buffer when it‟s full and that the reader threads can‟t read from the buffer when it‟s empty!

Run your program for different numbers of writers and readers

Readers-Writers Problem

• Multiple threads may access data

Readers will only observe, not modify data

Writers will change the data

• Goal: allow multiple readers or one single writer Thus, lock can be shared amongst concurrent

readers

• Can implement with other primitives Keep integer i # or readers or -1 if held by writer Protect i

with mutex Sleep on condition variable when can‟t get lock

Conclusion :

Hence we have implemented Reader-Writer problem using OPENMP

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, Nasik - 4

Assignment No: C - 1

Aim:

Develop Robotics (stepper motor) Application using Beagle Board.

Theory:

Stepper motors provide a means for precise positioning and speed control without the use of

feedback sensors. The basic operation of a stepper motor allows the shaft to move a precise number of

degrees each time a pulse of electricity is sent to the motor. Since the shaft of the motor moves only

the number of degrees that it was designed for when each pulse is delivered, you can control the pulses

that are sent and control the positioning and speed. The rotor of the motor produces torque from the

interaction between the magnetic field in the stator and rotor. The strength of the magnetic fields is

proportional to the amount of current sent to the stator and the number of turns in the windings.

A stepper motor is an electromechanical device which converts electrical pulses into discrete

mechanical movements. The shaft or spindle of a stepper motor rotates in discrete step increments

when electrical command pulses are applied to it in the proper sequence. The motors rotation has

several direct relationships to these applied input pulses. The sequence of the applied pulses is directly

related to the direction of motor shafts rotation. The speed of the motor shafts rotation is directly

related to the frequency of the input pulses and the length of rotation is directly related to the number

of input pulses applied.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, Nasik - 4

The above figure is the cross-section view of a single-stack variable-reluctance motor. The

stator

core is the outer structure and has six poles or teeth. The inner device is called the rotor and has four

poles. Both the stator and rotor are made of soft steel. The stator has three sets of windings as shown

in the figure.

Each set has two coils connected in series. A set of windings is called a ―phase‖. The motor

above, using this designation, is a three-phase motor. Current is supplied from the DC power source to

the windings via the switches I, II, and, III

Starting with state (1) in the upper left diagram, note that in state (1), the winding of Phase I is

supplied with current through switch I. This is called in technical terms, ―phase I is excited‖. Arrows

on the coil windings indicate the magnetic flux, which occurs in the air-gap due to the excitation.

T.E. Computer Engineering Programming Laboratory - III

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, Nasik - 4

Conclusion:

Thus, we have studied Robotics (stepper motor) Application using Beagle Board.