<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to debug OpenMP parallelized code with vfn 10.1? in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875151#M73587</link>
    <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;I am in process of learning how to use OpenMP in order to optimizesome research code, but I am really stuck in the debug process. DoI need to do something special in order to use watches on parallel code? I created a very simple example below to illustrate my problem. When I run this code with a watch on I, I is equal to 1 during every iteration of the loop... ?????&lt;/P&gt;
&lt;P&gt;!$omp parallel private(i) num_threads(1)&lt;BR /&gt;!$omp do &lt;BR /&gt; DO I=1,100 &lt;BR /&gt; X=X+I&lt;BR /&gt; ENDDO&lt;BR /&gt;!$omp end do&lt;BR /&gt;!$omp end parallel&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Any help will be greatly appreciated!!!!&lt;/P&gt;</description>
    <pubDate>Mon, 05 Jan 2009 13:06:38 GMT</pubDate>
    <dc:creator>PKM</dc:creator>
    <dc:date>2009-01-05T13:06:38Z</dc:date>
    <item>
      <title>How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875151#M73587</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;I am in process of learning how to use OpenMP in order to optimizesome research code, but I am really stuck in the debug process. DoI need to do something special in order to use watches on parallel code? I created a very simple example below to illustrate my problem. When I run this code with a watch on I, I is equal to 1 during every iteration of the loop... ?????&lt;/P&gt;
&lt;P&gt;!$omp parallel private(i) num_threads(1)&lt;BR /&gt;!$omp do &lt;BR /&gt; DO I=1,100 &lt;BR /&gt; X=X+I&lt;BR /&gt; ENDDO&lt;BR /&gt;!$omp end do&lt;BR /&gt;!$omp end parallel&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Any help will be greatly appreciated!!!!&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jan 2009 13:06:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875151#M73587</guid>
      <dc:creator>PKM</dc:creator>
      <dc:date>2009-01-05T13:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875152#M73588</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="margin-top: 5px; width: 100%;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/409519"&gt;Casper Kirkegaard&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt;
&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;I am in process of learning how to use OpenMP in order to optimizesome research code, but I am really stuck in the debug process. DoI need to do something special in order to use watches on parallel code? I created a very simple example below to illustrate my problem. When I run this code with a watch on I, I is equal to 1 during every iteration of the loop... ?????&lt;/P&gt;
&lt;P&gt;!$omp parallel private(i) num_threads(1)&lt;BR /&gt;!$omp do &lt;BR /&gt; DO I=1,100 &lt;BR /&gt; X=X+I&lt;BR /&gt; ENDDO&lt;BR /&gt;!$omp end do&lt;BR /&gt;!$omp end parallel&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Any help will be greatly appreciated!!!!&lt;/P&gt;
&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;BR /&gt;Set the watch on I &lt;EM&gt;after&lt;/EM&gt; you enter the parallel region. i.e. place the break point on X=X+I, then at break set the watch.&lt;/P&gt;
&lt;P&gt;Note, the I as specified will be valid only for the thread context when the watch was set.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jan 2009 14:08:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875152#M73588</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2009-01-05T14:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875153#M73589</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;BR /&gt;Thanks for your reply Jim!&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I just tried following your guidelines, but the issue remains the same. After placing the watch and hitting F5 to continue the I variable just remains 1 no matterhow many times I hitcontinue ... Any suggestions?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jan 2009 14:31:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875153#M73589</guid>
      <dc:creator>PKM</dc:creator>
      <dc:date>2009-01-05T14:31:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875154#M73590</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="margin-top: 5px; width: 100%;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/409519"&gt;Casper Kirkegaard&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt;
&lt;P&gt;&lt;BR /&gt;Thanks for your reply Jim!&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I just tried following your guidelines, but the issue remains the same. After placing the watch and hitting F5 to continue the I variable just remains 1 no matterhow many times I hitcontinue ... Any suggestions?&lt;/P&gt;
&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;BR /&gt;Are your optimizations settings set to disabled? When not at disabled I may be optimized away. Also, for the particular loop you were using a good optimizer could optimize the entire loop away (i.e. the compiler could compute the sum of the I, then insert code to add that precomputed sumonce to X).&lt;/P&gt;
&lt;P&gt;To see what is happening you can use the debugger dissassembly window, but you may not be up to rolling your sleaves up that far.&lt;/P&gt;
&lt;P&gt;Because this is a learningexperiment you can do the following:&lt;/P&gt;
&lt;P&gt;Place the code contained within the loop into a subroutine. In this case&lt;/P&gt;
&lt;P&gt;subroutine DOSUM(X, I)&lt;BR /&gt;real :: X&lt;BR /&gt;integer :: I&lt;BR /&gt;X = X + I&lt;BR /&gt;end subroutine DOSUM&lt;BR /&gt;&lt;BR /&gt;And then use a call tothis subroutine for the body of your loop.&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jan 2009 15:42:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875154#M73590</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2009-01-05T15:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875155#M73591</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="width: 100%; margin-top: 5px;"&gt;In the title, you mention parallelized code, but you don't show any. You set 1 thread, as you must do, when you don't specify how you will handle the x variable which would be shared among threads. So, I don't know what your question is. &lt;BR /&gt;&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 05 Jan 2009 16:43:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875155#M73591</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2009-01-05T16:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875156#M73592</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
&lt;P&gt;Tim,&lt;/P&gt;
&lt;P&gt;I would guess that the number of threads was set to 1 for purposes of debugging the parallel code using 1 thread. In this case such that the variable I would not hop about with context switches. The problem the poster is having is either the symbolic address of I is not resolved within the thread context .OR. I is optimized out of the code. The end result in either case is for the debugger to not be able to observe the value of I at break point during iteration.&lt;/P&gt;
&lt;P&gt;When optimizations are on for that loop it is likely that I will be registerized and the debugger will not see it varying during execution.&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jan 2009 18:41:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875156#M73592</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2009-01-05T18:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875157#M73593</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
&lt;BR /&gt;You are right Jim ... I'm also having this problem with more complicated code and I just wanted to keep my test case simple ...&lt;BR /&gt;&lt;BR /&gt;Anyway, I tried rewriting the code into its own subroutine as you suggested - unsuccesfull, however. I have also gone through all the compiler settings at least 10 times before posting here, so unless there are optimizations hidden in a setting that I don't of this should not be the cause.&lt;BR /&gt;&lt;BR /&gt;I attached my example project code. I run it with the default compiler debug profile+/Qopenmp. If someone could try and open it and see whether they are having the same problem I would really appreciate it. I have been struggling with this for days now and I can't seem to find a solution :-(&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;BR /&gt;&lt;BR /&gt;Casper</description>
      <pubDate>Tue, 06 Jan 2009 14:46:04 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875157#M73593</guid>
      <dc:creator>PKM</dc:creator>
      <dc:date>2009-01-06T14:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875158#M73594</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="margin-top: 5px; width: 100%;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/409519"&gt;Casper Kirkegaard&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt;&lt;BR /&gt;You are right Jim ... I'm also having this problem with more complicated code and I just wanted to keep my test case simple ...&lt;BR /&gt;&lt;BR /&gt;Anyway, I tried rewriting the code into its own subroutine as you suggested - unsuccesfull, however. I have also gone through all the compiler settings at least 10 times before posting here, so unless there are optimizations hidden in a setting that I don't of this should not be the cause.&lt;BR /&gt;&lt;BR /&gt;I attached my example project code. I run it with the default compiler debug profile+/Qopenmp. If someone could try and open it and see whether they are having the same problem I would really appreciate it. I have been struggling with this for days now and I can't seem to find a solution :-(&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;BR /&gt;&lt;BR /&gt;Casper&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;BR /&gt;Casper,&lt;BR /&gt;&lt;BR /&gt;Your sample code was not to be found??&lt;BR /&gt;&lt;BR /&gt;Jim</description>
      <pubDate>Tue, 06 Jan 2009 15:09:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875158#M73594</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2009-01-06T15:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875159#M73595</link>
      <description>&lt;BR /&gt;Sorry. I had a hard time figuring out how to attach files. Itried editing my post but couldn't really get it to work.&lt;BR /&gt;&lt;BR /&gt;Anyway, the file is here:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://software.intel.com/file/8419" target="_blank"&gt;http://software.intel.com/file/8419&lt;/A&gt;</description>
      <pubDate>Tue, 06 Jan 2009 16:27:37 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875159#M73595</guid>
      <dc:creator>PKM</dc:creator>
      <dc:date>2009-01-06T16:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875160#M73596</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
&lt;BR /&gt;You may have a bug here. IVF is inserting a break point at each step of the statement "x=x+i" as opposed to at the first assembly code line of the statement. On my system it take 3 continues to advance the statement. File a report with Premier Support. Also, move the break point to the "x=x+i" as opposed to being located on the "do i=1,100" statement.&lt;BR /&gt;&lt;BR /&gt;Sample of code using subroutine&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE&gt;[cpp]    program Console2
    implicit none
    integer i
    real*8  x
    
    x = 0
    !$omp parallel private(i) shared(x) num_threads(1)
    !$omp do schedule(static)
    do i=1,100 
      call DoSum(x,i)
    enddo
    !$omp end do
    !$omp end parallel
    
    end program Console2

    subroutine DoSum(x, i)
    implicit none
    integer i
    real*8  x
    !$omp atomic
    x=x+i
    end subroutine DoSum
[/cpp]&lt;/PRE&gt;
&lt;BR /&gt;Jim Dempsey</description>
      <pubDate>Tue, 06 Jan 2009 17:46:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875160#M73596</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2009-01-06T17:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875161#M73597</link>
      <description>&lt;DIV style="margin:0px;"&gt;Thanks a lot Jim!&lt;BR /&gt;&lt;BR /&gt;I alsofound itstrangethat stepping through code follows the assembler lines rather than the code lines. I come from more modern programming languages and Fortran is new to me, so I just assumed this was intentional behaviour for an old low level language ... Also, this strange assembly-stepping behaviour is not just for this particular example -it is consistent. Iuse the default debug compilation profile, but could it be there is some setting I need to change to get "normal" codeline-by-codeline stepping behaviour? Are you using the same IVF as me? Perhaps I should give the 11.1 trial a go to see if itbehaves differently ..&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Casper&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;
&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Jan 2009 19:19:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875161#M73597</guid>
      <dc:creator>PKM</dc:creator>
      <dc:date>2009-01-06T19:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875162#M73598</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
&lt;BR /&gt;I am using IVF 11.0.066&lt;BR /&gt;&lt;BR /&gt;Jim&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Jan 2009 19:31:11 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875162#M73598</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2009-01-06T19:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875163#M73599</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
Instructions for attaching files are &lt;A href="http://software.intel.com/en-us/forums/showannouncement.php?a=78"&gt;here&lt;/A&gt; (announcement at top of forum). Most people miss steps 5-7.&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Jan 2009 20:28:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875163#M73599</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2009-01-06T20:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875164#M73600</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="width: 100%; margin-top: 5px;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/99850"&gt;jimdempseyatthecove&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt; &lt;BR /&gt;You may have a bug here. IVF is inserting a break point at each step of the statement "x=x+i" as opposed to at the first assembly code line of the statement. On my system it take 3 continues to advance the statement. File a report with Premier Support. Also, move the break point to the "x=x+i" as opposed to being located on the "do i=1,100" statement.&lt;BR /&gt;&lt;BR /&gt;Sample of code using subroutine&lt;BR /&gt;&lt;BR /&gt;
&lt;/EM&gt;&lt;PRE&gt;&lt;EM&gt;[cpp]    program Console2&lt;BR /&gt;    implicit none&lt;BR /&gt;    integer i&lt;BR /&gt;    real*8  x&lt;BR /&gt;    &lt;BR /&gt;    x = 0&lt;BR /&gt;    !$omp parallel private(i) shared(x) num_threads(1)&lt;BR /&gt;    !$omp do schedule(static)&lt;BR /&gt;    do i=1,100 &lt;BR /&gt;      call DoSum(x,i)&lt;BR /&gt;    enddo&lt;BR /&gt;    !$omp end do&lt;BR /&gt;    !$omp end parallel&lt;BR /&gt;    &lt;BR /&gt;    end program Console2&lt;BR /&gt;&lt;BR /&gt;    subroutine DoSum(x, i)&lt;BR /&gt;    implicit none&lt;BR /&gt;    integer i&lt;BR /&gt;    real*8  x&lt;BR /&gt;    !$omp atomic&lt;BR /&gt;    x=x+i&lt;BR /&gt;    end subroutine DoSum&lt;BR /&gt;[/cpp]&lt;/EM&gt;&lt;/PRE&gt;
&lt;BR /&gt;Jim Dempsey&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
This is a bit off topic, but nonetheless an interesting sidelight on OpenMP. Running the program above (Release build) with an i loop limit of 10,000,000 instead of 100 takes 0.38 sec on my machine. Increasing the number of threads to 4 gives an execution time of 4.27 sec. I guess !$omp atomic is quite expensive.&lt;BR /&gt;&lt;BR /&gt;Gib&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Jan 2009 04:08:11 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875164#M73600</guid>
      <dc:creator>gib</dc:creator>
      <dc:date>2009-01-07T04:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875165#M73601</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
&lt;BR /&gt;
&lt;PRE&gt;[cpp]Yes it is, that is why you use reduction variables,
the atomic operation occures on the exit of the loop,
once per thread. In this example you would have 4 atomic
add operations as opposed to 10,000,000 atomic add operations.

!$omp parallel private(i) num_threads(1)
!$omp do reduction(+:X)
       DO I=1,100 
        X=X+I
       ENDDO
!$omp end do
! subroutine scoped X has full result
!$omp end parallel

or

!$omp parallel private(i), num_threads(1), reduction(+:X)
!$omp do
       DO I=1,100 
        X=X+I
       ENDDO
!$omp end do
! each thread parallel region scoped X has partial result
!$omp end parallel
! subroutine scoped X has full result

or

!$omp parallel private(i), num_threads(1),  reduction(+:X)
!$omp do
       DO I=1,100 
        call DoSum(X,I)
       ENDDO
!$omp end do
! each thread parallel region scoped X has partial result
!$omp end parallel
! subroutine scoped X has full result
...
subroutine DoSum(x, i) 
    implicit none 
    integer i 
    real*8  x 
     x=x+i ! without !$OMP ATOMIC
end subroutine DoSum 


[/cpp]&lt;/PRE&gt;
Jim</description>
      <pubDate>Wed, 07 Jan 2009 18:36:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875165#M73601</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2009-01-07T18:36:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875166#M73602</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="width: 100%; margin-top: 5px;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/99850"&gt;jimdempseyatthecove&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt; &lt;BR /&gt;
&lt;/EM&gt;&lt;PRE&gt;&lt;EM&gt;[cpp]Yes it is, that is why you use reduction variables,&lt;BR /&gt;the atomic operation occures on the exit of the loop,&lt;BR /&gt;once per thread. In this example you would have 4 atomic&lt;BR /&gt;add operations as opposed to 10,000,000 atomic add operations.&lt;BR /&gt;&lt;BR /&gt;!$omp parallel private(i) num_threads(1)&lt;BR /&gt;!$omp do reduction(+:X)&lt;BR /&gt;       DO I=1,100 &lt;BR /&gt;        X=X+I&lt;BR /&gt;       ENDDO&lt;BR /&gt;!$omp end do&lt;BR /&gt;! subroutine scoped X has full result&lt;BR /&gt;!$omp end parallel&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;!$omp parallel private(i), num_threads(1), reduction(+:X)&lt;BR /&gt;!$omp do&lt;BR /&gt;       DO I=1,100 &lt;BR /&gt;        X=X+I&lt;BR /&gt;       ENDDO&lt;BR /&gt;!$omp end do&lt;BR /&gt;! each thread parallel region scoped X has partial result&lt;BR /&gt;!$omp end parallel&lt;BR /&gt;! subroutine scoped X has full result&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;!$omp parallel private(i), num_threads(1),  reduction(+:X)&lt;BR /&gt;!$omp do&lt;BR /&gt;       DO I=1,100 &lt;BR /&gt;        call DoSum(X,I)&lt;BR /&gt;       ENDDO&lt;BR /&gt;!$omp end do&lt;BR /&gt;! each thread parallel region scoped X has partial result&lt;BR /&gt;!$omp end parallel&lt;BR /&gt;! subroutine scoped X has full result&lt;BR /&gt;...&lt;BR /&gt;subroutine DoSum(x, i) &lt;BR /&gt;    implicit none &lt;BR /&gt;    integer i &lt;BR /&gt;    real*8  x &lt;BR /&gt;     x=x+i ! without !$OMP ATOMIC&lt;BR /&gt;end subroutine DoSum &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;[/cpp]&lt;/EM&gt;&lt;/PRE&gt;
Jim&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
Continuing off topic, because this is very educational: not knowing about the reduction clause, I improvised the following:&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;nthreads = 4&lt;BR /&gt;nloop = 10000000&lt;BR /&gt;dn = nloop/nthreads&lt;BR /&gt;x = 0  &lt;BR /&gt;!$omp parallel do private(i,kpar,xt) num_threads(nthreads)&lt;BR /&gt;do k = 1,nthreads&lt;BR /&gt; kpar = omp_get_thread_num()&lt;BR /&gt; xt = 0&lt;BR /&gt; do i = 1 + kpar*dn, (kpar+1)*dn&lt;BR /&gt; call DoSum(xt,i)  &lt;BR /&gt; enddo &lt;BR /&gt; !$omp atomic&lt;BR /&gt; x = xt + x &lt;BR /&gt;enddo&lt;BR /&gt;!$omp end parallel do  &lt;BR /&gt;...&lt;BR /&gt; &lt;BR /&gt;subroutine DoSum(x, i)  &lt;BR /&gt;implicit none  &lt;BR /&gt;integer i  &lt;BR /&gt;real*8  x  &lt;BR /&gt;x=x+i  &lt;BR /&gt;end subroutine DoSum  &lt;BR /&gt;&lt;BR /&gt;Is this equivalent to one/all of your more elegant code examples?&lt;BR /&gt;&lt;BR /&gt;Gib&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Jan 2009 21:22:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875166#M73602</guid>
      <dc:creator>gib</dc:creator>
      <dc:date>2009-01-07T21:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875167#M73603</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
&lt;BR /&gt;No it is not the same. &lt;BR /&gt;k iterates over 1:n (split by the compilerinto four treads each with a portion of the range) &lt;BR /&gt;i iterates over 1:n (split by you into four treads each with a portion of the range)&lt;BR /&gt;Therefor the end result in X will be nloop * the result of X from the original code.&lt;BR /&gt;&lt;BR /&gt;You may have been thinking along the line of the following:&lt;BR /&gt;
&lt;PRE&gt;[cpp]nthreads = 4
nloop = 10000000
dn = nloop/nthreads
x = 0 
!$omp parallel private(i,kpar,xt) num_threads(nthreads)
kpar = omp_get_thread_num()
xt = 0
do i = 1 + kpar*dn, (kpar+1)*dn
call DoSum(xt,i) 
enddo 
!$omp atomic
x = xt + x 
!$omp end parallel 
...

subroutine DoSum(x, i) 
implicit none 
integer i 
real*8 x 
x=x+i 
end subroutine DoSum 
[/cpp]&lt;/PRE&gt;
&lt;BR /&gt;Jim&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Jan 2009 22:40:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875167#M73603</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2009-01-07T22:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875168#M73604</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="width: 100%; margin-top: 5px;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/99850"&gt;jimdempseyatthecove&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt; &lt;BR /&gt;No it is not the same. &lt;BR /&gt;k iterates over 1:n (split by the compilerinto four treads each with a portion of the range) &lt;BR /&gt;i iterates over 1:n (split by you into four treads each with a portion of the range)&lt;BR /&gt;Therefor the end result in X will be nloop * the result of X from the original code.&lt;BR /&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
Actually k iterates over 1:nthreads, and for each thread i iterates over a fraction 1/nthreads of the whole range. My code yields exactly the same result in the same time as your third example. Thanks for alerting me to 'reduction'.&lt;BR /&gt;&lt;BR /&gt;Gib&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Jan 2009 22:55:11 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875168#M73604</guid>
      <dc:creator>gib</dc:creator>
      <dc:date>2009-01-07T22:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875169#M73605</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="margin-top: 5px; width: 100%;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/311276"&gt;gib&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt;
&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="margin-top: 5px; width: 100%;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/99850"&gt;jimdempseyatthecove&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt;&lt;BR /&gt;No it is not the same. &lt;BR /&gt;k iterates over 1:n (split by the compilerinto four treads each with a portion of the range) &lt;BR /&gt;i iterates over 1:n (split by you into four treads each with a portion of the range)&lt;BR /&gt;Therefor the end result in X will be nloop * the result of X from the original code.&lt;BR /&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
Actually k iterates over 1:nthreads, and for each thread i iterates over a fraction 1/nthreads of the whole range. My code yields exactly the same result in the same time as your third example. Thanks for alerting me to 'reduction'.&lt;BR /&gt;&lt;BR /&gt;Gib&lt;BR /&gt;&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;BR /&gt;Gib,&lt;BR /&gt;&lt;BR /&gt;There is the potential for an intermittent bug to appear in your program that you should be aware of. The OpenMP clause num_threads(nhtreads) is a suggestion for a desired number of threads and not a declaration of a required number of threads. When the number of threads available to the parallel region is less than what you requested then your routine will break. Also, when the number of threads available is equal to the number of threads requested, other activities on the system may interfere with one or more of these threads from starting up immediatelyand depending on your scheduling (default scheduling for OpenMP) one of the thread team members may execute an iteration you expect to be executed by a different team member (e.g. kpar varies 0,1,2,0 not 0,1,2,3)&lt;BR /&gt;&lt;BR /&gt;Jim Dempsey</description>
      <pubDate>Fri, 09 Jan 2009 13:45:22 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875169#M73605</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2009-01-09T13:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to debug OpenMP parallelized code with vfn 10.1?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875170#M73606</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="width: 100%; margin-top: 5px;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/99850"&gt;jimdempseyatthecove&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt; &lt;BR /&gt;Gib,&lt;BR /&gt;&lt;BR /&gt;There is the potential for an intermittent bug to appear in your program that you should be aware of. The OpenMP clause num_threads(nhtreads) is a suggestion for a desired number of threads and not a declaration of a required number of threads. When the number of threads available to the parallel region is less than what you requested then your routine will break. Also, when the number of threads available is equal to the number of threads requested, other activities on the system may interfere with one or more of these threads from starting up immediatelyand depending on your scheduling (default scheduling for OpenMP) one of the thread team members may execute an iteration you expect to be executed by a different team member (e.g. kpar varies 0,1,2,0 not 0,1,2,3)&lt;BR /&gt;&lt;BR /&gt;Jim Dempsey&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
Thanks Jim. First, I should point out that I've never used the num_threads clause in my own programs - I just learned of it from your code examples. The possibility of the parallel section being executed by fewer than nthreads team members is indeed a trap for the unwary. All my OpenMP code is currently run on my personal quad core machine, therefore the possibility of a team member being unavailable is remote, but when/if I start running my program on a shared memory server that has other users, or if/when I make my code available to others the situation will be different.&lt;BR /&gt;&lt;BR /&gt;Now, I have a couple of questions, if you don't mind. In my own code I start by calling omp_set_num_threads(nthreads) in an initialisation subroutine, and I assume that this number of threads will henceforth be available. Assuming that the number of threads allocated initially is what I request (as checked with omp_get_num_threads()), does this guarantee that the same number will be available throughout the execution of the program, as I've been assuming? I found the following info in some online OpenM documentation: "when dynamic adjustment of the number of threads is disabled, omp_set_num_threads sets the exact number of threads to use in the next parallel region. " I never enable or disable dynamic adjustment - which is the default? The section I quoted refers to the "next parallel section" - what about the parallel section after that?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Gib&lt;BR /&gt;</description>
      <pubDate>Fri, 09 Jan 2009 20:19:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-debug-OpenMP-parallelized-code-with-vfn-10-1/m-p/875170#M73606</guid>
      <dc:creator>gib</dc:creator>
      <dc:date>2009-01-09T20:19:52Z</dc:date>
    </item>
  </channel>
</rss>

