<?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 Re: pointer to derived type component in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746602#M4398</link>
    <description>The mistake probably comes from a misalignment of double values.&lt;BR /&gt;&lt;BR /&gt;Indeed, when I add a new integer variable in the definition of the derived type, then the result is OK :&lt;BR /&gt;&lt;BR /&gt;&lt;B&gt;FORTRAN side&lt;/B&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="Courier New"&gt; TYPE, BIND(C) :: mytype&lt;BR /&gt; INTEGER(C_INT) :: ival,ival2&lt;BR /&gt; REAL(C_DOUBLE) :: dval&lt;BR /&gt; END TYPE&lt;BR /&gt;&lt;BR /&gt;&lt;B&gt;C side&lt;/B&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; typedef struct{&lt;BR /&gt;  int ival,ival2;&lt;BR /&gt;  double dval;&lt;BR /&gt; }mytype;&lt;BR /&gt;&lt;BR /&gt;&lt;B&gt;Result with ifort and gcc&lt;/B&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt; 0.000000000000000E+000 1.00000000000000 2.00000000000000&lt;BR /&gt; 3.00000000000000 4.00000000000000 5.00000000000000&lt;BR /&gt; 6.00000000000000 7.00000000000000 8.00000000000000&lt;BR /&gt; 9.00000000000000&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Thu, 17 Jan 2008 15:12:40 GMT</pubDate>
    <dc:creator>lcoul</dc:creator>
    <dc:date>2008-01-17T15:12:40Z</dc:date>
    <item>
      <title>pointer to derived type component</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746601#M4397</link>
      <description>Versions used (in debug and optimized modes) :&lt;BR /&gt;&lt;BR /&gt;ifort (IFORT) 10.0 20070809&lt;BR /&gt;gcc version 3.3.5 (Debian 1:3.3.5-13)&lt;BR /&gt;&lt;BR /&gt;and&lt;BR /&gt;&lt;BR /&gt;ifort (IFORT) 10.0 20070426&lt;BR /&gt;gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I get a wrong result with the following test example (g95 gives the correct answer but gfortran does not want to compile &lt;IMG src="https://community.intel.com/isn/Community/en-US/emoticons/emotion-9.gif" alt="Sad smiley [:(]" /&gt;) :&lt;BR /&gt;&lt;BR /&gt;&lt;B&gt;File test15.f90 : &lt;/B&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="Courier New"&gt;PROGRAM test&lt;BR /&gt;&lt;BR /&gt; USE iso_c_binding&lt;BR /&gt;&lt;BR /&gt; TYPE, BIND(C) :: mytype&lt;BR /&gt; INTEGER(C_INT) :: ival&lt;BR /&gt; REAL(C_DOUBLE) :: dval&lt;BR /&gt; END TYPE&lt;BR /&gt; &lt;BR /&gt; INTERFACE&lt;BR /&gt; FUNCTION get_c_pointer(n) RESULT BIND(C,name="get_c_pointer")&lt;BR /&gt; USE iso_c_binding&lt;BR /&gt; TYPE(C_PTR) :: r&lt;BR /&gt; INTEGER(C_INT),VALUE,INTENT(IN) :: n&lt;BR /&gt; END FUNCTION&lt;BR /&gt; END INTERFACE&lt;BR /&gt; &lt;BR /&gt; TYPE(mytype),POINTER :: array(:)&lt;BR /&gt; DOUBLE PRECISION,POINTER :: vector(:)&lt;BR /&gt; TYPE(C_PTR) :: cptr&lt;BR /&gt; &lt;BR /&gt; cptr= get_c_pointer(10)&lt;BR /&gt; CALL C_F_POINTER(cptr,array,(/10/))&lt;BR /&gt; &lt;BR /&gt; vector =&amp;gt; array(:)%dval&lt;BR /&gt; &lt;BR /&gt; WRITE(*,*) vector&lt;BR /&gt; &lt;BR /&gt;END PROGRAM&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;B&gt;File get_c_pointer : &lt;BR /&gt;&lt;BR /&gt;&lt;/B&gt;&lt;FONT face="Courier New"&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;&lt;BR /&gt;typedef struct{&lt;BR /&gt; int ival;&lt;BR /&gt; double dval;&lt;BR /&gt;}mytype;&lt;BR /&gt;&lt;BR /&gt;mytype* get_c_pointer(int n){&lt;BR /&gt; int i;&lt;BR /&gt; mytype *s;&lt;BR /&gt; s=(mytype*)malloc(n*sizeof(mytype));&lt;BR /&gt; for(i=0;i&lt;N&gt; s&lt;I&gt;.ival=i;&lt;BR /&gt; s&lt;I&gt;.dval=i;&lt;BR /&gt; }&lt;BR /&gt; return s;&lt;BR /&gt;}&lt;BR /&gt;&lt;/I&gt;&lt;/I&gt;&lt;/N&gt;&lt;/STDLIB.H&gt;&lt;/FONT&gt;&lt;B&gt;&lt;FONT face="Courier New"&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/B&gt;
&lt;FONT face="Courier New"&gt;&lt;B&gt;&lt;FONT face="Courier New"&gt;g95 result :&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/B&gt;0. 1. 2. 3. 4. 5. 6. 7. 8. 9.&lt;BR /&gt;&lt;BR /&gt;&lt;B&gt;ifort result :&lt;/B&gt;&lt;BR /&gt;&lt;BR /&gt; 2.121995790965272E-314 9.881312916824931E-324 3.00000000000000 &lt;BR /&gt; 1.114099596794633E-313 2.964393875047479E-323 7.00000000000000 &lt;BR /&gt; 1.962949719718608E-313 2.865224816750859E-309 0.000000000000000E+000&lt;BR /&gt; 0.000000000000000E+000&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;/FONT&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 17 Jan 2008 13:43:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746601#M4397</guid>
      <dc:creator>lcoul</dc:creator>
      <dc:date>2008-01-17T13:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: pointer to derived type component</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746602#M4398</link>
      <description>The mistake probably comes from a misalignment of double values.&lt;BR /&gt;&lt;BR /&gt;Indeed, when I add a new integer variable in the definition of the derived type, then the result is OK :&lt;BR /&gt;&lt;BR /&gt;&lt;B&gt;FORTRAN side&lt;/B&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="Courier New"&gt; TYPE, BIND(C) :: mytype&lt;BR /&gt; INTEGER(C_INT) :: ival,ival2&lt;BR /&gt; REAL(C_DOUBLE) :: dval&lt;BR /&gt; END TYPE&lt;BR /&gt;&lt;BR /&gt;&lt;B&gt;C side&lt;/B&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; typedef struct{&lt;BR /&gt;  int ival,ival2;&lt;BR /&gt;  double dval;&lt;BR /&gt; }mytype;&lt;BR /&gt;&lt;BR /&gt;&lt;B&gt;Result with ifort and gcc&lt;/B&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt; 0.000000000000000E+000 1.00000000000000 2.00000000000000&lt;BR /&gt; 3.00000000000000 4.00000000000000 5.00000000000000&lt;BR /&gt; 6.00000000000000 7.00000000000000 8.00000000000000&lt;BR /&gt; 9.00000000000000&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 17 Jan 2008 15:12:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746602#M4398</guid>
      <dc:creator>lcoul</dc:creator>
      <dc:date>2008-01-17T15:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: pointer to derived type component</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746603#M4399</link>
      <description>Hmm,, I'm going to have to regression test this a bit - I have the 10.1 compiler on my Mac and I get the correct answer. Have you tried the latest 10.1 compiler on your development platform?&lt;BR /&gt;&lt;BR /&gt;Here's what I'm seeing on my Mac with 10.1.007 and gcc:&lt;BR /&gt;&lt;BR /&gt;rwgreen$ gcc -m64 -c get_c_pointer.c&lt;BR /&gt;&lt;BR /&gt;rwgreen$ ifort test15.f90 get_c_pointer.o&lt;BR /&gt;test15.f90(27): (col. 3) remark: LOOP WAS VECTORIZED.&lt;BR /&gt;&lt;BR /&gt;mbp0017f2df31c3:~/quads/forums/30247174 rwgreen$ ./a.out&lt;BR /&gt; 0.000000000000000E+000 1.00000000000000 2.00000000000000 &lt;BR /&gt; 3.00000000000000 4.00000000000000 5.00000000000000 &lt;BR /&gt; 6.00000000000000 7.00000000000000 8.00000000000000 &lt;BR /&gt; 9.00000000000000 &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 17 Jan 2008 16:28:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746603#M4399</guid>
      <dc:creator>Ron_Green</dc:creator>
      <dc:date>2008-01-17T16:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: pointer to derived type component</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746604#M4400</link>
      <description>10.1.013 on Windows shows me the same good results Ron saw on MacOS.&lt;BR /&gt;</description>
      <pubDate>Thu, 17 Jan 2008 16:54:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746604#M4400</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2008-01-17T16:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: pointer to derived type component</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746605#M4401</link>
      <description>I will bet $20 you are using a 32bit Linux system, yes?&lt;BR /&gt;&lt;BR /&gt;I can reproduce this with the latest 10.1 iforts, but ONLY on 32bit Linux and Mac OS X. So it seems to be an issue with the 32bit compiler. &lt;BR /&gt;&lt;BR /&gt;On my Mac, I can compile in 32bits:&lt;BR /&gt;rwgreen$ gcc -m32 -c get_c_pointer.c&lt;BR /&gt;rwgreen$ ifort -m32 test15.f90 get_c_pointer.o&lt;BR /&gt;test15.f90(27): (col. 3) remark: LOOP WAS VECTORIZED.&lt;BR /&gt;mbp0017f2df31c3:~/quads/forums/30247174 rwgreen$ ./a.out&lt;BR /&gt; 2.121995790965272E-314 9.881312916824931E-324 3.00000000000000 &lt;BR /&gt; 1.114099596794633E-313 2.964393875047479E-323 7.00000000000000 &lt;BR /&gt; 1.962949719718608E-313 0.000000000000000E+000 0.000000000000000E+000&lt;BR /&gt; 0.000000000000000E+000&lt;BR /&gt;&lt;BR /&gt;On Linux, I used a 32bit Linux host, hence the 32bit gcc and 32bit Ifort to the same results.&lt;BR /&gt;&lt;BR /&gt;If you can, use a 64bit Linux host and 64 bit gcc and ifort to work around this issue.&lt;BR /&gt;&lt;BR /&gt;Please go to premier.intel.com and open a bug report. Reference &lt;B&gt;T82358-CP&lt;/B&gt; in your Premier issue. This is the internal bug report that I opened on this. If you don't have Premier access let me know so I an assign the bug to myself instead of you.&lt;BR /&gt;&lt;BR /&gt;ron&lt;BR /&gt;</description>
      <pubDate>Thu, 17 Jan 2008 17:26:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746605#M4401</guid>
      <dc:creator>Ron_Green</dc:creator>
      <dc:date>2008-01-17T17:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: pointer to derived type component</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746606#M4402</link>
      <description>Yes this is a 32 bit Linux&lt;BR /&gt;&lt;BR /&gt;No I cannot switch to a 64 bit system easily. I have the choice between my personal computer (core 2 duo 2.4Gz), a Cluster of 128 Linux OS nodes (32bit 3.2Gz), 1 cluster of 32 nodes (32bit 3Gz), and a farm of PCs (about 1 hundred PCs with Intel or AMD processors 32 or 64 bits). And the codes I develop must be install everywhere.&lt;BR /&gt;&lt;BR /&gt;No, I haven't Premier access. I just use the free ifort version on my personal computer and an official 10.0 version on the clusters : the maintenance team managing this network has surely a Premier access but not me.&lt;BR /&gt;&lt;BR /&gt;F. Jacq&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 17 Jan 2008 18:20:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746606#M4402</guid>
      <dc:creator>lcoul</dc:creator>
      <dc:date>2008-01-17T18:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: pointer to derived type component</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746607#M4403</link>
      <description>You have access to Intel Premier Support even with the free non-commercial license. Just &lt;A href="https://registrationcenter.intel.com/"&gt;register your serial number&lt;/A&gt; and check the box to register for support.&lt;BR /&gt;&lt;BR /&gt;What I found is that the Fortran compiler needs to know whether or not the "companion C processor" inserts padding for misaligned members of structs by default. Apparently some do (MSVC) and some don't (gcc?).&lt;BR /&gt;</description>
      <pubDate>Thu, 17 Jan 2008 19:29:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746607#M4403</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2008-01-17T19:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: pointer to derived type component</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746608#M4404</link>
      <description>OK, how about just using -malign-double with gcc?&lt;BR /&gt;&lt;BR /&gt;rwgreen$ gcc -m32 -malign-double -c get_c_pointer.c&lt;BR /&gt;rwgreen$ ifort -m32 test15.f90 get_c_pointer.o&lt;BR /&gt;test15.f90(27): (col. 3) remark: LOOP WAS VECTORIZED.&lt;BR /&gt;mbp0017f2df31c3:~/quads/forums/30247174 rwgreen$ ./a.out&lt;BR /&gt; 0.000000000000000E+000 1.00000000000000 2.00000000000000 &lt;BR /&gt; 3.00000000000000 4.00000000000000 5.00000000000000 &lt;BR /&gt; 6.00000000000000 7.00000000000000 8.00000000000000 &lt;BR /&gt; 9.00000000000000 &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Try this on your linux box.&lt;BR /&gt;&lt;BR /&gt;and some cautions from our GNUish friends:&lt;BR /&gt;"-malign-double&lt;BR /&gt;-mno-align-double&lt;BR /&gt;Control whether GCC aligns double, long double, and long long variables on a two word boundary or a one word boundary. Aligning double variables on a two word boundary will produce code that runs somewhat faster on a `Pentium' at the expense of more memory.&lt;BR /&gt;On x86-64, -malign-double is enabled by default.&lt;BR /&gt;&lt;BR /&gt;Warning: if you use the -malign-double switch, structures containing the above types will be aligned differently than the published application binary interface specifications for the 386 and will not be binary compatible with structures in code compiled without that switch. "&lt;BR /&gt;&lt;BR /&gt;SO you will have to use that switch for ALL your source files. But hey, as a side benefit you will get a little performance increase (in theory).&lt;BR /&gt;&lt;BR /&gt;cheers&lt;BR /&gt;&lt;BR /&gt;ron&lt;BR /&gt;</description>
      <pubDate>Thu, 17 Jan 2008 19:44:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746608#M4404</guid>
      <dc:creator>Ron_Green</dc:creator>
      <dc:date>2008-01-17T19:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: pointer to derived type component</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746609#M4405</link>
      <description>Just so it's crystal clear, don't use -m32 on your Linux system. This is a Mac-ism.&lt;BR /&gt;</description>
      <pubDate>Thu, 17 Jan 2008 19:46:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746609#M4405</guid>
      <dc:creator>Ron_Green</dc:creator>
      <dc:date>2008-01-17T19:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: pointer to derived type component</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746610#M4406</link>
      <description>this is an important issue for me..but I can't even use the iso_c_binding module.  How do I link in the appropriate module?
&lt;BR /&gt;
&lt;BR /&gt;</description>
      <pubDate>Tue, 22 Jan 2008 20:10:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746610#M4406</guid>
      <dc:creator>srinath</dc:creator>
      <dc:date>2008-01-22T20:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: pointer to derived type component</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746611#M4407</link>
      <description>gcc and gfortran switch from 64-bit to 32-bit code by the -m32 switch. The equivalent switch with ifort is to set environment variables according to the scripts in /opt/intel/fce/bin (64-bit) or /opt/intel/fc/bin (32-bit, if both are installed).&lt;BR /&gt;iso_c_binding is invoked by the USE, in accordance with any textbook, or see e.g.&lt;BR /&gt;&lt;A href="http://www.fortran.bcs.org/2002/interop.htm" target="_blank"&gt;http://www.fortran.bcs.org/2002/interop.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 22 Jan 2008 21:09:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746611#M4407</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2008-01-22T21:09:12Z</dc:date>
    </item>
    <item>
      <title>Re: pointer to derived type component</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746612#M4408</link>
      <description>I should clarify.  I used the discussion's first example as an introduction to using c-bind.  I copied the above example, and on a mac w/ Leopard, using the 32-bit ifort, I saved the 2 portions of code in a fortran and c file.  ifort -c test1.f failed at compile time, even though I source the variables in the intel variable script.  The error is that the "use" statement :
&lt;BR /&gt;fortcom: Error: c_bindtest.f, line 4: Error in opening the compiled module file.  Check INCLUDE paths.   [ISO_C_BINDINGROGRAMTEST]
&lt;BR /&gt;      USE iso_c_binding
&lt;BR /&gt;
&lt;BR /&gt;I don't think I have to explicitly include the intel compiler include path, do I?</description>
      <pubDate>Wed, 23 Jan 2008 05:06:06 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746612#M4408</guid>
      <dc:creator>srinath</dc:creator>
      <dc:date>2008-01-23T05:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: pointer to derived type component</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746613#M4409</link>
      <description>Fixed.  I was using a *.f suffix, the correct one is *.f90.
&lt;BR /&gt;Sorry for the confusion.
&lt;BR /&gt;
&lt;BR /&gt;</description>
      <pubDate>Wed, 23 Jan 2008 06:22:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-derived-type-component/m-p/746613#M4409</guid>
      <dc:creator>srinath</dc:creator>
      <dc:date>2008-01-23T06:22:51Z</dc:date>
    </item>
  </channel>
</rss>

