<?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 aligned_alloc and ifort/icc v17 in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/aligned-alloc-and-ifort-icc-v17/m-p/1143489#M137865</link>
    <description>&lt;P&gt;I have a code that wraps aligned_alloc C function using iso_c_binding in a module. This code, when compiled with gfortran v4.8 and newer, has no issues. However, compiling it with ifort (v17.0.1) produces linkage problems such as: testalign.f90:(.text+0x40): undefined reference to `aligned_alloc' .&lt;/P&gt;&lt;P&gt;As I understand it, aligned_alloc is part of c11 standard so there may be a switch that takes care of this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, the question is how to compile the code below with ifort v17?&lt;/P&gt;&lt;P&gt;If this is not possible, is there an Intel Fortran version that supports something like this? Of course, if aligned_alloc is not supported, then I will need to detect a compiler using some ugly preprocessor code and replace aligned_alloc with allocate.&lt;/P&gt;&lt;P&gt;Here's the (almost) minimal example:&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;module align                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                               
implicit none                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                               
public !Default access for the module is public .                                                                                                                                                                                              
    interface                                                                                                                                                                                                                                  
        function aligned_alloc(alg, sz) bind(c)                                                                                                                                                                                                
            use, intrinsic :: iso_c_binding                                                                                                                                                                                                    
                                                                                                                                                                                                                                               
            implicit none                                                                                                                                                                                                                      
            integer(kind=c_size_t), intent(in), value :: alg                                                                                                                                                                                   
            integer(kind=c_size_t), intent(in), value :: sz                                                                                                                                                                                    
                                                                                                                                                                                                                                               
            type(c_ptr) :: aligned_alloc                                                                                                                                                                                                       
                                                                                                                                                                                                                                               
        end function  aligned_alloc                                                                                                                                                                                                            
                                                                                                                                                                                                                                               
    end interface                                                                                                                                                                                                                              
                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                               
contains                                                                                                                                                                                                                                       
    subroutine res_align(p, n, alg)                                                                                                                                                                                                            
	use, intrinsic :: iso_c_binding                                                                                                                                                                                                        
                                                                                                                                                                                                                                               
        implicit none                                                                                                                                                                                                                          
        real(kind=c_double), intent(out), pointer, contiguous :: p(:)                                                                                                                                                                          
        integer, intent(in) :: n                                                                                                                                                                                                               
        integer, intent(in) :: alg                                                                                                                                                                                                             
                                                                                                                                                                                                                                               
        integer(kind=c_size_t) :: aalg                                                                                                                                                                                                         
        integer :: bytesz                                                                                                                                                                                                                      
        integer(kind=c_size_t) :: bbytesz                                                                                                                                                                                                      
        type(c_ptr) :: ptr                                                                                                                                                                                                                     
        bytesz=n*storage_size(p)/8                                                                                                                                                                                                             
        aalg=int(alg,kind=kind(aalg))                                                                                                                                                                                                          
        bbytesz=int(bytesz,kind=kind(bbytesz))                                                                                                                                                                                                 
        ptr=aligned_alloc(aalg,bbytesz)                                                                                                                                                                                                        
        if (.not. c_associated(ptr)) stop 'error(res_align): unsuccessful allocation'                                                                                                                                                          
        call c_f_pointer(ptr,p,&lt;N&gt;)                                                                                                                                                                                                            
                                                                                                                                                                                                                                               
    end subroutine  res_align                                                                                                                                                                                                                  
end module  align                                                                                                                                                                                                                              
                                                                                                                                                                                                                                               
program test                                                                                                                                                                                                                                   
  use, intrinsic :: iso_c_binding                                                                                                                                                                                                              
  use align                                                                                                                                                                                                                                    
  implicit none                                                                                                                                                                                                                                
  real(kind=c_double), pointer, contiguous :: parr(:)                                                                                                                                                                                          
  integer, parameter :: alg=64                                                                                                                                                                                                                 
  integer, parameter :: sz=399                                                                                                                                                                                                                 
                                                                                                                                                                                                                                               
  call res_align(parr,sz,alg)                                                                                                                                                                                                                  
                                                                                                                                                                                                                                               
  parr=77.                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                               
end program test                   &lt;/N&gt;&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Jan 2019 13:26:52 GMT</pubDate>
    <dc:creator>Todor_K_</dc:creator>
    <dc:date>2019-01-30T13:26:52Z</dc:date>
    <item>
      <title>aligned_alloc and ifort/icc v17</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/aligned-alloc-and-ifort-icc-v17/m-p/1143489#M137865</link>
      <description>&lt;P&gt;I have a code that wraps aligned_alloc C function using iso_c_binding in a module. This code, when compiled with gfortran v4.8 and newer, has no issues. However, compiling it with ifort (v17.0.1) produces linkage problems such as: testalign.f90:(.text+0x40): undefined reference to `aligned_alloc' .&lt;/P&gt;&lt;P&gt;As I understand it, aligned_alloc is part of c11 standard so there may be a switch that takes care of this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, the question is how to compile the code below with ifort v17?&lt;/P&gt;&lt;P&gt;If this is not possible, is there an Intel Fortran version that supports something like this? Of course, if aligned_alloc is not supported, then I will need to detect a compiler using some ugly preprocessor code and replace aligned_alloc with allocate.&lt;/P&gt;&lt;P&gt;Here's the (almost) minimal example:&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;module align                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                               
implicit none                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                               
public !Default access for the module is public .                                                                                                                                                                                              
    interface                                                                                                                                                                                                                                  
        function aligned_alloc(alg, sz) bind(c)                                                                                                                                                                                                
            use, intrinsic :: iso_c_binding                                                                                                                                                                                                    
                                                                                                                                                                                                                                               
            implicit none                                                                                                                                                                                                                      
            integer(kind=c_size_t), intent(in), value :: alg                                                                                                                                                                                   
            integer(kind=c_size_t), intent(in), value :: sz                                                                                                                                                                                    
                                                                                                                                                                                                                                               
            type(c_ptr) :: aligned_alloc                                                                                                                                                                                                       
                                                                                                                                                                                                                                               
        end function  aligned_alloc                                                                                                                                                                                                            
                                                                                                                                                                                                                                               
    end interface                                                                                                                                                                                                                              
                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                               
contains                                                                                                                                                                                                                                       
    subroutine res_align(p, n, alg)                                                                                                                                                                                                            
	use, intrinsic :: iso_c_binding                                                                                                                                                                                                        
                                                                                                                                                                                                                                               
        implicit none                                                                                                                                                                                                                          
        real(kind=c_double), intent(out), pointer, contiguous :: p(:)                                                                                                                                                                          
        integer, intent(in) :: n                                                                                                                                                                                                               
        integer, intent(in) :: alg                                                                                                                                                                                                             
                                                                                                                                                                                                                                               
        integer(kind=c_size_t) :: aalg                                                                                                                                                                                                         
        integer :: bytesz                                                                                                                                                                                                                      
        integer(kind=c_size_t) :: bbytesz                                                                                                                                                                                                      
        type(c_ptr) :: ptr                                                                                                                                                                                                                     
        bytesz=n*storage_size(p)/8                                                                                                                                                                                                             
        aalg=int(alg,kind=kind(aalg))                                                                                                                                                                                                          
        bbytesz=int(bytesz,kind=kind(bbytesz))                                                                                                                                                                                                 
        ptr=aligned_alloc(aalg,bbytesz)                                                                                                                                                                                                        
        if (.not. c_associated(ptr)) stop 'error(res_align): unsuccessful allocation'                                                                                                                                                          
        call c_f_pointer(ptr,p,&lt;N&gt;)                                                                                                                                                                                                            
                                                                                                                                                                                                                                               
    end subroutine  res_align                                                                                                                                                                                                                  
end module  align                                                                                                                                                                                                                              
                                                                                                                                                                                                                                               
program test                                                                                                                                                                                                                                   
  use, intrinsic :: iso_c_binding                                                                                                                                                                                                              
  use align                                                                                                                                                                                                                                    
  implicit none                                                                                                                                                                                                                                
  real(kind=c_double), pointer, contiguous :: parr(:)                                                                                                                                                                                          
  integer, parameter :: alg=64                                                                                                                                                                                                                 
  integer, parameter :: sz=399                                                                                                                                                                                                                 
                                                                                                                                                                                                                                               
  call res_align(parr,sz,alg)                                                                                                                                                                                                                  
                                                                                                                                                                                                                                               
  parr=77.                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                               
end program test                   &lt;/N&gt;&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 13:26:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/aligned-alloc-and-ifort-icc-v17/m-p/1143489#M137865</guid>
      <dc:creator>Todor_K_</dc:creator>
      <dc:date>2019-01-30T13:26:52Z</dc:date>
    </item>
    <item>
      <title>It's possible that the Intel</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/aligned-alloc-and-ifort-icc-v17/m-p/1143490#M137866</link>
      <description>&lt;P&gt;How do you know you're even linking to a library containing this procedure?&lt;/P&gt;&lt;P&gt;Intel Fortran supports !DEC$ ATTRIBUTES ALIGN on ALLOCATABLE variables.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 15:04:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/aligned-alloc-and-ifort-icc-v17/m-p/1143490#M137866</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2019-01-30T15:04:00Z</dc:date>
    </item>
    <item>
      <title>Good question. I don't. I</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/aligned-alloc-and-ifort-icc-v17/m-p/1143491#M137867</link>
      <description>&lt;P&gt;Good question. I don't. I only know that, for gfortran, the function exists in whatever gfortran(gcc) links in automatically (libc, i guess). I don't know where to look in case of intel fortran/c.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 15:40:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/aligned-alloc-and-ifort-icc-v17/m-p/1143491#M137867</guid>
      <dc:creator>Todor_K_</dc:creator>
      <dc:date>2019-01-30T15:40:57Z</dc:date>
    </item>
    <item>
      <title>As far as the Intel compiler</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/aligned-alloc-and-ifort-icc-v17/m-p/1143492#M137868</link>
      <description>&lt;P&gt;As far as the Intel compiler's alignment control directives, I am aware of that. However they are compiler specific, so this is a plan B.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 15:42:27 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/aligned-alloc-and-ifort-icc-v17/m-p/1143492#M137868</guid>
      <dc:creator>Todor_K_</dc:creator>
      <dc:date>2019-01-30T15:42:27Z</dc:date>
    </item>
    <item>
      <title>I suggest that you write a</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/aligned-alloc-and-ifort-icc-v17/m-p/1143493#M137869</link>
      <description>&lt;P&gt;I suggest that you write a simple C program that references aligned_malloc, build it (using gcc) with a link map, and see where the reference is pulled from.&amp;nbsp; ifort uses the gcc libraries, so you may just need to add one that isn't referenced by default.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 16:16:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/aligned-alloc-and-ifort-icc-v17/m-p/1143493#M137869</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2019-01-30T16:16:02Z</dc:date>
    </item>
    <item>
      <title>For the record, it turned out</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/aligned-alloc-and-ifort-icc-v17/m-p/1143494#M137870</link>
      <description>&lt;P&gt;For the record, it turned out that on our cluster we have an ancient version of glibc (2010) installed together with the newest Intel compilers. This did not have aligned_alloc.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 09:25:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/aligned-alloc-and-ifort-icc-v17/m-p/1143494#M137870</guid>
      <dc:creator>Todor_K_</dc:creator>
      <dc:date>2019-02-04T09:25:12Z</dc:date>
    </item>
  </channel>
</rss>

