# (j3.2006) (DE)ALLOCATE with STAT= question

Tobias Burnus burnus
Tue Dec 20 09:36:01 EST 2011

```Hello,

I am not sure whether I have completely understood the result of
(DE)ALLOCATE with stat.

Assume the following (with num_images() > 1):
integer, allocatable :: A[*], B, C
integer :: stat
allocate(B)
if (this_image() > 1) stop
ALLOCATE (A[*], B, C, stat=stat)

i.e. "C" can be allocated, "A" cannot as other images have initiated
termination of execution, and "B" is already allocated.

Which value does "stat" have at the end? Does the result depend on the
order of the allocate-object-list and if so, how?* And what's the
allocation status of A, B and C?

(* For DEALLOCATE one can find the following, I didn't spot something
regarding the order for ALLOCATE: [F2008, 6.7.3.1, para. 4] "When more
than one allocated object is deallocated by execution of a DEALLOCATE
statement, the order of deallocation is processor dependent.")

Similarly for:
integer, allocatable :: A[*], B, C
integer :: stat
allocate(C, A[*])
if (this_image() > 1) stop
DEALLOCATE (A[*], B, C, stat=stat)

What's the value of stat and the allocation status of A, B and C?

My understanding is that:
- For ALLOCATE, B remains allocated, C gets allocated and A remains
unallocated
- For DEALLOCATE, A remains allocated, C gets deallocated and B remains
unallocated
- The STAT= value is STAT_STOPPED_IMAGE in all cases, independent of the
order.

Is this the correct reading? Or can be the value for STAT= also different?

Tobias

From "6.7.4 STAT= specifier":

"If an ALLOCATE or DEALLOCATE statement with a coarray allocate-object
is executed when one or more images has initiated termination of
execution, the stat-variable becomes defined with the
processor-dependent positive integer value of the constant
STAT_STOPPED_IMAGE from the intrinsic module ISO_FORTRAN_ENV (13.8.2).
If any other error condition occurs during execution of the ALLOCATE or
DEALLOCATE statement, the stat-variable becomes defined with a
processor-dependent positive integer value different from
STAT_STOPPED_IMAGE. In either case, each allocate-object has a
processor-dependent status:

* each allocate-object that was successfully allocated shall have an
allocation status of allocated or a pointer association status of
associated;
* each allocate-object that was successfully deallocated shall have an
allocation status of unallocated or a pointer association status of
disassociated;
* each allocate-object that was not successfully allocated or
deallocated shall retain its previous allocation status or pointer
association status."

```