|
| 1 | +! BSD 3-Clause License |
| 2 | +! |
| 3 | +! Copyright (c) 2016, Sourcery Institute |
| 4 | +! All rights reserved. |
| 5 | +! |
| 6 | +! Redistribution and use in source and binary forms, with or without |
| 7 | +! modification, are permitted provided that the following conditions are met: |
| 8 | +! |
| 9 | +! * Redistributions of source code must retain the above copyright notice, this |
| 10 | +! list of conditions and the following disclaimer. |
| 11 | +! |
| 12 | +! * Redistributions in binary form must reproduce the above copyright notice, |
| 13 | +! this list of conditions and the following disclaimer in the documentation |
| 14 | +! and/or other materials provided with the distribution. |
| 15 | +! |
| 16 | +! * Neither the name of the copyright holder nor the names of its |
| 17 | +! contributors may be used to endorse or promote products derived from |
| 18 | +! this software without specific prior written permission. |
| 19 | +! |
| 20 | +! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 21 | +! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 | +! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 23 | +! DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 24 | +! FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 25 | +! DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 26 | +! SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 27 | +! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 28 | +! OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | +! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | + |
| 31 | +program main |
| 32 | + !! author: Damian Rouson |
| 33 | + !! date: 2017-08-01 |
| 34 | + !! category: regression |
| 35 | + !! Test whether assigning an allocatable coarray component to an allocatable |
| 36 | + !! coarray component works. |
| 37 | + !! OpenCoarrays issue #422 |
| 38 | + use iso_fortran_env, only : error_unit |
| 39 | + implicit none |
| 40 | + |
| 41 | + type foo |
| 42 | + !! A derived type is required to demonstrate issue #422 |
| 43 | + integer, allocatable :: bar(:)[:] |
| 44 | + end type |
| 45 | + type(foo) :: foobar |
| 46 | + |
| 47 | + enum, bind(C) |
| 48 | + enumerator :: recipient=1, provider, getter_putter |
| 49 | + end enum |
| 50 | + |
| 51 | + integer, parameter :: bar_size=2 |
| 52 | + |
| 53 | + associate( me=>this_image(), N_images=>num_images(), required_images=>maxval([recipient,provider,getter_putter]) ) |
| 54 | + |
| 55 | + verify_num_images: if (N_images<required_images) then |
| 56 | + write(error_unit,*) "issue-422-send-get.f90 requires at least ",required_images," images" |
| 57 | + error stop |
| 58 | + end if verify_num_images |
| 59 | + |
| 60 | + allocate(foobar%bar(bar_size)[*],source=me) |
| 61 | + !! Assign each image's identifier to each element of foobar%bar |
| 62 | + |
| 63 | + get_put_component: if (me==getter_putter) then |
| 64 | + foobar%bar(:)[recipient] = foobar%bar(:)[provider] |
| 65 | + !! Get bar from provider image and put bar on recipient image |
| 66 | + sync images(recipient) |
| 67 | + !! Signal recipient that get and put have completed |
| 68 | + end if get_put_component |
| 69 | + |
| 70 | + wait_and_verify: if (me==recipient) then |
| 71 | + sync images(getter_putter) |
| 72 | + !! Wait for signal from getter-putter |
| 73 | + |
| 74 | + verify_result: if (any(foobar%bar/=provider)) then |
| 75 | + write(error_unit,*) "Recipient image ",recipient," received ",foobar%bar," but expected ",provider |
| 76 | + error stop |
| 77 | + end if verify_result |
| 78 | + |
| 79 | + print *,"Test passed." |
| 80 | + !! Report success |
| 81 | + |
| 82 | + end if wait_and_verify |
| 83 | + |
| 84 | + end associate |
| 85 | + |
| 86 | +end program |
0 commit comments