|
| 1 | +! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 2 | +! DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 3 | +! FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 4 | +! DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 5 | +! SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 6 | +! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 7 | +! OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 8 | +! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 9 | + |
| 10 | +! Comments preceded by "!!" are formatted for the FORD docoumentation generator |
| 11 | +program alloc_comp_multidim_shape |
| 12 | + !! summary: Test shape of multidimensional allocatable array coarray components of a derived type shape(object%comp(:,:)[1]) |
| 13 | + !! author: Damian Rouson , 2018 |
| 14 | + !! date: 2018-03-08 |
| 15 | + !! |
| 16 | + !! [OpenCoarrays issue #511](https://github.com/sourceryinstitute/opencoarrays/issues/511) |
| 17 | + |
| 18 | + implicit none |
| 19 | + |
| 20 | +! TODO: add tests for other types and kinds, including integer, logical, character, and derived types |
| 21 | + |
| 22 | + type reals |
| 23 | + real, allocatable :: array_2D(:,:)[*] |
| 24 | + real, allocatable :: array_3D(:,:,:)[*] |
| 25 | + real, allocatable :: array_4D(:,:,:,:)[*] |
| 26 | + real, allocatable :: array_5D(:,:,:,:,:)[*] |
| 27 | + real, allocatable :: array_6D(:,:,:,:,:,:)[*] |
| 28 | +#ifdef GCC_GE_8 |
| 29 | + real, allocatable :: array_7D(:,:,:,:,:,:,:)[*] |
| 30 | + real, allocatable :: array_8D(:,:,:,:,:,:,:,:)[*] |
| 31 | + real, allocatable :: array_9D(:,:,:,:,:,:,:,:,:)[*] |
| 32 | + real, allocatable :: array_10D (:,:,:,:,:,:,:,:,:,:)[*] |
| 33 | + real, allocatable :: array_11D(:,:,:,:,:,:,:,:,:,:,:)[*] |
| 34 | + real, allocatable :: array_12D(:,:,:,:,:,:,:,:,:,:,:,:)[*] |
| 35 | + real, allocatable :: array_13D(:,:,:,:,:,:,:,:,:,:,:,:,:)[*] |
| 36 | + real, allocatable :: array_14D(:,:,:,:,:,:,:,:,:,:,:,:,:,:)[*] |
| 37 | + real, allocatable :: array_15D(:,:,:,:,:,:,:,:,:,:,:,:,:,:,:)[*] |
| 38 | +#endif |
| 39 | + end type |
| 40 | + |
| 41 | + type(reals), save :: object |
| 42 | + |
| 43 | + logical :: error_printed=.false. |
| 44 | + |
| 45 | + associate(me => this_image(), np => num_images()) |
| 46 | + |
| 47 | + allocate(object%array_2D(2,1)[*]) |
| 48 | + if ( any( shape(object%array_2D) /= shape(object%array_2D(:,:)[1]) ) ) & |
| 49 | + call print_and_register('incorrect shape for coindexed 2D array component of derived type') |
| 50 | + |
| 51 | + allocate(object%array_3D(3,2,1)[*]) |
| 52 | + if ( any( shape(object%array_3D) /= shape(object%array_3D(:,:,:)[1]) ) ) & |
| 53 | + call print_and_register('incorrect shape for coindexed 3D array component of derived type') |
| 54 | + |
| 55 | + allocate(object%array_4D(4,3,2,1)[*]) |
| 56 | + if ( any( shape(object%array_4D) /= shape(object%array_4D(:,:,:,:)[1]) ) ) & |
| 57 | + call print_and_register('incorrect shape for coindexed 4D array component of derived type') |
| 58 | + |
| 59 | + allocate(object%array_5D(5,4,3,2,1)[*]) |
| 60 | + if ( any( shape(object%array_5D) /= shape(object%array_5D(:,:,:,:,:)[1]) ) ) & |
| 61 | + call print_and_register('incorrect shape for coindexed 5D array component of derived type') |
| 62 | + |
| 63 | + allocate(object%array_6D(6,5,4,3,2,1)[*]) |
| 64 | + if ( any( shape(object%array_6D) /= shape(object%array_6D(:,:,:,:,:,:)[1]) ) ) & |
| 65 | + call print_and_register('incorrect shape for coindexed 6D array component of derived type') |
| 66 | + |
| 67 | +#ifdef GCC_GE_8 |
| 68 | + allocate(object%array_7D(7,6,5,4,3,2,1)[*]) |
| 69 | + if ( any( shape(object%array_7D) /= shape(object%array_7D(:,:,:,:,:,:,:)[1]) ) ) & |
| 70 | + call print_and_register('incorrect shape for coindexed 7D array component of derived type') |
| 71 | + |
| 72 | + allocate(object%array_8D(6,7,6,5,4,3,2,1)[*]) |
| 73 | + if ( any( shape(object%array_8D) /= shape(object%array_8D(:,:,:,:,:,:,:)[1]) ) ) & |
| 74 | + call print_and_register('incorrect shape for coindexed 8D array component of derived type') |
| 75 | + |
| 76 | + allocate(object%array_9D(5,6,7,6,5,4,3,2,1)[*]) |
| 77 | + if ( any( shape(object%array_9D) /= shape(object%array_9D(:,:,:,:,:,:,:,:)[1]) ) ) & |
| 78 | + call print_and_register('incorrect shape for coindexed 9D array component of derived type') |
| 79 | + |
| 80 | + allocate(object%array_10D(4,5,6,7,6,5,4,3,2,1)[*]) |
| 81 | + if ( any( shape(object%array_10D) /= shape(object%array_10D(:,:,:,:,:,:,:,:,:)[1]) ) ) & |
| 82 | + call print_and_register('incorrect shape for coindexed 10D array component of derived type') |
| 83 | + |
| 84 | + allocate(object%array_11D(3,4,5,6,7,6,5,4,3,2,1)[*]) |
| 85 | + if ( any( shape(object%array_11D) /= shape(object%array_11D(:,:,:,:,:,:,:,:,:,:)[1]) ) ) & |
| 86 | + call print_and_register('incorrect shape for coindexed 11D array component of derived type') |
| 87 | + |
| 88 | + allocate(object%array_12D(2,3,4,5,6,7,6,5,4,3,2,1)[*]) |
| 89 | + if ( any( shape(object%array_12D) /= shape(object%array_12D(:,:,:,:,:,:,:,:,:,:,:)[1]) ) ) & |
| 90 | + call print_and_register('incorrect shape for coindexed 12D array component of derived type') |
| 91 | + |
| 92 | + allocate(object%array_13D(1,2,3,4,5,6,7,6,5,4,3,2,1)[*]) |
| 93 | + if ( any( shape(object%array_13D) /= shape(object%array_13D(:,:,:,:,:,:,:,:,:,:,:,:)[1]) ) ) & |
| 94 | + call print_and_register('incorrect shape for coindexed 13D array component of derived type') |
| 95 | + |
| 96 | + allocate(object%array_14D(2,3,4,5,6,7,8,7,6,5,4,3,2,1)[*]) |
| 97 | + if ( any( shape(object%array_14D) /= shape(object%array_14D(:,:,:,:,:,:,:,:,:,:,:,:,:)[1]) ) ) & |
| 98 | + call print_and_register('incorrect shape for coindexed 14D array component of derived type') |
| 99 | + |
| 100 | +#endif |
| 101 | + |
| 102 | + check_global_success: block |
| 103 | + |
| 104 | + logical :: no_error_printed |
| 105 | + |
| 106 | + no_error_printed = .not. error_printed |
| 107 | + call co_all(no_error_printed,result_image=1) |
| 108 | + |
| 109 | + if (me==1 .and. no_error_printed) print *,"Test passed." |
| 110 | + |
| 111 | + end block check_global_success |
| 112 | + |
| 113 | + end associate |
| 114 | + |
| 115 | +contains |
| 116 | + |
| 117 | + subroutine print_and_register(error_message) |
| 118 | + use iso_fortran_env, only : error_unit |
| 119 | + character(len=*), intent(in) :: error_message |
| 120 | + write(error_unit,*) error_message |
| 121 | + error_printed=.true. |
| 122 | + end subroutine |
| 123 | + |
| 124 | + pure function both(lhs,rhs) RESULT(lhs_and_rhs) |
| 125 | + logical, intent(in) :: lhs,rhs |
| 126 | + logical :: lhs_and_rhs |
| 127 | + lhs_and_rhs = lhs .and. rhs |
| 128 | + end function |
| 129 | + |
| 130 | + subroutine co_all(boolean,result_image) |
| 131 | + logical, intent(inout) :: boolean |
| 132 | + integer, intent(in) :: result_image |
| 133 | + call co_reduce(boolean,both,result_image=result_image) |
| 134 | + end subroutine |
| 135 | + |
| 136 | +end program alloc_comp_multidim_shape |
| 137 | + |
0 commit comments