# Error: Function result ‘res’ at (1) shall not be a coarray or have a coarray component

**URL:** <https://fortran-lang.discourse.group/t/error-function-result-res-at-1-shall-not-be-a-coarray-or-have-a-coarray-component/3566>\
**Category:** Help\
**Created:** [May 27, 2022, 8:22am UTC](https://fortran-lang.discourse.group/t/error-function-result-res-at-1-shall-not-be-a-coarray-or-have-a-coarray-component/3566 "2022-05-27T08:22:22Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![sverdrup](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@sverdrup](https://fortran-lang.discourse.group/u/sverdrup)\
**Post date:** [May 27, 2022, 8:22am UTC](https://fortran-lang.discourse.group/t/error-function-result-res-at-1-shall-not-be-a-coarray-or-have-a-coarray-component/3566/1 "2022-05-27T08:22:22Z")

</div>

Hi all,  
I need help, I’ve a code and it run perfectly on a cluster compiled with ifort. Now I move the code on a PC with gfortran and caf compiler, but I’ve the error in the title…

```auto
  230 | type(Sbathy) function bat_constructor(fcu,dname,ig) result(res)
      | 1
Error: Function result ‘res’ at (1) shall not be a coarray or have a coarray component
bathy.f90:4:5:

```

If i comment the function, both the compiler work great!  
Where is the problem??  
Thanks

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [May 27, 2022, 9:51am UTC](https://fortran-lang.discourse.group/t/error-function-result-res-at-1-shall-not-be-a-coarray-or-have-a-coarray-component/3566/2 "2022-05-27T09:51:34Z")

</div>

@sverdrup, welcome to the forum! Your question is clear enough, but to really answer it, we will need to see the code, especially the definition of the derived type Sbathy.

---

<div class="post-metadata">

**Author:** ![sverdrup](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@sverdrup](https://fortran-lang.discourse.group/u/sverdrup)\
**Post date:** [May 27, 2022, 9:56am UTC](https://fortran-lang.discourse.group/t/error-function-result-res-at-1-shall-not-be-a-coarray-or-have-a-coarray-component/3566/3 "2022-05-27T09:56:36Z")

</div>

Thank you Arjen,

```auto
type Sbathy
type(Gridinfo) :: gemo, gmed
type(Halo)::halo
contains
procedure, pass(self) :: get_inner
procedure,pass(self) :: halo_ex 
procedure, pass(self) :: find_neighbor
procedure, pass(self) ::init
end type Sbathy

```

and here I’ve the problem:

```auto
type(Sbathy) function bat_constructor(fcu,dname,ig) result(res)
character(len=*), intent(in)::dname,fcu
integer, intent (in) ::ig
type(Gridinfo) :: gem, gme
integer ::status, i,j

gem=Gridinfo(dname,ig)
gme=Gridinfo(fcu,0)
res%gemo=gem
res%gmed=gme
call res%halo_ex()
sync all
!print *,'exit from halo'
call res%init()
!%res%gmed=gme

end function bat_constructor

```

If I comment the function and the call in the main, the compilation (gfortran) terminate without errors.  
The strange thing is if I compile the same code with ifortran compiler on the cluster i don’t have the error.

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [May 27, 2022, 10:50am UTC](https://fortran-lang.discourse.group/t/error-function-result-res-at-1-shall-not-be-a-coarray-or-have-a-coarray-component/3566/4 "2022-05-27T10:50:54Z")

</div>

So, it might be the “sync all” statement that is causing this. The compiler erroneously interprets this as a coarray component in the result. Just a hunch, but could you instead turn the function into a subroutine that sets argument res? Maybe that way the compiler is no longer confused.

---

<div class="post-metadata">

**Author:** ![sverdrup](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@sverdrup](https://fortran-lang.discourse.group/u/sverdrup)\
**Post date:** [May 27, 2022, 11:12am UTC](https://fortran-lang.discourse.group/t/error-function-result-res-at-1-shall-not-be-a-coarray-or-have-a-coarray-component/3566/5 "2022-05-27T11:12:13Z")

</div>

Yes I can try, but if I simply comment the “sync all” I obtain the same error…

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [May 27, 2022, 12:39pm UTC](https://fortran-lang.discourse.group/t/error-function-result-res-at-1-shall-not-be-a-coarray-or-have-a-coarray-component/3566/6 "2022-05-27T12:39:17Z")

</div>

Any coarray components in one of the other derived types that you use in type(Sbathy)?

---

<div class="post-metadata">

**Author:** ![sverdrup](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@sverdrup](https://fortran-lang.discourse.group/u/sverdrup)\
**Post date:** [May 27, 2022, 12:45pm UTC](https://fortran-lang.discourse.group/t/error-function-result-res-at-1-shall-not-be-a-coarray-or-have-a-coarray-component/3566/7 "2022-05-27T12:45:58Z")

</div>

Yes in the init and halo\_ex subrutine.

---

<div class="post-metadata">

**Author:** ![sverdrup](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@sverdrup](https://fortran-lang.discourse.group/u/sverdrup)\
**Post date:** [May 30, 2022, 2:25pm UTC](https://fortran-lang.discourse.group/t/error-function-result-res-at-1-shall-not-be-a-coarray-or-have-a-coarray-component/3566/8 "2022-05-30T14:25:11Z")

</div>

Ok I’ve triied to reconfigure all the system, I’ve used ubuntu 18.04 docker with libnetcdf, opencoarray and all other the stuff… But the problem remane the same, when I try to compile the code I’ve this result:

```auto
root@c977ddc8aae3:/home/data# caf mod_bathy_field.f90 bathy.f90 `nf-config --fflags --flibs` -o pippon
mod_bathy_field.f90:230:63:

 type(Sbathy) function bat_constructor(fcu,dname,ig) result(res)
                                                               1
Error: Function result 'res' at (1) shall not be a coarray or have a coarray component
bathy.f90:4:4:

 use mod_bathy_field
    1
Fatal Error: Can't open module file 'mod_bathy_field.mod' for reading at (1): No such file or directory
compilation terminated.
Error: comand:
   `/usr/bin/mpifort -I/usr/include/OpenCoarrays-2.0.0-rc1_GNU-7.3.0 -fcoarray=lib mod_bathy_field.f90 bathy.f90 -I/usr/include -L/usr/lib -lnetcdff -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -lnetcdf -lnetcdf -o pippon /usr/lib/x86_64-linux-gnu/libcaf_mpi.a`
failed to compile.

```

any idea?  
thanks in advance.

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [May 30, 2022, 7:08pm UTC](https://fortran-lang.discourse.group/t/error-function-result-res-at-1-shall-not-be-a-coarray-or-have-a-coarray-component/3566/9 "2022-05-30T19:08:43Z")

</div>

Hm, do you have a small(ish) reproducer? So far we have only parts of the program and that makes us guess as to what is going on. It would greatly help if you can provide a complete program of very moderate size 🙂 that we can try to compile ourselves.

---

<div class="post-metadata">

**Author:** ![sverdrup](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@sverdrup](https://fortran-lang.discourse.group/u/sverdrup)\
**Post date:** [May 31, 2022, 6:48am UTC](https://fortran-lang.discourse.group/t/error-function-result-res-at-1-shall-not-be-a-coarray-or-have-a-coarray-component/3566/10 "2022-05-31T06:48:24Z")

</div>

Hi Arjen, thanks for your help.  
Here the code, I hope can help to solve this problem.

[bathy.f90](https://fortran-lang.discourse.group/uploads/short-url/lUvfDsAYxS8SNSP6wMh7NBTCNKh.f90) (1.8 KB)  
[mod\_bathy\_field.f90](https://fortran-lang.discourse.group/uploads/short-url/i8WkeldHgBUDLGzcUxDwRpAgrd1.f90) (10.8 KB)

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [May 31, 2022, 1:53pm UTC](https://fortran-lang.discourse.group/t/error-function-result-res-at-1-shall-not-be-a-coarray-or-have-a-coarray-component/3566/11 "2022-05-31T13:53:36Z")

</div>

I used these source files for some experimentation. When I changed the function to a subroutine and added an intent(out) to the new “res” argument, both Intel Fortran and gfortran complained. Something along these lines:

```auto
 error #8391: An entity with the INTENT(OUT) attribute must not be an allocatable coarray or have a subobject that is an allocatable coarray. [RES]

```

which does make sense in a way, as coarrays require synchronisation. Not sure how to solve this problem.

---

<div class="post-metadata">

**Author:** ![sverdrup](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@sverdrup](https://fortran-lang.discourse.group/u/sverdrup)\
**Post date:** [May 31, 2022, 3:24pm UTC](https://fortran-lang.discourse.group/t/error-function-result-res-at-1-shall-not-be-a-coarray-or-have-a-coarray-component/3566/12 "2022-05-31T15:24:10Z")

</div>

Thank you Arjen for your help, I have the same result with a simil modification of the code… I’m working on it.

---

<div class="post-metadata">

**Author:** ![sverdrup](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@sverdrup](https://fortran-lang.discourse.group/u/sverdrup)\
**Post date:** [June 15, 2022, 2:00pm UTC](https://fortran-lang.discourse.group/t/error-function-result-res-at-1-shall-not-be-a-coarray-or-have-a-coarray-component/3566/13 "2022-06-15T14:00:39Z")

</div>

Ok, I managed to compile the code using the oneAPI Intel compiler, but now when I run the code I’ve the follow error:

```auto
===================================================================================
= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
= RANK 0 PID 117 RUNNING AT 686bff36a2cc
= KILLED BY SIGNAL: 11 (Segmentation fault)
===================================================================================

===================================================================================
= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
= RANK 1 PID 118 RUNNING AT 686bff36a2cc
= KILLED BY SIGNAL: 11 (Segmentation fault)
===================================================================================

===================================================================================
= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
= RANK 2 PID 119 RUNNING AT 686bff36a2cc
= KILLED BY SIGNAL: 11 (Segmentation fault)
===================================================================================

```

Does anyone have any idea regarding the meaning of the error?  
thank’s in advance

---

<div class="post-metadata">

**Author:** ![wclodius](https://avatars.discourse-cdn.com/v4/letter/w/87869e/32.png) [@wclodius](https://fortran-lang.discourse.group/u/wclodius)\
**Post date:** [June 15, 2022, 3:24pm UTC](https://fortran-lang.discourse.group/t/error-function-result-res-at-1-shall-not-be-a-coarray-or-have-a-coarray-component/3566/14 "2022-06-15T15:24:39Z")

</div>

Segmentation fault indicates an illegal memory access. One cause of that is accessing an out of bounds array element. Check that any allocatable arrays or pointers are properly allocated. Also check that you don’t access elements less than the lower bound (typically 1), or greater than the upper bound. Another cause is exceeding the stack size. Most systems come with a default maximum stack size that can be reset using a shell command often to an unlimited value. Mac OSX has a maximum maximum stack size of 64 Mb. Check also that you do not have an infinite recursion in your code that will result in you always exceeding the maximum stack size. I haven’t used co-arrays and using them may provide another way of illegally accessing a memory location.

---

<div class="post-metadata">

**Author:** ![sverdrup](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@sverdrup](https://fortran-lang.discourse.group/u/sverdrup)\
**Post date:** [June 15, 2022, 3:54pm UTC](https://fortran-lang.discourse.group/t/error-function-result-res-at-1-shall-not-be-a-coarray-or-have-a-coarray-component/3566/15 "2022-06-15T15:54:20Z")

</div>

Thank you wclodius, the problem is the code run perfectly on mac with oneapi intel compiler with netcdf, running on 6 core. I think my problem is due to my work environment, I’ve compile zlib, hdf5, netcdf-c and netcdf-fortran with oneapi c and fortran compiler, but I have the same error with different code running in parallel with coarray.
