Parallel programming in Java. Java has 2 forms of support for parallel programming: –Multithreading Multiple threads of control (sub processes), useful.

Slides:



Advertisements
Similar presentations
Multiple Processor Systems
Advertisements

Threads, SMP, and Microkernels
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Deadlocks, Message Passing Brief refresh from last week Tore Larsen Oct
CS 5704 Fall 00 1 Monitors in Java Model and Examples.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Parallel programming in Java. Java has 2 forms of support for parallel programming: –Multithreading Multiple threads of control (sub processes), useful.
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
Lecture 4: Concurrency and Threads CS 170 T Yang, 2015 Chapter 4 of AD textbook.
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.
Concurrency CS 510: Programming Languages David Walker.
CS444/CS544 Operating Systems Synchronization 2/21/2007 Prof. Searleman
Threads CSCI 444/544 Operating Systems Fall 2008.
1/30/2004CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
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.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
Concurrency - 1 Tasking Concurrent Programming Declaration, creation, activation, termination Synchronization and communication Time and delays conditional.
CS603 Communication Mechanisms 14 January Types of Communication Shared Memory Message Passing Stream-oriented Communications Remote Procedure Call.
Multithreading.
50.003: Elements of Software Construction Week 5 Basics of Threads.
Lecture 4: Parallel Programming Models. Parallel Programming Models Parallel Programming Models: Data parallelism / Task parallelism Explicit parallelism.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Winter 2007SEG2101 Chapter 101 Chapter 10 Concurrency.
Cli/Serv.: rmiCORBA/131 Client/Server Distributed Systems v Objectives –introduce rmi and CORBA , Semester 1, RMI and CORBA.
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.
Threads Concurrency in Java. What is mult-tasking? Doing more than one task.
111 © 2002, Cisco Systems, Inc. All rights reserved.
Messaging is an important means of communication between two systems. There are 2 types of messaging. - Synchronous messaging. - Asynchronous messaging.
New features for CORBA 3.0 by Steve Vinoski Presented by Ajay Tandon.
Starting Object Design
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 Lecture 5 (part2) : “Interprocess communication” n reasons for process cooperation n types of message passing n direct and indirect message passing n.
Parallel Programming. Introduction Idea has been around since 1960’s –pseudo parallel systems on multiprogram-able computers True parallelism –Many processors.
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.
PREPARED BY : MAZHAR JAVED AWAN BSCS-III Process Communication & Threads 4 December 2015.
Introduction to Threads Session 01 Java Simplified / Session 14 / 2 of 28 Objectives Define a thread Define multithreading List benefits of multithreading.
Java Thread and Memory Model
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Department of Computer Science and Software Engineering
Multi-Threading in Java
CMSC 330: Organization of Programming Languages Threads.
Threads-Process Interaction. CONTENTS  Threads  Process interaction.
Threads A thread is an alternative model of program execution
Comunication&Synchronization threads 1 Programación Concurrente Benemérita Universidad Autónoma de Puebla Facultad de Ciencias de la Computación Comunicación.
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.
1 Threads in Java Jingdi Wang. 2 Introduction A thread is a single sequence of execution within a program Multithreading involves multiple threads of.
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.
Lecture 5. Example for periority The average waiting time : = 41/5= 8.2.
Client-Server Communication
03 – Remote invoaction Request-reply RPC RMI Coulouris 5
Java Concurrency.
Java Concurrency.
Chapter 4: Threads.
Condition Variables and Producer/Consumer
Condition Variables and Producer/Consumer
Background and Motivation
Parallel programming in Java
Presentation transcript:

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: –Lab course uses IPL (Ibis Portability Layer)

Multithreading 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 X

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 Notifywakes up (resumes) one blocked thread notifyAllwakes up all blocked threads

Example: circular bounded buffer public class BoundedBuffer { // shared variables: int buf[SIZE],count,Wpos, Rpos=0; public synchronized void put(int x) { //block if buffer full: while (count == SIZE) wait(); buf[Wpos] = x; count++; Wpos = (Wpos + 1) mod SIZE; if (count == 1) notifyAll(); } public synchronized int get() { int x; // local variable //block if buffer empty: while (count==0) wait(); x = buf[Rpos]; count- -; Rpos = (Rpos+1) mod SIZE; if (count==SIZE-1) notifyAll(); return x; } Coun t=4 xx x x RW

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 UnicastRemoteObjectimplements 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 RMISatin RepMI GMI MPJ TCPUDP P2P GMPanda 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: