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
1 Multithreaded Programming in Java. 2 Agenda Introduction Thread Applications Defining Threads Java Threads and States Examples.
Advertisements

Multiple Processor Systems
Threads, SMP, and Microkernels
13/04/2015Client-server Programming1 Block 6: Threads 1 Jin Sa.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
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.
DISTRIBUTED AND HIGH-PERFORMANCE COMPUTING CHAPTER 7: SHARED MEMORY PARALLEL PROGRAMMING.
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.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
Scripting Languages For Virtual Worlds. Outline Necessary Features Classes, Prototypes, and Mixins Static vs. Dynamic Typing Concurrency Versioning Distribution.
Threads CSCI 444/544 Operating Systems Fall 2008.
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.
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 Parallel Computing Basics of Parallel Computers Shared Memory SMP / NUMA Architectures Message Passing Clusters.
1 Developing Native Device for MPJ Express Advisor: Dr. Aamir Shafi Co-advisor: Ms Samin Khaliq.
Lecture 4 : JAVA Thread Programming
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Chapter 4 Threads, SMP, and Microkernels Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design.
Cli/Serv.: rmiCORBA/131 Client/Server Distributed Systems v Objectives –introduce rmi and CORBA , Semester 1, RMI and CORBA.
Threading and Concurrency Issues ● Creating Threads ● In Java ● Subclassing Thread ● Implementing Runnable ● Synchronization ● Immutable ● Synchronized.
12/1/98 COP 4020 Programming Languages Parallel Programming in Ada and Java Gregory A. Riccardi Department of Computer Science Florida State University.
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.
 2004 Deitel & Associates, Inc. All rights reserved. 1 Chapter 4 – Thread Concepts Outline 4.1 Introduction 4.2Definition of Thread 4.3Motivation for.
New features for CORBA 3.0 by Steve Vinoski Presented by Ajay Tandon.
Starting Object Design
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
CS 346 – Chapter 4 Threads –How they differ from processes –Definition, purpose Threads of the same process share: code, data, open files –Types –Support.
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.
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership: process includes a virtual address space to hold the process image (fig 3.16)
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.
Introduction to Threads Session 01 Java Simplified / Session 14 / 2 of 28 Objectives Define a thread Define multithreading List benefits of multithreading.
Chapter 4 Message-Passing Programming. The Message-Passing Model.
Java Thread and Memory Model
Concurrency Control 1 Fall 2014 CS7020: Game Design and Development.
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.
Grid Programming Models: Author: Craig Lee and Domenico Talia Presenter: Tuan Cameron Author: Craig Lee and Domenico Talia Presenter: Tuan Cameron Current.
Threads A thread is an alternative model of program execution
Thread A thread represents an independent module of an application that can be concurrently execution With other modules of the application. MULTITHREADING.
Operating Systems Unit 2: – Process Context switch Interrupt Interprocess communication – Thread Thread models Operating Systems.
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.
Threads, SMP, and Microkernels Chapter 4. Processes and Threads Operating systems use processes for two purposes - Resource allocation and resource ownership.
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
Chapter 4: Threads.
Background and Motivation
Chapter 4: Threads.
Representation and Management of Data on the Internet
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: –MPJ Express (based on MPI) –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

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 in Cluster & Grid 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: