<?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 Multithreading in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/Multithreading/m-p/938382#M16404</link>
    <description>I'm using Compaq Visual Fortran, ver. 6.5, and am having trouble  &lt;BR /&gt;implementing the CreateThread call. The motivation for creating another &lt;BR /&gt;thread is not for parallel processing, it's because I'm making a  &lt;BR /&gt;'recursive' call to a NAG subroutine (nag_nlp_sol), but that subroutine &lt;BR /&gt;does not support RECURSIVE calls. So, I'm trying to separate the data in &lt;BR /&gt;the two separate calls to nag_nlp_sol by running them in different  &lt;BR /&gt;threads. The nag_nlp_sol routine is supposedly 'thread safe'. &lt;BR /&gt; &lt;BR /&gt;Anyway, I'm not having success using multiple threads. I put together a &lt;BR /&gt;simple program that highlights the problem, while removing most of the  &lt;BR /&gt;real program's complexity. &lt;BR /&gt; &lt;BR /&gt;The following program takes a given value of 'x', set in a PARAMS module &lt;BR /&gt;(shared data for all routines), calls a subroutine to calculate y=x**2, &lt;BR /&gt;which in turn calls another subroutine to calculate z=y*1000. It works  &lt;BR /&gt;in the form below (just using subroutine calls with no multithreading), &lt;BR /&gt;but apparently fails to enter MOD2 at all when I try to run the call to &lt;BR /&gt;'calcz' in a separate thread. Clearly, I'm making a fundamental error in &lt;BR /&gt;the way I'm trying to do this, but I don't know where and the thing  &lt;BR /&gt;compiles without any errors.  &lt;BR /&gt; &lt;BR /&gt;Also, if I try to add a call to WaitForSingleObject, it fails miserably. &lt;BR /&gt;And, I'd like to use  &lt;BR /&gt;    CreateThread(0, 0, calcz, 0,  0, ThreadID)   &lt;BR /&gt;instead of &lt;BR /&gt;    CreateThread(0, 0, calcz, y1, 0, ThreadID) &lt;BR /&gt; &lt;BR /&gt;(i.e., omit the parameter argument 'y1'), and just set the value of z &lt;BR /&gt;by calculating z=y*1000 in MOD2, but that causes more problems. &lt;BR /&gt; &lt;BR /&gt;Any help would be appreciated. The program follows: &lt;BR /&gt; &lt;BR /&gt;! Multithread test program - if working properly, the program &lt;BR /&gt;! takes an initial value of x, calls MOD1 to calculate &lt;BR /&gt;! y = x**2, which in turn calls MOD2 to calculate z = y * 1000. &lt;BR /&gt;! &lt;BR /&gt;! The program works in the form below, but does not work when  &lt;BR /&gt;! an attempt is made to calculate z in a separate thread. Also,  &lt;BR /&gt;! the WaitForSingleObject call is death. &lt;BR /&gt; &lt;BR /&gt;MODULE PARAMS &lt;BR /&gt; &lt;BR /&gt;  IMPLICIT NONE &lt;BR /&gt;  SAVE &lt;BR /&gt;  INTRINSIC KIND &lt;BR /&gt;  INTEGER, PARAMETER :: wp = KIND(1.0D0) &lt;BR /&gt; &lt;BR /&gt;  REAL(wp) :: x, y, z &lt;BR /&gt; &lt;BR /&gt;  DATA x /5.0_wp/ &lt;BR /&gt; &lt;BR /&gt;END MODULE PARAMS &lt;BR /&gt; &lt;BR /&gt;!**************** &lt;BR /&gt; &lt;BR /&gt;MODULE MOD2 &lt;BR /&gt; &lt;BR /&gt;  IMPLICIT NONE  &lt;BR /&gt;  CONTAINS &lt;BR /&gt; &lt;BR /&gt;  SUBROUTINE calcz(y1) &lt;BR /&gt; &lt;BR /&gt;      USE PARAMS &lt;BR /&gt;      REAL(wp), INTENT (IN) :: y1 &lt;BR /&gt; &lt;BR /&gt;          z = y1 * 1000 &lt;BR /&gt; &lt;BR /&gt;      open(unit=5, file='c:	est.out', status='unknown', action='write') &lt;BR /&gt;      write (5,100) &lt;BR /&gt;          100 format ('MOD2 reached.') &lt;BR /&gt; &lt;BR /&gt;  END SUBROUTINE calcz &lt;BR /&gt;END MODULE MOD2 &lt;BR /&gt; &lt;BR /&gt;!************** &lt;BR /&gt; &lt;BR /&gt;MODULE MOD1 &lt;BR /&gt; &lt;BR /&gt;  IMPLICIT NONE &lt;BR /&gt;  CONTAINS &lt;BR /&gt; &lt;BR /&gt;  SUBROUTINE calcy(x1) &lt;BR /&gt;  &lt;BR /&gt;      USE DFMT &lt;BR /&gt;      USE PARAMS &lt;BR /&gt;      USE MOD2, ONLY : calcz &lt;BR /&gt; &lt;BR /&gt;      INTEGER :: ThreadHandle, ThreadID, Err &lt;BR /&gt; &lt;BR /&gt;      REAL(wp), INTENT (IN) :: x1 &lt;BR /&gt;      REAL(wp) :: y1 &lt;BR /&gt; &lt;BR /&gt;      y = x1**2 &lt;BR /&gt;      y1 = y &lt;BR /&gt; &lt;BR /&gt;! The program works with the following CALL uncommented. &lt;BR /&gt;! However, if you comment-out the CALL and uncomment the  &lt;BR /&gt;! CreateThread line, it doesn't work. If in addition you &lt;BR /&gt;! uncomment the WaitForSingleObject line, the program  &lt;BR /&gt;! dies horribly. &lt;BR /&gt; &lt;BR /&gt;      CALL calcz(y1) &lt;BR /&gt; &lt;BR /&gt;!      ThreadHandle = CreateThread(0, 0, calcz, y1, 0, ThreadID) &lt;BR /&gt; &lt;BR /&gt;!      Err = WaitForSingleObject(ThreadHandle, 
WAIT_INFINITE) &lt;BR /&gt; &lt;BR /&gt;  END SUBROUTINE calcy &lt;BR /&gt;END MODULE MOD1 &lt;BR /&gt; &lt;BR /&gt;!************** &lt;BR /&gt; &lt;BR /&gt;PROGRAM mt_test &lt;BR /&gt; &lt;BR /&gt;      USE PARAMS &lt;BR /&gt;      USE MOD1, ONLY : calcy  &lt;BR /&gt;      IMPLICIT NONE &lt;BR /&gt; &lt;BR /&gt;      REAL(wp) ::  x1 &lt;BR /&gt; &lt;BR /&gt;      x1 = x &lt;BR /&gt; &lt;BR /&gt;      Call calcy(x1) &lt;BR /&gt; &lt;BR /&gt;      write (*,200) x, y, z &lt;BR /&gt;      200 format ('x = ', f8.4, 2x, 'y = ', f8.4, 2x, 'z = ', f12.4,/) &lt;BR /&gt; &lt;BR /&gt;END PROGRAM mt_test</description>
    <pubDate>Fri, 09 Feb 2001 05:49:16 GMT</pubDate>
    <dc:creator>Intel_C_Intel</dc:creator>
    <dc:date>2001-02-09T05:49:16Z</dc:date>
    <item>
      <title>Multithreading</title>
      <link>https://community.intel.com/t5/Software-Archive/Multithreading/m-p/938382#M16404</link>
      <description>I'm using Compaq Visual Fortran, ver. 6.5, and am having trouble  &lt;BR /&gt;implementing the CreateThread call. The motivation for creating another &lt;BR /&gt;thread is not for parallel processing, it's because I'm making a  &lt;BR /&gt;'recursive' call to a NAG subroutine (nag_nlp_sol), but that subroutine &lt;BR /&gt;does not support RECURSIVE calls. So, I'm trying to separate the data in &lt;BR /&gt;the two separate calls to nag_nlp_sol by running them in different  &lt;BR /&gt;threads. The nag_nlp_sol routine is supposedly 'thread safe'. &lt;BR /&gt; &lt;BR /&gt;Anyway, I'm not having success using multiple threads. I put together a &lt;BR /&gt;simple program that highlights the problem, while removing most of the  &lt;BR /&gt;real program's complexity. &lt;BR /&gt; &lt;BR /&gt;The following program takes a given value of 'x', set in a PARAMS module &lt;BR /&gt;(shared data for all routines), calls a subroutine to calculate y=x**2, &lt;BR /&gt;which in turn calls another subroutine to calculate z=y*1000. It works  &lt;BR /&gt;in the form below (just using subroutine calls with no multithreading), &lt;BR /&gt;but apparently fails to enter MOD2 at all when I try to run the call to &lt;BR /&gt;'calcz' in a separate thread. Clearly, I'm making a fundamental error in &lt;BR /&gt;the way I'm trying to do this, but I don't know where and the thing  &lt;BR /&gt;compiles without any errors.  &lt;BR /&gt; &lt;BR /&gt;Also, if I try to add a call to WaitForSingleObject, it fails miserably. &lt;BR /&gt;And, I'd like to use  &lt;BR /&gt;    CreateThread(0, 0, calcz, 0,  0, ThreadID)   &lt;BR /&gt;instead of &lt;BR /&gt;    CreateThread(0, 0, calcz, y1, 0, ThreadID) &lt;BR /&gt; &lt;BR /&gt;(i.e., omit the parameter argument 'y1'), and just set the value of z &lt;BR /&gt;by calculating z=y*1000 in MOD2, but that causes more problems. &lt;BR /&gt; &lt;BR /&gt;Any help would be appreciated. The program follows: &lt;BR /&gt; &lt;BR /&gt;! Multithread test program - if working properly, the program &lt;BR /&gt;! takes an initial value of x, calls MOD1 to calculate &lt;BR /&gt;! y = x**2, which in turn calls MOD2 to calculate z = y * 1000. &lt;BR /&gt;! &lt;BR /&gt;! The program works in the form below, but does not work when  &lt;BR /&gt;! an attempt is made to calculate z in a separate thread. Also,  &lt;BR /&gt;! the WaitForSingleObject call is death. &lt;BR /&gt; &lt;BR /&gt;MODULE PARAMS &lt;BR /&gt; &lt;BR /&gt;  IMPLICIT NONE &lt;BR /&gt;  SAVE &lt;BR /&gt;  INTRINSIC KIND &lt;BR /&gt;  INTEGER, PARAMETER :: wp = KIND(1.0D0) &lt;BR /&gt; &lt;BR /&gt;  REAL(wp) :: x, y, z &lt;BR /&gt; &lt;BR /&gt;  DATA x /5.0_wp/ &lt;BR /&gt; &lt;BR /&gt;END MODULE PARAMS &lt;BR /&gt; &lt;BR /&gt;!**************** &lt;BR /&gt; &lt;BR /&gt;MODULE MOD2 &lt;BR /&gt; &lt;BR /&gt;  IMPLICIT NONE  &lt;BR /&gt;  CONTAINS &lt;BR /&gt; &lt;BR /&gt;  SUBROUTINE calcz(y1) &lt;BR /&gt; &lt;BR /&gt;      USE PARAMS &lt;BR /&gt;      REAL(wp), INTENT (IN) :: y1 &lt;BR /&gt; &lt;BR /&gt;          z = y1 * 1000 &lt;BR /&gt; &lt;BR /&gt;      open(unit=5, file='c:	est.out', status='unknown', action='write') &lt;BR /&gt;      write (5,100) &lt;BR /&gt;          100 format ('MOD2 reached.') &lt;BR /&gt; &lt;BR /&gt;  END SUBROUTINE calcz &lt;BR /&gt;END MODULE MOD2 &lt;BR /&gt; &lt;BR /&gt;!************** &lt;BR /&gt; &lt;BR /&gt;MODULE MOD1 &lt;BR /&gt; &lt;BR /&gt;  IMPLICIT NONE &lt;BR /&gt;  CONTAINS &lt;BR /&gt; &lt;BR /&gt;  SUBROUTINE calcy(x1) &lt;BR /&gt;  &lt;BR /&gt;      USE DFMT &lt;BR /&gt;      USE PARAMS &lt;BR /&gt;      USE MOD2, ONLY : calcz &lt;BR /&gt; &lt;BR /&gt;      INTEGER :: ThreadHandle, ThreadID, Err &lt;BR /&gt; &lt;BR /&gt;      REAL(wp), INTENT (IN) :: x1 &lt;BR /&gt;      REAL(wp) :: y1 &lt;BR /&gt; &lt;BR /&gt;      y = x1**2 &lt;BR /&gt;      y1 = y &lt;BR /&gt; &lt;BR /&gt;! The program works with the following CALL uncommented. &lt;BR /&gt;! However, if you comment-out the CALL and uncomment the  &lt;BR /&gt;! CreateThread line, it doesn't work. If in addition you &lt;BR /&gt;! uncomment the WaitForSingleObject line, the program  &lt;BR /&gt;! dies horribly. &lt;BR /&gt; &lt;BR /&gt;      CALL calcz(y1) &lt;BR /&gt; &lt;BR /&gt;!      ThreadHandle = CreateThread(0, 0, calcz, y1, 0, ThreadID) &lt;BR /&gt; &lt;BR /&gt;!      Err = WaitForSingleObject(ThreadHandle, 
WAIT_INFINITE) &lt;BR /&gt; &lt;BR /&gt;  END SUBROUTINE calcy &lt;BR /&gt;END MODULE MOD1 &lt;BR /&gt; &lt;BR /&gt;!************** &lt;BR /&gt; &lt;BR /&gt;PROGRAM mt_test &lt;BR /&gt; &lt;BR /&gt;      USE PARAMS &lt;BR /&gt;      USE MOD1, ONLY : calcy  &lt;BR /&gt;      IMPLICIT NONE &lt;BR /&gt; &lt;BR /&gt;      REAL(wp) ::  x1 &lt;BR /&gt; &lt;BR /&gt;      x1 = x &lt;BR /&gt; &lt;BR /&gt;      Call calcy(x1) &lt;BR /&gt; &lt;BR /&gt;      write (*,200) x, y, z &lt;BR /&gt;      200 format ('x = ', f8.4, 2x, 'y = ', f8.4, 2x, 'z = ', f12.4,/) &lt;BR /&gt; &lt;BR /&gt;END PROGRAM mt_test</description>
      <pubDate>Fri, 09 Feb 2001 05:49:16 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Multithreading/m-p/938382#M16404</guid>
      <dc:creator>Intel_C_Intel</dc:creator>
      <dc:date>2001-02-09T05:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: Multithreading</title>
      <link>https://community.intel.com/t5/Software-Archive/Multithreading/m-p/938383#M16405</link>
      <description>Change your call to CreateThread, like so &lt;BR /&gt; &lt;BR /&gt;ThreadHandle = CreateThread(0, 0, calcz, loc(y1), 0, ThreadID) &lt;BR /&gt; &lt;BR /&gt;You can skip passing the fourth param,  &lt;BR /&gt; &lt;BR /&gt;ThreadHandle = CreateThread(0, 0, calcz, 0, 0, ThreadID)  &lt;BR /&gt;but you'll have to change the signature of calcz in mod2 to accept no parameters and remove the declaration of dummy arg y1. Then all will work fine, including WaitForSingleObject.   &lt;BR /&gt; &lt;BR /&gt;I must admit though, that I have my doubts about the overall objective here.  I'd be interested in hearing how it goes. &lt;BR /&gt; &lt;BR /&gt;hth, &lt;BR /&gt;John</description>
      <pubDate>Fri, 09 Feb 2001 07:52:04 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Multithreading/m-p/938383#M16405</guid>
      <dc:creator>Intel_C_Intel</dc:creator>
      <dc:date>2001-02-09T07:52:04Z</dc:date>
    </item>
  </channel>
</rss>

