Introduction to OpenMP: 05 Module 3

Поделиться
HTML-код
  • Опубликовано: 12 дек 2024

Комментарии • 60

  • @elias19r
    @elias19r 10 лет назад +127

    8:35 Hahaha, sure I remember learning Calculus in kindergarten

    • @ankurg_
      @ankurg_ 6 лет назад

      lol noticed after reading your comment. I was so lost in understanding things. :p

    • @hbrg9173
      @hbrg9173 5 лет назад +2

      When higher secondary is so far back in your life, it's inseparable from kindergarten

    • @shiwamjaiswal9653
      @shiwamjaiswal9653 5 лет назад +1

      Good old days of kindergarten : -})

  • @AaronCohn84
    @AaronCohn84 11 лет назад +38

    At 7:14, the code shown calls a function "think" which I "think" is a typo.

  • @edwardh9488
    @edwardh9488 7 лет назад +9

    At 4:45 he says the A array sets on the heap. However, since this is a statically sized array declared in a function(presumably the main function), shouldn't the array instead be put on the stack instead of the heap?

    • @chucky2578
      @chucky2578 6 лет назад

      No. We have double A[1000] outside the structured block. So this will be shared by all the threads. If we had double A[1000] inside the structured block, then each thread would have it's own private copy of A[1000].

    • @esrefozdq
      @esrefozdq 6 лет назад +3

      I get where you are coming from, but if we write
      int main() {
      double A[1000];
      }
      A sits on the stack of the master thread (A is stack allocated array here). So when we write
      int main() {
      double A[1000];
      #pragma omp parallel
      {
      // do stuff with A
      }
      }
      how all the threads share A since A was created on the stack of the master thread before parallelization began? Maybe openmp itself copies all stack allocated variables of the master thread to heap itself without the programmer knowing?

    • @chucky2578
      @chucky2578 6 лет назад +1

      Think of it this way. Example: If anything is written globally, that is outside a method, then all the methods you have defined in your program will have access to that SAME variable(not a copy of it). If you define anything inside a method, then only that method has access to it.
      Similarly, if you define A[1000] outside the structured block, then all threads have access to the same A. But if you have A[1000] inside the structured block, then each thread gets a copy of A[1000]. So if some thread modifies A[1000], it will only be on it's copy of A[1000].

    • @J.Rahman
      @J.Rahman 3 года назад +6

      You are right. It does not matter whether an array is private or shared, you can allocate it either on stack or heap. For the specific example in question, the shared variable A is obviously allocated on the stack before reaching the parallel block. No doubt about that. As for whether OpenMP moves the shared variables on the stack to the heap, that is implementation dependent. In other words, the data sharing attributes of such variables are implicitly defined by the implementation. However, if you want to be sure, you can check the addresses of the shared variables and, most likely, you will find them on the stack.

    • @jonf6509
      @jonf6509 2 месяца назад

      @@J.Rahman i asked chatgpt, which was not available in the olden days when you commented
      my guess, after speaking with Senhor GPT, is thats why he says "To a first order approximation" the data is on the heap. Its not actually on the heap, but behaves as if it were, in that, its available to all threads

  • @pranaynayak
    @pranaynayak 4 года назад

    watching it twice helped me. didn't get it exactly the first time

  • @Apokalypzx
    @Apokalypzx 7 лет назад +4

    We put a #pragma omp parallel in your #pragma omp parallel so you can fork threads while you fork threads...

  • @arjunkshaji9738
    @arjunkshaji9738 Год назад +1

    Do all the threads need to join back at the same time or can some threads join the master thread at some point in the execution when they're done with their part and the remaining threads join later? Or does the fork and join only happen at the beginning and end of the structured block for which they're created?

  • @diaamostafa1005
    @diaamostafa1005 7 лет назад +2

    This video is very helpful. Thank you !

  • @vimalkargathara
    @vimalkargathara 8 лет назад +1

    Can i get something on how to parallelized nested while loops in C.

  • @aniketgarade1344
    @aniketgarade1344 10 месяцев назад

    Is A is sit on heap or stack? If A is sit on stack then how the threads in parallel region can access A?

  • @__hannibaal__
    @__hannibaal__ Год назад

    So there are another questions; what is relation with lib c++ thread.h ?

  • @stinkybadger2000
    @stinkybadger2000 4 года назад +3

    4:19

  • @uschan5227
    @uschan5227 4 года назад

    very good explained Thank you Mattson

  • @rishishahloyola
    @rishishahloyola 9 лет назад +4

    Here is the code github.com/rishiloyola/pi-openmp
    if someone wanted to copy paste it.

    • @whovillewho9764
      @whovillewho9764 8 лет назад +2

      There are a lot of syntax errors in this code (forgetting to add ; at the end of omp_set_num_threads and accessing sum as an aggregate when you defined it with a literal). Did you even compile it?

  • @charleshwankong
    @charleshwankong 2 года назад

    thunk seems to refer to thread function.

  • @damilareoyebanji2834
    @damilareoyebanji2834 4 года назад +2

    hahaha "far back to kindergarten when you learnt Calculus".
    Thank you for the tutorial Tim Mattson.

  • @naviddaneshvaran5411
    @naviddaneshvaran5411 7 лет назад

    Very helpful and great video. Thanks.

  • @伟建-j4u
    @伟建-j4u 5 лет назад +1

    what is pooh really means,i could run my process pooh(ID,A).can anybody explain?thanks

    • @pranaynayak
      @pranaynayak 4 года назад

      pooh() can be any function with intake ID and array A. For each parallel thread, pooh has a different value of ID in its argument list. pooh() can carry out an operation accordingly for each thread. You can put a switch-case or if-else like construct in pooh(ID,A) which allows different operations on the common array A, in each thread.
      I just learned it and may be wrong in my interpretation. So please cross check

  • @dulantha99
    @dulantha99 9 лет назад

    Just to make sure, when it requests 4 threads the team does not include the main thread correct? So in total there are 5 threads running 5 thunks?

    • @10051993able
      @10051993able 9 лет назад +1

      Dulantha Fernando No. The team gets 4 threads with main (also known as master) thread with ID = 0. Other IDs: 1, 2, 3.

  • @manikasharma9497
    @manikasharma9497 4 года назад

    Which kindergarten did you guys to!!!!

  • @oillyareeya4562
    @oillyareeya4562 4 года назад +1

    why i+0.5 before (i+0.5)*steps? x=(i+0.5)*step

    • @pranaynayak
      @pranaynayak 4 года назад

      to average the lower sum and upper sum approximations to the actuall integral

  • @mibo747
    @mibo747 2 года назад

    MAny thanks for usefull videos

  • @thelittleendian2643
    @thelittleendian2643 4 года назад +2

    Why multiply the sum by step after the for loop in the pi code?
    Doesn't sum store the sum of areas of all rectangles which itself is the value of the integral?

    • @123Handbuch
      @123Handbuch 3 года назад +1

      That's just the definition of the Rieman-Integral. What we do is: int_0^1 f(x) dx = sum_i^100000 f(x_i)*step_i = stepi_i*sum_i=0^100000 f(x_i) with f(x) being 1/(1+x^2).
      So since the step size is constant, we can just take it out of the sum. We we first sum up all f(x_i) evaulations and then multiply it with the step size. Check "Rieman Sum" in the wiki.

  • @anantmishra4939
    @anantmishra4939 9 лет назад +1

    Is it possible that 2 threads would try to read a shared variable at exact same time? or due to higher frequency of procs it is super rare???

    • @ilrefex91
      @ilrefex91 9 лет назад +1

      +Anant Mishra read and write are operations that a calculator sees as a 3 part scheme in order to fetch, decode and execute an instruction. So it CAN happen that a certain value is going to be affected by two different threads, let's say thread A wants to add 1 to value z and B wants to sub 1. If you are not using some sort of synchronizations the output will be one of the possible interleaved combinations.

  • @JiveDadson
    @JiveDadson 7 лет назад +2

    I would have had it on the first try, except I omitted the step*sum at the end. Dangit.

  • @samadmazarei3097
    @samadmazarei3097 5 лет назад +1

    Does anybody know of an IRC channel where I can chat a bit about openMP? Ask questions, lurk, all that good stuff?

    • @123Handbuch
      @123Handbuch 3 года назад

      #cprogramming #programming #c++-libraries maybe on freenode

  • @PikesCore24
    @PikesCore24 3 года назад

    You don't define the function "pooh". Am I supposed to know what it is?

    • @konstantinrebrov675
      @konstantinrebrov675 3 года назад +1

      It can be anything. You can put any code you want in it.

  • @arjunkshaji9738
    @arjunkshaji9738 Год назад

    Thank you for using pooh and not foo!

  • @amaanakhtar9574
    @amaanakhtar9574 2 месяца назад

    lol 8:30 , calculus in kindergarden.... yeh

  • @devilzwishbone
    @devilzwishbone 2 года назад

    He so looks like Benny Hill

  • @kylehess4472
    @kylehess4472 7 лет назад +1

    Umm... So not only do you have programming mistakes in your code (like not including stdio.h in previous exercises), but you also encourage bad form by using non-monospace font and bad coding style?

    • @JiveDadson
      @JiveDadson 7 лет назад +1

      So give the gift horse a breath mint.

    • @anuragsingh2276
      @anuragsingh2276 6 лет назад

      on gcc, the code works without 'stdio.h'. gives out a warning though. but works.