1 / 9

Παραλληλη / κατανεμημενη επεξεργασια και εφαρμογεσ

Παραλληλη / κατανεμημενη επεξεργασια και εφαρμογεσ. Εισαγωγή στο O penMP. Περιεχομενα. Εισαγωγή Σύνταξη στη C/C++ Hello World Σύνταξη στη C/C++ Κανόνας του τραπεζίου Υπολογισμός π Αναφορές. Εισαγωγη. Shared memory συστήματα Pthreads OpenMP Java threads

durin
Download Presentation

Παραλληλη / κατανεμημενη επεξεργασια και εφαρμογεσ

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Παραλληλη/κατανεμημενηεπεξεργασια και εφαρμογεσ Εισαγωγή στο OpenMP

  2. Περιεχομενα • Εισαγωγή • Σύνταξη στη C/C++ • Hello World • Σύνταξη στη C/C++ • Κανόνας του τραπεζίου • Υπολογισμός π • Αναφορές

  3. Εισαγωγη • Shared memory συστήματα • Pthreads • OpenMP • Java threads • Το OpenMPείναι προγραμματισμός σε πιο “υψηλό” επίπεδο από το Pthreads • Πρέπει να το υποστηρίζει ο compiler • gcc: -fopenmp

  4. Εισαγωγη • OpenMP • SPMD (Υπάρχει η δυνατότητα και για MPMD) • Βασίζεται στα νήματα • Μνήμη • Κοινή μεταξύ των threads • Τοπική για κάθε thread (τα άλλα δεν έχουν πρόσβαση)

  5. Συνταξη στη c/c++ • #include <omp.h> • #pragmaomp directive [ clauses [ ] ] • directive: parallel, parallel for • clause: num_threads(number of threads) • #pragmaompparallel\ num_threads(thread_count) • intomp_get_thread_num (): thread id • intomp_get_num_threads ():αριθμός threads

  6. Hello World #include <stdio.h> #include <stdlib.h> #include <omp.h> void Hello(void); intmain(intargc, char* argv[]){ intthread_count = strtol(argv[1], NULL, 10); # pragmaomp parallel num_threads(thread_count) Hello(); return 0; } void Hello(void){ intmy_rank = omp_get_thread_num(); intthread_count = omp_get_num_threads(); printf("Hello from thread %d of %d\n", my_rank, thread_count); }

  7. Συνταξηστη C/C++ • implicit barrier • parallel • for • single • _OPENMP: δείχνει αν υποστηρίζει ο compiler OpenMP • Προσοχή στα«κρίσιμα τμήματα» • #pragmaomp critical • Μεταβλητές • private: clause • shared: clause • Reduction clause • reduction (+,-,*: μεταβλητή)

  8. Συνταξη στη C/C++ • parallel for directive • Πρέπει να ξέρουμε από πριν τον αριθμό των επαναλήψεων • No data dependence • Όχι ifμε return

  9. Αναφορεσ • Peter S. Pacheco, An Introduction to Parallel Programming, Morgan Kaufmann, 2011 • Thomas Rauber, GudulaRunger, Parallel Programming for Multicore and Cluster Systems, Springer, 2010

More Related