<?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 Try using in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sharing-COMMON-data-between-DLLs/m-p/1099286#M126361</link>
    <description>&lt;P&gt;Try using&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;COMMON /hack/ hackIgnoreThis
!DIR$ OBJCOMMENT LINKER: "/SECTION:.data,RWS"
COMMON /YourSharedCommon/ A,B,C,...&lt;/PRE&gt;

&lt;P&gt;Notes,&lt;/P&gt;

&lt;P&gt;a) hackIgnoreThis and A,B, C are uninitialized and are expected to be placed into .bss section.&lt;BR /&gt;
	b) The /hack/ common block strategically placed before your shared and uninitialized common is placed in there such that the compiler is condition to having the output set to the .bss section. IOW any immediately following common block, intended for .bss, do not require a linker directive to set the section.&lt;BR /&gt;
	c) The linker comment is intended to redirect the output (to same section) to the .data section.&lt;/P&gt;

&lt;P&gt;The unknowns are:&lt;/P&gt;

&lt;P&gt;1) If the compiler would not reissue a section comment back to the .bss following the !DIR$&lt;BR /&gt;
	2) If the compiler supports !DIR$ OBJCOMMENT LINKER:"..."&lt;BR /&gt;
	(if not, why not???)&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
    <pubDate>Tue, 04 Oct 2016 14:57:44 GMT</pubDate>
    <dc:creator>jimdempseyatthecove</dc:creator>
    <dc:date>2016-10-04T14:57:44Z</dc:date>
    <item>
      <title>Sharing COMMON data between DLLs</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sharing-COMMON-data-between-DLLs/m-p/1099281#M126356</link>
      <description>&lt;P&gt;For this particular project, I have created A.dll, B.dll, and C.exe.&lt;/P&gt;

&lt;P&gt;A.dll does a whole lot of calculations, and keeps the numbers in COMMON blocks. &amp;nbsp;Given the sheer number of variables and COMMON blocks, I have attempted to export them like so in a single subroutine:&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; IMPLICIT DOUBLE PRECISION (A-H,K-Z)&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; COMMON /FUN2 &amp;nbsp; &amp;nbsp; &amp;nbsp; / CFUN2 &amp;nbsp; &amp;nbsp; ( &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;76)&lt;BR /&gt;
	!DIR$ ATTRIBUTES DLLEXPORT :: /FUN2/&lt;/P&gt;

&lt;P&gt;C.exe will load A.dll, direct A.dll to initialize itself, and populate the variables in the COMMON blocks. &amp;nbsp;So far so good! &amp;nbsp;But now, C.exe loads B.dll, and calls one special subroutine in B.dll. &amp;nbsp;Now, B.dll contains this:&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; SUBROUTINE Special()&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; !DIR$ ATTRIBUTES DLLIMPORT :: /FUN2/&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; DOUBLE PRECISION C1, C2, C3, ...&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; COMMON/FUN2/&lt;SPAN style="font-size: 13.008px;"&gt;C1, C2, C3(2,11), ...&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px;"&gt;But unfortunately, once I step into Special(), the value of C1 is equal to 0. &amp;nbsp;If I'm in A.dll, the value of C1 is non-zero. &amp;nbsp;So, I have the impression that I messed up somewhere in sharing the data in the COMMON blocks between A.dll and B.dll. &amp;nbsp;Any idea what I'm doing wrong?&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 17:47:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sharing-COMMON-data-between-DLLs/m-p/1099281#M126356</guid>
      <dc:creator>Nick2</dc:creator>
      <dc:date>2016-10-03T17:47:14Z</dc:date>
    </item>
    <item>
      <title>There is a DLL example that</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sharing-COMMON-data-between-DLLs/m-p/1099282#M126357</link>
      <description>&lt;P&gt;There is a DLL example that demonstrates this.&amp;nbsp;Its included w/the PSXE 2016 release (&amp;lt;install-dir&amp;gt;\IntelSWTools\samples_2016\en\compiler_f\PSXE\DLL.zip), or online for PSXE 2017 at: &lt;A href="https://software.intel.com/en-us/product-code-samples"&gt;https://software.intel.com/en-us/product-code-samples&lt;/A&gt; (filter for Fortran and Windows), or try the direct link: &lt;A href="https://software.intel.com/en-us/node/611720"&gt;https://software.intel.com/en-us/node/611720&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Perhaps the missing ingredients are explicit initialization and&amp;nbsp;the linker options, &lt;STRONG&gt;/section:.data,rws&lt;/STRONG&gt; for the DLL containing the shared data.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 18:50:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sharing-COMMON-data-between-DLLs/m-p/1099282#M126357</guid>
      <dc:creator>Kevin_D_Intel</dc:creator>
      <dc:date>2016-10-03T18:50:00Z</dc:date>
    </item>
    <item>
      <title>Oh.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sharing-COMMON-data-between-DLLs/m-p/1099283#M126358</link>
      <description>&lt;P&gt;Oh.&lt;/P&gt;

&lt;OL&gt;
	&lt;LI&gt;The variables must be initialized to a non-zero value so that they are placed in the &lt;SPAN style="font-weight: bold;"&gt;.data&lt;/SPAN&gt; image section&lt;/LI&gt;
	&lt;LI&gt;The linker command line options are modified to add: &lt;SPAN style="font-weight: bold;"&gt;/section:.data,RWS&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px;"&gt;Bummer I didn't find this sooner. &amp;nbsp;Now that I look at it, my variables that are in BLOCK DATA are visible from B.dll. &amp;nbsp;And I never added the linker flag from the second requirement.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px;"&gt;May I suggest somebody to update this page? &amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://software.intel.com/en-us/node/535307" target="_blank"&gt;https://software.intel.com/en-us/node/535307&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Is there any way to bypass the 1st requirement? &amp;nbsp;Some unknown fraction of my COMMON variables are declared in 3000-lines worth of BLOCK DATA; some unknown fraction is declared in BLOCK DATA that initializes it to 0, and I also rely on /Qinit:zero&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 20:47:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sharing-COMMON-data-between-DLLs/m-p/1099283#M126358</guid>
      <dc:creator>Nick2</dc:creator>
      <dc:date>2016-10-03T20:47:10Z</dc:date>
    </item>
    <item>
      <title>You may check with Depwalker</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sharing-COMMON-data-between-DLLs/m-p/1099284#M126359</link>
      <description>&lt;P&gt;You may check with Depwalker &amp;nbsp;if the common is really exported/imported.&lt;/P&gt;

&lt;P&gt;Another solution is to&amp;nbsp;pass the base address of the common and its length when the DLL is called and acquire its content.&amp;nbsp;Copy back the common content&amp;nbsp;at the DLL exit point.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 08:11:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sharing-COMMON-data-between-DLLs/m-p/1099284#M126359</guid>
      <dc:creator>LRaim</dc:creator>
      <dc:date>2016-10-04T08:11:45Z</dc:date>
    </item>
    <item>
      <title>I’m uncertain about the</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sharing-COMMON-data-between-DLLs/m-p/1099285#M126360</link>
      <description>&lt;P&gt;I’m uncertain about the reason for the non-zero initialization and inquired about that and if it can be bypassed.&lt;/P&gt;

&lt;P&gt;As I understand it, the linker flag makes the data explicitly read-write-sharable so that may not be applicable for all use cases, and we’ll look at improvements to the User’s Guide on these.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 12:33:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sharing-COMMON-data-between-DLLs/m-p/1099285#M126360</guid>
      <dc:creator>Kevin_D_Intel</dc:creator>
      <dc:date>2016-10-04T12:33:09Z</dc:date>
    </item>
    <item>
      <title>Try using</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sharing-COMMON-data-between-DLLs/m-p/1099286#M126361</link>
      <description>&lt;P&gt;Try using&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;COMMON /hack/ hackIgnoreThis
!DIR$ OBJCOMMENT LINKER: "/SECTION:.data,RWS"
COMMON /YourSharedCommon/ A,B,C,...&lt;/PRE&gt;

&lt;P&gt;Notes,&lt;/P&gt;

&lt;P&gt;a) hackIgnoreThis and A,B, C are uninitialized and are expected to be placed into .bss section.&lt;BR /&gt;
	b) The /hack/ common block strategically placed before your shared and uninitialized common is placed in there such that the compiler is condition to having the output set to the .bss section. IOW any immediately following common block, intended for .bss, do not require a linker directive to set the section.&lt;BR /&gt;
	c) The linker comment is intended to redirect the output (to same section) to the .data section.&lt;/P&gt;

&lt;P&gt;The unknowns are:&lt;/P&gt;

&lt;P&gt;1) If the compiler would not reissue a section comment back to the .bss following the !DIR$&lt;BR /&gt;
	2) If the compiler supports !DIR$ OBJCOMMENT LINKER:"..."&lt;BR /&gt;
	(if not, why not???)&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 14:57:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sharing-COMMON-data-between-DLLs/m-p/1099286#M126361</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2016-10-04T14:57:44Z</dc:date>
    </item>
    <item>
      <title>My apologies. Following some</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Sharing-COMMON-data-between-DLLs/m-p/1099287#M126362</link>
      <description>&lt;P&gt;My apologies. Following some consultation, I learned my advice was incorrect for your use case.&lt;/P&gt;

&lt;P&gt;The DLL example applies when data is to be shared across two or more separately running programs. In your case, to share data among a main program and DLLs in the same running program, neither the linker directive nor initialization is required.&lt;/P&gt;

&lt;P&gt;To borrow from the guidance I received:&lt;/P&gt;

&lt;P&gt;In your case, it is required that shared data (be it COMMON or a module) be linked into its own DLL, DLLEXPORTed, and any other DLL or EXE that wants to use the data, link directly to the shared data DLL and DLLIMPORT the data. (If the data is in a module, the DLLIMPORT happens automatically if the module DLLEXPORTs the data, but for a COMMON you have to do it yourself.) There is no requirement for initialization. Note the example below uses BLOCK DATA for the COMMON DLL definition.&lt;/P&gt;

&lt;P&gt;The example below was also provided to me to help demonstrate your use case.&lt;BR /&gt;
	&amp;nbsp;&lt;BR /&gt;
	cmndll.f90 declares the COMMON block and DLLEXPORTs this. dllsub.f90 is a subroutine that uses the COMMON and updates it, and then main.f90 also uses the COMMON and calls the subroutine.&amp;nbsp; The intent is to show that the data is shared.&lt;/P&gt;

&lt;P&gt;Build the example like this:&lt;/P&gt;

&lt;PRE class="brush:bash;"&gt;ifort /dll /libs:dll cmndll.f90
ifort /dll /libs:dll dllsub.f90 cmndll.lib
ifort /libs:dll main.f90 dllsub.lib cmndll.lib&lt;/PRE&gt;

&lt;P&gt;Note the use of &lt;STRONG&gt;/libs:dll &lt;/STRONG&gt;– this makes sure that all code is referencing the DLL form of the run-time library. When run you see:&lt;/P&gt;

&lt;PRE class="brush:bash;"&gt;Main program, setting sharedvar to 486
Calling DLLSUB
Entering DLLSUB, sharedvar =&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 486
Leaving DLLSUB, sharedvar =&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 487
Back in main program, sharedvar =&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 487&lt;/PRE&gt;

&lt;P&gt;This demonstrates that the data is shared between the main program and the subroutine, with the data residing in the shared DLL.&lt;/P&gt;

&lt;P&gt;cmddll.f90:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;block data cmndll
integer sharedvar
common /cmn/ sharedvar
!DEC$ ATTRIBUTES DLLEXPORT :: /cmn/
end block data cmndll&lt;/PRE&gt;

&lt;P&gt;dllsub.f90:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;subroutine dllsub
!DEC$ attributes dllexport :: dllsub
integer sharedvar
common /cmn/ sharedvar
!DEC$ ATTRIBUTES DLLIMPORT :: /cmn/

print *, "Entering DLLSUB, sharedvar = ", sharedvar
sharedvar = sharedvar + 1
print *, "Leaving DLLSUB, sharedvar = ", sharedvar
end subroutine dllsub&lt;/PRE&gt;

&lt;P&gt;main.f90:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;program main
integer sharedvar
common /cmn/ sharedvar
!DEC$ ATTRIBUTES DLLIMPORT :: /cmn/

print *, "Main program, setting sharedvar to 486"
sharedvar = 486
print *, "Calling DLLSUB"
call dllsub
print *, "Back in main program, sharedvar = ", sharedvar
end program main&lt;/PRE&gt;

&lt;P&gt;I apologize again for the mis-information&amp;nbsp;for your use case.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 15:43:37 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Sharing-COMMON-data-between-DLLs/m-p/1099287#M126362</guid>
      <dc:creator>Kevin_D_Intel</dc:creator>
      <dc:date>2016-10-04T15:43:37Z</dc:date>
    </item>
  </channel>
</rss>

