Parallel programming in Java

Slides:



Advertisements
Similar presentations
1 Multithreaded Programming in Java. 2 Agenda Introduction Thread Applications Defining Threads Java Threads and States Examples.
Advertisements

European Research Network on Foundations, Software Infrastructures and Applications for large scale distributed, GRID and Peer-to-Peer Technologies Experiences.
Multiple Processor Systems
Threads, SMP, and Microkernels
13/04/2015Client-server Programming1 Block 6: Threads 1 Jin Sa.
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
CS 5704 Fall 00 1 Monitors in Java Model and Examples.
Parallel programming in Java. Java has 2 forms of support for parallel programming: –Multithreading Multiple threads of control (sub processes), useful.
COS 461 Fall 1997 Concurrent Programming u Traditional programs do one thing at a time. u Concurrent programs do several things at once. u Why do this?
Chapter 4 Threads, SMP, and Microkernels Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design.
Computer Systems/Operating Systems - Class 8
Introduction in algorithms and applications Introduction in algorithms and applications Parallel machines and architectures Parallel machines and architectures.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
Principles of Object-Oriented Software Development The language Java.
Parallel programming in Java. Java has 2 forms of support for parallel programming: –Multithreading Multiple threads of control (sub processes), useful.
Asynchronous Message Passing EE 524/CS 561 Wanliang Ma 03/08/2000.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CS603 Communication Mechanisms 14 January Types of Communication Shared Memory Message Passing Stream-oriented Communications Remote Procedure Call.
Multithreading.
Lecture 4: Parallel Programming Models. Parallel Programming Models Parallel Programming Models: Data parallelism / Task parallelism Explicit parallelism.
Threads. Overview Problem Multiple tasks for computer Draw & display images on screen Check keyboard & mouse input Send & receive data on network Read.
Lecture 5 : JAVA Thread Programming Courtesy : MIT Prof. Amarasinghe and Dr. Rabbah’s course note.
Quick overview of threads in Java Babak Esfandiari (extracted from Qusay Mahmoud’s slides)
Multithreading in Java Project of COCS 513 By Wei Li December, 2000.
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
Threads Concurrency in Java. What is mult-tasking? Doing more than one task.
111 © 2002, Cisco Systems, Inc. All rights reserved.
New features for CORBA 3.0 by Steve Vinoski Presented by Ajay Tandon.
CS 346 – Chapter 4 Threads –How they differ from processes –Definition, purpose Threads of the same process share: code, data, open files –Types –Support.
1 Concurrency Architecture Types Tasks Synchronization –Semaphores –Monitors –Message Passing Concurrency in Ada Java Threads.
3.1 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8 th Edition Chapter 3: Processes.
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
Hwajung Lee.  Interprocess Communication (IPC) is at the heart of distributed computing.  Processes and Threads  Process is the execution of a program.
OPERATING SYSTEMS Frans Sanen.  Recap of threads in Java  Learn to think about synchronization problems in Java  Solve synchronization problems in.
Concurrency Control 1 Fall 2014 CS7020: Game Design and Development.
Multi-Threading in Java
CMSC 330: Organization of Programming Languages Threads.
CS533 Concepts of Operating Systems Jonathan Walpole.
Thread A thread represents an independent module of an application that can be concurrently execution With other modules of the application. MULTITHREADING.
CSC CSC 143 Threads. CSC Introducing Threads  A thread is a flow of control within a program  A piece of code that runs on its own. The.
Concurrency in Java MD. ANISUR RAHMAN. slide 2 Concurrency  Multiprogramming  Single processor runs several programs at the same time  Each program.
Computer Science Lecture 4, page 1 CS677: Distributed OS Last Class: RPCs RPCs make distributed computations look like local computations Issues: –Parameter.
Concurrent Programming in Java Based on Notes by J. Johns (based on Java in a Nutshell, Learning Java) Also Java Tutorial, Concurrent Programming in Java.
Distributed Web Systems Distributed Objects and Remote Method Invocation Lecturer Department University.
A Parallel Communication Infrastructure for STAPL
Last Class: Introduction
Client-Server Communication
OPERATING SYSTEM CONCEPT AND PRACTISE
Threads in Java Two ways to start a thread
03 – Remote invoaction Request-reply RPC RMI Coulouris 5
Chapter 4: Threads.
Threads, SMP, and Microkernels
Slides for Chapter 6: Operating System support
Multithreading.
Chapter 40 Remote Method Invocation
Multithreading.
Lecture 4- Threads, SMP, and Microkernels
Concurrency in Java Last Updated: Fall 2010 Paul Ammann SWE 619.
Distributed Algorithms
Fast Communication and User Level Parallelism
Programming with Shared Memory Java Threads and Synchronization
Programming with Shared Memory Java Threads and Synchronization
Background and Motivation
EECE.4810/EECE.5730 Operating Systems
Chapter 46 Remote Method Invocation
Chapter 4: Threads & Concurrency
Chapter 4: Threads.
Chapter 46 Remote Method Invocation
CS510 Operating System Foundations
Representation and Management of Data on the Internet
Presentation transcript:

Parallel programming in Java

Parallel programming in Java Java has 2 forms of support for parallel programming: Multithreading Multiple threads of control (sub processes), useful for * Pseudo-parallelism within a single machine * Real parallelism on shared-memory machine Remote Method Invocation (RMI) Allows invocation on an object located at another machine Useful for distributed-memory machines Many additional parallel programming libraries exist: MPJ Express (based on MPI) Lab course uses IPL (Ibis Portability Layer)

Multithreading A thread has Its own program counter X A thread has Its own program counter Its own local variables All threads on same Java Virtual Machine share global variables Threads can communicate through shared variables Threads can run concurrently (on multiprocessor or multicore) or are time-sliced

Creating threads in Java public class mythread extends Thread { public void hi() { System.out.println("hi"); } public void run() { System.out.println("hello"); mythread t1 = new mythread(); // allocates a thread mythread t2 = new mythread(); // allocates another thread t1.start(); // starts first thread and invokes t1.run() t2.start(); // starts second thread and invokes t2.run() t1.hi();

Thread synchronization Problem-1: Thread-1 does: X = X + 1; Thread-2 does: X = X + 2; Result should be +3, not +1 or +2. Need to prevent concurrent access to same data: mutual exclusion synchronization

Mutual exclusion in Java public class example { int value; public synchronized increment (int amount) { value = value + amount; } The synchronized keyword guarantees that only one call to increment is executed at a time

More thread synchronization Problem-2: Sometimes threads have to wait for each other Condition synchronization Supported in Java with wait/notify/notifyAll wait blocks (suspends) a thread Notify wakes up (resumes) one blocked thread notifyAll wakes up all blocked threads

Remote Method Invocation RMI is 2-way synchronous communication, like RPC RMI invokes a method on a (possibly) remote object Integrates cleanly into Java's object-oriented model

Example public interface Hello extends Remote { String sayHello(); } public class HelloImpl extends UnicastRemoteObject implements Hello { public String sayHello() { return "Hello World!";

Asynchronous communication with Java RMI Can you do asynchronous messages passing in Java? Yes: create a new thread to do the RMI for you and wait for the result Awkward to program, performance overhead

IPL (Ibis Portability Layer) Ibis: Java-centric communication system designed for grid computing Supports heterogeneous and dynamic (malleable) systems Discussed later in this class IPL: flexible message passing library for Java

Structure of the Ibis system IPL RMI Satin RepMI GMI MPJ TCP UDP P2P GM Panda Application Java Native Legend:

Functionality of IPL Based on setting up connections Programmer can create send-ports and receive-ports These can be connected in a flexible way: one-to-one, one- to-many (multicast), many-to-one Programmer can define properties of connections and ports: FIFO ordering, reliability, delivery mechanisms, streaming IPL supports explicit message receipt, implicit message receipt (upcalls), polling

More information Tutorials/documentation about multithreading and IPL are available through the web site of the lab course: http://www.cs.vu.nl/ppp