JAVA Multi-thread Programming on multiprocessors.

Slides:



Advertisements
Similar presentations
Shared-Memory Model and Threads Intel Software College Introduction to Parallel Programming – Part 2.
Advertisements

Threads Chapter 4 Threads are a subdivision of processes
PROCESS SCHEDULING AND SYNCRONIZATION
CPU Scheduling.
Chapter 5: CPU Scheduling
Zhongxing Telecom Pakistan (Pvt.) Ltd
1 Multithreaded Programming in Java. 2 Agenda Introduction Thread Applications Defining Threads Java Threads and States Examples.
Processes and Operating Systems
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 3 CPUs.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 5: Repetition and Loop Statements Problem Solving & Program.
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
1 Processes and Threads Creation and Termination States Usage Implementations.
Scheduling Algorithems
Schedulers Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue. Short-term scheduler (or CPU scheduler)
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc
Module 10: Virtual Memory
Chapter 10: Virtual Memory
CS 6143 COMPUTER ARCHITECTURE II SPRING 2014 ACM Principles and Practice of Parallel Programming, PPoPP, 2006 Panel Presentations Parallel Processing is.
IP Multicast Information management 2 Groep T Leuven – Information department 2/14 Agenda •Why IP Multicast ? •Multicast fundamentals •Intradomain.
Name Convolutional codes Tomashevich Victor. Name- 2 - Introduction Convolutional codes map information to code bits sequentially by convolving a sequence.
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
OPERATING SYSTEM SUPPORT
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process An operating system executes a variety of programs: Batch system.
Chapter 3: Processes.
1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Processes Management.
KAIST Computer Architecture Lab. The Effect of Multi-core on HPC Applications in Virtualized Systems Jaeung Han¹, Jeongseob Ahn¹, Changdae Kim¹, Youngjin.
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
Chapter 10: The Traditional Approach to Design
Systems Analysis and Design in a Changing World, Fifth Edition
Chapter 9 Interactive Multimedia Authoring with Flash Introduction to Programming 1.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Chapter 15 Multithreading, Networks, and Client/Server Programming
PSSA Preparation.
Essential Cell Biology
Chapter 6: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Chapter 6: CPU Scheduling Basic.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
50.003: Elements of Software Construction Week 5 Basics of Threads.
Operating System Concepts Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
Threads. Overview Problem Multiple tasks for computer Draw & display images on screen Check keyboard & mouse input Send & receive data on network Read.
Multi-Threaded Application CSNB534 Asma Shakil. Overview Software applications employ a strategy called multi- threaded programming to split tasks into.
Multithreading in Java Project of COCS 513 By Wei Li December, 2000.
Dr. R R DOCSIT, Dr BAMU. Basic Java : Multi Threading 2 Objectives of This Session State what is Multithreading. Describe the life cycle of Thread.
111 © 2002, Cisco Systems, Inc. All rights reserved.
Java Threads. What is a Thread? A thread can be loosely defined as a separate stream of execution that takes place simultaneously with and independently.
Silberschatz and Galvin  Operating System Concepts Module 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor.
Source: Operating System Concepts by Silberschatz, Galvin and Gagne.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
Chapter 5: Process Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Basic Concepts Maximum CPU utilization can be obtained.
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
Silberschatz and Galvin  Operating System Concepts Module 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor.
Thread A thread represents an independent module of an application that can be concurrently execution With other modules of the application. MULTITHREADING.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
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.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Java Thread Programming
Multi Threading.
Multithreaded Programming in Java
Chapter 4: Threads 羅習五.
Definitions Concurrent program – Program that executes multiple instructions at the same time. Process – An executing program (the running JVM for Java.
Presentation transcript:

JAVA Multi-thread Programming on multiprocessors. Pree Thiengburanathum Nopparat Suwannarat

Agenda Background Motivation Contribution Working environment Program design and Implementations Measurements Workloads Benchmark Analysis Conclusion Question

Background – quick overview Multi-programming Multi-processing Multi-threading Thread Homogenous CMP system

Background JAVA API Thread start() run() wait() join() sleep() getName() isAlive() Thread.isSleep()

JAVA Thread API Wait : public final void wait(long timeout, int nanos) Causes the current thread to wait until another thread invokes the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed Start : public void start() Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.

JAVA Thread API Run : public void run() If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns. Subclasses of Thread should override this method Stop : public final void stop() An application should not normally try to catch ThreadDeath unless it must do some extraordinary cleanup operation . If a catch clause catches a ThreadDeath object, it is important to rethrow the object so that the thread actually dies.

JAVA Thread API Sleep : public static void sleep(long millis) Causes the currently executing thread to sleep for the specified number of milliseconds, subject to the precision and accuracy of system timers and schedulers. The thread does not lose ownership of any monitors. Join : public final void join() Waits for this thread to die.

Motivation Multithreading with JAVA on large problems. For large computation problems, we would like to know how much performance will be improved if we use thread-based programming instead of execute by one process. How multi processors affects when programming with JAVA thread. Advantages and disadvantages of multithread programming with real applications. Gain experiences with JAVA Thread, multi-thread programming, CMP system, and various tools.

Contributions Software : A JAVA program benchmark. Why JAVA? Portability, can easily test on different operating systems. Synchronization Three Workloads (input) modules. Want to see the performance when having multiple processors compute the workloads in multiprogramming environment.

Working Environments Operating Systems Tools and language Microsoft Window Vista Ubuntu, Linux-based operating system. VMWare virtual machine. Tools and language Eclipse IDE with JAVA JRE 1.6.03, JRE 1.5.0_13 Project hosting at (Google code) Subversion repository URL: http://code.google.com/p/thread-programming-multiprocessors/

Working Environments Google code project.

Benchmark Three input(workloads), large problems which can be divided into small sub problems. Trapezoid’s rule Sorting array Fibonacci number

Workloads Trapezoid's Rule To compute the area under the function or Integrate the function by compute the summation of the small rectangular.

Workloads Trapezoid's Rule (cont.) Trapezoid's Rule – An example of the complicate function, a = 0, b = 10

Workloads Trapezoid's Rule(cont.) Trapezoid's Rule – two threads and how they are assigned.

Workloads Sorting Arrays Sorting Random Integer Arrays. Array before sort 8949 -3467 101 -2367 4050 2766 2 Assign a chuck of array to each thread. 8949 -3467 101 -2367 4050 2766 2 Thread 1 Thread 2 Thread 3

Workloads Sorting Arrays (cont.) Sorting Random Integer Arrays. The Array after sort -3467 -2367 2 101 2766 4050 8949

Workloads Fibonacci number the Fibonacci numbers are a sequence of numbers named after Leonardo of Pisa, known as Fibonacci. The first number of the sequence is 0 the second number is 1 each subsequent number is equal to the sum of the previous two numbers of the sequence itself

Fibonacci number (cont.) The family trees of cows and bees, the Fibonacci series, the Fibonacci Spiral and sea shell shapes, branching plants, flower petal and seeds, leaves and petal arrangements, on pineapples and in apples, pine cones and leaf arrangements. All involve the Fibonacci

Fibonacci number (cont.)

Fibonacci number (cont.)

Program Design – UML

Program Implementation Examples of program input rapry@Morphine:~/csc5573/ThreadSim/ java ThreadSim 1 Run workloads with 1 thread(s). Start trapaziod workload... Thread-1 is running trapazoid workload. Start sorting workload... execution time is: 3879000 nanoseconds. Running fibo workload... Done finding fibonacci number. execution time is: 12,192,912,000 nanoseconds. Finished all the workloads. Total execution time is: 12.19874 seconds.

Measurements Number of thread and performance of large problems. Performance in multiple processors environment. Performance in various operating systems Window/Linux and so on. Measurements on: Intel Core 2 Duo, 3.0Ghz, 2G RAM, Vista, Ubuntu Intel Centrino Duo, 1.44Ghz, 2G RAM, Vista Run 3 times and find the average of the total execution time.

Benchmark – 1 Vista JAVA Thread(s) run for each workload Time in seconds

Benchmark – 2 Vista Time in seconds

Benchmark – 1 Ubuntu JAVA Thread(s) run for each workload Time in seconds

Benchmark – 2 Ubuntu Time in seconds

Results Analysis Benchmark 1 (divide large problem into sub problems) If we assign right number of thread to compute the problems, better execution time. The more thread assign to the problem, the worse performance we get. Benchmark 2 (a pack of workloads) The more thread we assign to compute those problems, the worse execution time we will have.

Results Analysis For a better results we will need CPU Intensive application Need very large problem to compute in order to see an improvement. I/O Intensive application See significantly improvement of execution time. Example.

Conclusion JAVA Threads Advantages Better interaction with user. Exploitation of multiple processors. Do other things while waiting for Slow I/O operations. Simplify object modeling Synchronized, lock objects and classes Inter-thread communication support wait(), notify()

Conclusion(cont.) JAVA Threads Disadvantages Memory resources Two stacks assigned by JavaVM One is used to keep track of java method calls and vars. The other stack is used to keep track of native code calls Processor resources Overhead, context switch Thread operations (start, stop, destroy). When adding additional threads to the design of a system, these costs should be considered.

Conclusion(cont.) JAVA Multi-thread programming Less effective in single processor? Need to assign right number of thread, more thread doesn’t mean good. No synchronization need. No critical section in the program. Effective when the problem require intensive I/O operation. Programmer has to know the problem well in order to use thread-based programming to archive the maximum. utilization of system resources. Easy to start, tough to master. Auto-garbage collection Tasks such as getting lock, releasing lock are simplified.

References [1] JAVA Standard Edition 6 API, Sun Microsystems, http://java.sun.com/javase/6/docs/api/, 2006 [2] Eclipse IDE, www.eclipse.org, 2008 [3] Paul, H., Java Thread Programming, 1999 [4] Scott O., Henry W., Java Threads 2nd edition, 2001 [4] Operating System Concepts, by Silberschatz. Galvin, and Gangne, 7th Edition , Wiley 2005. Fibonacci, http://britton.disted.camosun.bc.ca/fibslide/jbfibslide.htmhttp://en.wikipedia.org/wiki/Fibonacci_number

Question