JavaPThreads - Shared memory programming with Java and...

Info icon This preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Shared memory programming with Java and Pthreads Thanks to LLNL for their tutorial from which these slides are derived http://www.llnl.gov/computing/tutorials/ workshops/workshop/pthreads/MAIN.html Friday, January 27, 12
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Many Java Virtual Machines use Pthreads to support their threading model We will first cover threads in general, and then Java threads, and then Pthreads For projects, you can use either Java, Pthreads (with C/C++ or Fortran) or OpenMP for shared memory programming Some homeworks require you to use either Java or Pthreads Java programming is not required 2 Friday, January 27, 12
Image of page 2
Multithreading in Java Friday, January 27, 12
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Multithreading a part of the language Language specification attempts to define what happens in programs with races not true with C/C++ & Pthreads these have “catch fire” semantics in the case of races Standard library calls for mutex synchronization, thread safe libraries, standard calls for thread creation, destruction, and so forth Friday, January 27, 12
Image of page 4
Java Basics .java files .java files .java files javac compiler ..class files .class files .class files java virtual machine jit compiler interpreter classloader mem. mgmt. scheduler OS/external services network input output Friday, January 27, 12
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Java Basics .java .java .java javac compiler ..class .class .class java virtual machine jit compiler interpreter classloader mem. mgmt. scheduler OS/external input output Supplies basic OS-like services to a program Scheduling Resource management Isolation Any program executed must be limited in the damage it can cause internally, this makes many things hard in particular, races have to have reasonable (i.e. not “catch fire” semantics. Friday, January 27, 12
Image of page 6
java virtual machine classes shared memory -- heap, stacks, etc. A simple view of the JVM .class files network input output main t0 t3 t2 t1 ... tn Friday, January 27, 12
Image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Java is an object oriented language Objects are a way to organize data and code that operates on that data You can think of an object as a collection of routines and a struct that holds the object's data Objects also support stuff like overloading, polymorphism, inheritance and data encapsulation That is the subject of another course and will be discussed then A class defines what data and code an object contains, and objects are instances of that class Friday, January 27, 12
Image of page 8
Reconsider OpenMP Critical What keeps the critical section in different threads from overlapping? A lock #pragma omp parallel for for (i=0; i < n; i++) { #pragma omp critical t += a[i]; } i=0 t=t+a[0] . . . . time = i=1 t=t+a[1] i=n-1 t=t+a[n-1] Friday, January 27, 12
Image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Locks A lock , sometimes called a mutex (for mutual exclusion) lock typically have the properties: at most one thread can hold the lock at a time when a thread tries to acquire a lock that is held, it joins a queue to wait to get the lock while in the wait queue the lock does no work when the lock is released by the thread that holds it,
Image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern