<?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 That last deallocate is in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/move-alloc-pointer-array-to-allocatable-array/m-p/996137#M102400</link>
    <description>&lt;P&gt;That last deallocate is indeed forbidden. That it seems to "work" is an accident, and it could corrupt memory. Don't do it. But you can now (in 16.0) do this:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include "ISO_Fortran_binding.h"
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;

extern "C" int alloc(CFI_cdesc_t * dv, int n) {
    CFI_index_t lower[1], upper[1];
    int i, ret;
    int* p;

    lower[0] = 1;
    upper[0] = n;

    ret = CFI_allocate(dv, lower, upper, 0);
    if (ret == CFI_SUCCESS) {
        printf("allocate int array size %d\n", n);
         p = (int *) dv-&amp;gt;base_addr;

        for (i = 0; i &amp;lt; n; i++){
            p&lt;I&gt; = i;
            printf("p %d = %d\n", i, p&lt;I&gt;);
        }
    }
    return ret;
}&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

&lt;PRE class="brush:fortran;"&gt;program foo
use iso_c_binding
 
integer(c_int) ,dimension(:),allocatable :: array 
integer(c_int) :: n, ret

interface
integer(c_int) function alloc(array,n) bind(c)
import
integer(c_int), dimension(:), allocatable :: array
integer(c_int), value :: n
end function
end interface

n=20

ret = alloc(array,n)
print *,array


deallocate(array)

end program foo&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Still can't make in polymorphic, though.&lt;/P&gt;</description>
    <pubDate>Tue, 25 Aug 2015 19:55:35 GMT</pubDate>
    <dc:creator>Steven_L_Intel1</dc:creator>
    <dc:date>2015-08-25T19:55:35Z</dc:date>
    <item>
      <title>move_alloc pointer array to allocatable array</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/move-alloc-pointer-array-to-allocatable-array/m-p/996134#M102397</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Is there a way to move the data from a pointer to an allocatable without doing a copy ?&lt;/P&gt;

&lt;P&gt;The data is allocated in C, but used and deallocated in fortran in a dimension(:),pointer, but then it needs to be attached to a class, but i dont see a way of moving the data to the allocatable without a copy.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;

&lt;P&gt;Pat.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2015 16:35:43 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/move-alloc-pointer-array-to-allocatable-array/m-p/996134#M102397</guid>
      <dc:creator>Patrice_l_</dc:creator>
      <dc:date>2015-08-25T16:35:43Z</dc:date>
    </item>
    <item>
      <title>No, you can't do this. And I</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/move-alloc-pointer-array-to-allocatable-array/m-p/996135#M102398</link>
      <description>&lt;P&gt;No, you can't do this. And I hope you aren't using Fortran DEALLOCATE to deallocate storage allocated in C. You can convert a C pointer to a Fortran pointer (which you aren't allowed to deallocate), but ALLOCATABLEs are in their own realm. Polymorphism is another barrier here - even with the new C descriptor support in 16.0, you can't make polymorphic objects interoperable with C.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2015 18:45:50 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/move-alloc-pointer-array-to-allocatable-array/m-p/996135#M102398</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2015-08-25T18:45:50Z</dc:date>
    </item>
    <item>
      <title>Just to have clear idea on</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/move-alloc-pointer-array-to-allocatable-array/m-p/996136#M102399</link>
      <description>&lt;P&gt;Just to have clear idea on what i am talking about here is a sample code below. I understand for a structure it is complicated but for a basic type , as long as i keep track of all my allocation and I am sure this pointer is not referenced anywhere else i should be ok ?&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
int* alloc(int n)
{
	int i;
	int *p=malloc(sizeof(int)*n);

	printf("allocate int array size %d\n",n);


	for (i=0;i&amp;lt;n;i++){
		p&lt;I&gt;=i; 
		printf("p %d = %d\n",i,p&lt;I&gt;);
	}
	return p;

}
&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

&lt;P&gt;and&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;program foo
use iso_c_binding
type(c_ptr) :: c_array
integer ,dimension(:),pointer ::fc_array 
integer ,dimension(:),allocatable :: array 
integer :: n

interface
type(c_ptr) function alloc(n) bind(c)
use iso_c_binding
integer(c_int),value :: n
end function
end interface

n=20

c_array=alloc(n)
call c_f_pointer(c_array,fc_array,(/n/))

print *,fc_array


!move fc_array storage to fc_array ??
allocate(array(n))
array=fc_array

deallocate(array)

! Forbidden ???? but working ?
deallocate(fc_array)

end program foo&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2015 19:28:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/move-alloc-pointer-array-to-allocatable-array/m-p/996136#M102399</guid>
      <dc:creator>Patrice_l_</dc:creator>
      <dc:date>2015-08-25T19:28:35Z</dc:date>
    </item>
    <item>
      <title>That last deallocate is</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/move-alloc-pointer-array-to-allocatable-array/m-p/996137#M102400</link>
      <description>&lt;P&gt;That last deallocate is indeed forbidden. That it seems to "work" is an accident, and it could corrupt memory. Don't do it. But you can now (in 16.0) do this:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include "ISO_Fortran_binding.h"
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;

extern "C" int alloc(CFI_cdesc_t * dv, int n) {
    CFI_index_t lower[1], upper[1];
    int i, ret;
    int* p;

    lower[0] = 1;
    upper[0] = n;

    ret = CFI_allocate(dv, lower, upper, 0);
    if (ret == CFI_SUCCESS) {
        printf("allocate int array size %d\n", n);
         p = (int *) dv-&amp;gt;base_addr;

        for (i = 0; i &amp;lt; n; i++){
            p&lt;I&gt; = i;
            printf("p %d = %d\n", i, p&lt;I&gt;);
        }
    }
    return ret;
}&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

&lt;PRE class="brush:fortran;"&gt;program foo
use iso_c_binding
 
integer(c_int) ,dimension(:),allocatable :: array 
integer(c_int) :: n, ret

interface
integer(c_int) function alloc(array,n) bind(c)
import
integer(c_int), dimension(:), allocatable :: array
integer(c_int), value :: n
end function
end interface

n=20

ret = alloc(array,n)
print *,array


deallocate(array)

end program foo&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Still can't make in polymorphic, though.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2015 19:55:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/move-alloc-pointer-array-to-allocatable-array/m-p/996137#M102400</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2015-08-25T19:55:35Z</dc:date>
    </item>
    <item>
      <title>I am not worry about</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/move-alloc-pointer-array-to-allocatable-array/m-p/996138#M102401</link>
      <description>&lt;P&gt;I am not worry about polymorphic at all, and since the library design in C does not depend on me, all i&amp;nbsp; have is a C wrapper and i could&amp;nbsp; use it to assign the base_addr ,CFI_ssetpointer ?&lt;/P&gt;

&lt;P&gt;I will do some more test and get familiar with the new CFI functions.&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2015 20:14:27 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/move-alloc-pointer-array-to-allocatable-array/m-p/996138#M102401</guid>
      <dc:creator>Patrice_l_</dc:creator>
      <dc:date>2015-08-25T20:14:27Z</dc:date>
    </item>
    <item>
      <title>The way you'd have to do this</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/move-alloc-pointer-array-to-allocatable-array/m-p/996139#M102402</link>
      <description>&lt;P&gt;The way you'd have to do this with CFI_setpointer is to create a separate C descriptor with CFI_establish, that points to malloced storage, and then use CFI_setpointer to do the pointer assign. It would then be not allowed to deallocate it in Fortran nor could you make this an allocatable.&lt;/P&gt;

&lt;P&gt;You aren't allowed to modify the base_addr component yourself.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2015 20:53:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/move-alloc-pointer-array-to-allocatable-array/m-p/996139#M102402</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2015-08-25T20:53:40Z</dc:date>
    </item>
  </channel>
</rss>

