475 type(
gs_t),
target,
intent(inout) :: gs
476 type(
mesh_t),
pointer :: msh
478 type(
stack_i4_t),
target :: local_dof, dof_local, shared_dof, dof_shared
479 type(
stack_i4_t),
target :: local_face_dof, face_dof_local
480 type(
stack_i4_t),
target :: shared_face_dof, face_dof_shared
481 integer :: i, j, k, l, lx, ly, lz, max_id, max_sid, id, lid, dm_size
487 sdm => gs%shared_dofs
492 dm_size =
dofmap%size()/lx
494 call dm%init(dm_size, i)
498 call sdm%init(
dofmap%size(), i)
501 call local_dof%init()
502 call dof_local%init()
504 call local_face_dof%init()
505 call face_dof_local%init()
507 call shared_dof%init()
508 call dof_shared%init()
510 call shared_face_dof%init()
511 call face_dof_shared%init()
523 if (
dofmap%shared_dof(1, 1, 1, i))
then
526 call shared_dof%push(id)
528 call dof_shared%push(lid)
534 call local_dof%push(id)
535 call dof_local%push(lid)
542 if (
dofmap%shared_dof(lx, 1, 1, i))
then
544 call shared_dof%push(id)
545 call dof_shared%push(lid)
548 call local_dof%push(id)
549 call dof_local%push(lid)
553 if (
dofmap%shared_dof(1, ly, 1, i))
then
555 call shared_dof%push(id)
556 call dof_shared%push(lid)
559 call local_dof%push(id)
560 call dof_local%push(lid)
564 if (
dofmap%shared_dof(lx, ly, 1, i))
then
566 call shared_dof%push(id)
567 call dof_shared%push(lid)
570 call local_dof%push(id)
571 call dof_local%push(lid)
575 if (
dofmap%shared_dof(1, 1, lz, i))
then
577 call shared_dof%push(id)
578 call dof_shared%push(lid)
581 call local_dof%push(id)
582 call dof_local%push(lid)
586 if (
dofmap%shared_dof(lx, 1, lz, i))
then
588 call shared_dof%push(id)
589 call dof_shared%push(lid)
592 call local_dof%push(id)
593 call dof_local%push(lid)
597 if (
dofmap%shared_dof(1, ly, lz, i))
then
599 call shared_dof%push(id)
600 call dof_shared%push(lid)
603 call local_dof%push(id)
604 call dof_local%push(lid)
608 if (
dofmap%shared_dof(lx, ly, lz, i))
then
610 call shared_dof%push(id)
611 call dof_shared%push(lid)
614 call local_dof%push(id)
615 call dof_local%push(lid)
632 if (
dofmap%shared_dof(2, 1, 1, i))
then
635 call shared_dof%push(id)
637 call dof_shared%push(id)
642 call local_dof%push(id)
644 call dof_local%push(id)
647 if (
dofmap%shared_dof(2, 1, lz, i))
then
650 call shared_dof%push(id)
652 call dof_shared%push(id)
657 call local_dof%push(id)
659 call dof_local%push(id)
663 if (
dofmap%shared_dof(2, ly, 1, i))
then
666 call shared_dof%push(id)
668 call dof_shared%push(id)
674 call local_dof%push(id)
676 call dof_local%push(id)
679 if (
dofmap%shared_dof(2, ly, lz, i))
then
682 call shared_dof%push(id)
684 call dof_shared%push(id)
689 call local_dof%push(id)
691 call dof_local%push(id)
698 if (
dofmap%shared_dof(1, 2, 1, i))
then
701 call shared_dof%push(id)
703 call dof_shared%push(id)
708 call local_dof%push(id)
710 call dof_local%push(id)
713 if (
dofmap%shared_dof(1, 2, lz, i))
then
716 call shared_dof%push(id)
718 call dof_shared%push(id)
723 call local_dof%push(id)
725 call dof_local%push(id)
729 if (
dofmap%shared_dof(lx, 2, 1, i))
then
732 call shared_dof%push(id)
734 call dof_shared%push(id)
739 call local_dof%push(id)
741 call dof_local%push(id)
744 if (
dofmap%shared_dof(lx, 2, lz, i))
then
747 call shared_dof%push(id)
749 call dof_shared%push(id)
754 call local_dof%push(id)
756 call dof_local%push(id)
762 if (
dofmap%shared_dof(1, 1, 2, i))
then
765 call shared_dof%push(id)
767 call dof_shared%push(id)
772 call local_dof%push(id)
774 call dof_local%push(id)
778 if (
dofmap%shared_dof(lx, 1, 2, i))
then
781 call shared_dof%push(id)
783 call dof_shared%push(id)
788 call local_dof%push(id)
790 call dof_local%push(id)
794 if (
dofmap%shared_dof(1, ly, 2, i))
then
797 call shared_dof%push(id)
799 call dof_shared%push(id)
804 call local_dof%push(id)
806 call dof_local%push(id)
810 if (
dofmap%shared_dof(lx, ly, 2, i))
then
813 call shared_dof%push(id)
815 call dof_shared%push(id)
820 call local_dof%push(id)
822 call dof_local%push(id)
841 if (msh%facet_neigh(3, i) .ne. 0)
then
842 if (
dofmap%shared_dof(2, 1, 1, i))
then
845 call shared_face_dof%push(id)
847 call face_dof_shared%push(id)
852 call local_face_dof%push(id)
854 call face_dof_local%push(id)
859 if (msh%facet_neigh(4, i) .ne. 0)
then
860 if (
dofmap%shared_dof(2, ly, 1, i))
then
864 call shared_face_dof%push(id)
866 call face_dof_shared%push(id)
873 call local_face_dof%push(id)
875 call face_dof_local%push(id)
883 if (msh%facet_neigh(1, i) .ne. 0)
then
884 if (
dofmap%shared_dof(1, 2, 1, i))
then
887 call shared_face_dof%push(id)
889 call face_dof_shared%push(id)
894 call local_face_dof%push(id)
896 call face_dof_local%push(id)
901 if (msh%facet_neigh(2, i) .ne. 0)
then
902 if (
dofmap%shared_dof(lx, 2, 1, i))
then
906 call shared_face_dof%push(id)
908 call face_dof_shared%push(id)
914 call local_face_dof%push(id)
916 call face_dof_local%push(id)
925 if (msh%facet_neigh(1, i) .ne. 0)
then
926 if (
dofmap%shared_dof(1, 2, 2, i))
then
931 call shared_face_dof%push(id)
933 call face_dof_shared%push(id)
941 call local_face_dof%push(id)
943 call face_dof_local%push(id)
949 if (msh%facet_neigh(2, i) .ne. 0)
then
950 if (
dofmap%shared_dof(lx, 2, 2, i))
then
955 call shared_face_dof%push(id)
957 call face_dof_shared%push(id)
965 call local_face_dof%push(id)
967 call face_dof_local%push(id)
974 if (msh%facet_neigh(3, i) .ne. 0)
then
975 if (
dofmap%shared_dof(2, 1, 2, i))
then
980 call shared_face_dof%push(id)
982 call face_dof_shared%push(id)
990 call local_face_dof%push(id)
992 call face_dof_local%push(id)
998 if (msh%facet_neigh(4, i) .ne. 0)
then
999 if (
dofmap%shared_dof(2, ly, 2, i))
then
1004 call shared_face_dof%push(id)
1006 call face_dof_shared%push(id)
1014 call local_face_dof%push(id)
1016 call face_dof_local%push(id)
1023 if (msh%facet_neigh(5, i) .ne. 0)
then
1024 if (
dofmap%shared_dof(2, 2, 1, i))
then
1029 call shared_face_dof%push(id)
1031 call face_dof_shared%push(id)
1039 call local_face_dof%push(id)
1041 call face_dof_local%push(id)
1047 if (msh%facet_neigh(6, i) .ne. 0)
then
1048 if (
dofmap%shared_dof(2, 2, lz, i))
then
1053 call shared_face_dof%push(id)
1055 call face_dof_shared%push(id)
1063 call local_face_dof%push(id)
1065 call face_dof_local%push(id)
1076 gs%nlocal = local_dof%size() + local_face_dof%size()
1077 gs%local_facet_offset = local_dof%size() + 1
1080 allocate(gs%local_dof_gs(gs%nlocal))
1087 select type (dof_array => local_dof%data)
1089 j = local_dof%size()
1091 gs%local_dof_gs(i) = dof_array(i)
1094 call local_dof%free()
1101 select type (dof_array => local_face_dof%data)
1103 do i = 1, local_face_dof%size()
1104 gs%local_dof_gs(i + j) = dof_array(i)
1107 call local_face_dof%free()
1110 allocate(gs%local_gs_dof(gs%nlocal))
1117 select type (dof_array => dof_local%data)
1119 j = dof_local%size()
1121 gs%local_gs_dof(i) = dof_array(i)
1124 call dof_local%free()
1129 select type (dof_array => face_dof_local%data)
1131 do i = 1, face_dof_local%size()
1132 gs%local_gs_dof(i+j) = dof_array(i)
1135 call face_dof_local%free()
1138 gs%nlocal, 1, gs%nlocal)
1141 gs%local_blk_off, gs%nlocal_blks, gs%nlocal, gs%local_facet_offset)
1144 allocate(gs%local_gs(gs%nlocal))
1146 gs%nshared = shared_dof%size() + shared_face_dof%size()
1147 gs%shared_facet_offset = shared_dof%size() + 1
1150 allocate(gs%shared_dof_gs(gs%nshared))
1157 select type (dof_array => shared_dof%data)
1159 j = shared_dof%size()
1161 gs%shared_dof_gs(i) = dof_array(i)
1164 call shared_dof%free()
1171 select type (dof_array => shared_face_dof%data)
1173 do i = 1, shared_face_dof%size()
1174 gs%shared_dof_gs(i + j) = dof_array(i)
1177 call shared_face_dof%free()
1180 allocate(gs%shared_gs_dof(gs%nshared))
1187 select type (dof_array => dof_shared%data)
1189 j = dof_shared%size()
1191 gs%shared_gs_dof(i) = dof_array(i)
1194 call dof_shared%free()
1199 select type (dof_array => face_dof_shared%data)
1201 do i = 1, face_dof_shared%size()
1202 gs%shared_gs_dof(i + j) = dof_array(i)
1205 call face_dof_shared%free()
1208 allocate(gs%shared_gs(gs%nshared))
1212 allocate(gs%shared_gs_v(
max(1,
gs_vec_nc * gs%nshared)))
1214 call device_map(gs%shared_gs_v, gs%shared_gs_v_d, &
1218 if (gs%nshared .gt. 0)
then
1220 gs%nshared, 1, gs%nshared)
1222 call gs_find_blks(gs%shared_dof_gs, gs%shared_blk_len, &
1223 gs%shared_blk_off, gs%nshared_blks, gs%nshared, &
1224 gs%shared_facet_offset)
1239 integer(kind=i8),
intent(inout) :: dof
1240 integer,
intent(inout) :: max_id
1243 if (map_%get(dof, id) .gt. 0)
then
1245 call map_%set(dof, max_id)
1253 integer,
intent(inout) :: n
1254 integer,
dimension(n),
intent(inout) :: dg
1255 integer,
dimension(n),
intent(inout) :: gd
1257 integer :: tmp, i, j, pivot
1261 pivot = dg((lo + hi) / 2)
1265 if (dg(i) .ge. pivot)
exit
1270 if (dg(j) .le. pivot)
exit
1281 else if (i .eq. j)
then
1295 integer,
intent(in) :: n
1296 integer,
intent(in) :: m
1297 integer,
dimension(n),
intent(inout) :: dg
1298 integer,
allocatable,
intent(inout) :: blk_len(:)
1299 integer,
allocatable,
intent(inout) :: blk_off(:)
1300 integer,
intent(inout) :: nblks
1302 integer :: id, count
1311 do while ( j+1 .le. n .and. dg(j+1) .eq. id)
1315 call blks%push(count)
1319 select type (blk_array => blks%data)
1322 allocate(blk_len(nblks))
1324 blk_len(i) = blk_array(i)
1326 allocate(blk_off(nblks))
1329 blk_off(i) = blk_off(i - 1) + blk_len(i - 1)
1672 class(
gs_t),
intent(inout) :: gs
1673 integer,
intent(in) :: n
1674 real(kind=
rp),
dimension(n),
intent(inout) :: u1, u2, u3
1675 type(c_ptr),
optional,
intent(inout) :: event
1676 integer :: m, l, op, lo, so, tid
1677 integer,
parameter :: nc = 3
1678 type(c_ptr) :: scatter_event
1682 if (.not. gs%comm%vec_supported)
then
1683 if (
present(event))
then
1695 lo = gs%local_facet_offset
1696 so = -gs%shared_facet_offset
1703 scatter_event = c_null_ptr
1704 if (
present(event)) scatter_event = event
1714 if (
pe_size .gt. 1 .and. n .gt. 0)
then
1715 call gs%comm%nbrecv_vec(tid, nc)
1716 call gs%bcknd%gather(gs%shared_gs_v(1), l, so, gs%shared_dof_gs, &
1717 u1, n, gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1718 gs%shared_blk_off, op, .true.)
1719 call gs%bcknd%gather(gs%shared_gs_v(l + 1), l, so, &
1720 gs%shared_dof_gs, u2, n, gs%shared_gs_dof, gs%nshared_blks, &
1721 gs%shared_blk_len, gs%shared_blk_off, op, .true.)
1722 call gs%bcknd%gather(gs%shared_gs_v(2*l + 1), l, so, &
1723 gs%shared_dof_gs, u3, n, gs%shared_gs_dof, gs%nshared_blks, &
1724 gs%shared_blk_len, gs%shared_blk_off, op, .true.)
1725 call gs%comm%nbsend_vec(gs%shared_gs_v, l, nc, tid, &
1726 gs%bcknd%gather_event, gs%bcknd%gs_stream)
1731 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u1, n, &
1732 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1733 gs%local_blk_off, op, .false.)
1734 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u1, n, &
1735 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1736 gs%local_blk_off, .false., c_null_ptr)
1737 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u2, n, &
1738 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1739 gs%local_blk_off, op, .false.)
1740 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u2, n, &
1741 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1742 gs%local_blk_off, .false., c_null_ptr)
1743 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u3, n, &
1744 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1745 gs%local_blk_off, op, .false.)
1746 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u3, n, &
1747 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1748 gs%local_blk_off, .false., c_null_ptr)
1751 if (
pe_size .gt. 1 .and. n .gt. 0)
then
1752 call gs%comm%nbwait_vec(gs%shared_gs_v, l, nc, op, &
1754 call gs%bcknd%scatter(gs%shared_gs_v(1), l, gs%shared_dof_gs, u1, &
1755 n, gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1756 gs%shared_blk_off, .true., scatter_event)
1757 call gs%bcknd%scatter(gs%shared_gs_v(l + 1), l, gs%shared_dof_gs, &
1758 u2, n, gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1759 gs%shared_blk_off, .true., scatter_event)
1760 call gs%bcknd%scatter(gs%shared_gs_v(2*l + 1), l, &
1761 gs%shared_dof_gs, u3, n, gs%shared_gs_dof, gs%nshared_blks, &
1762 gs%shared_blk_len, gs%shared_blk_off, .true., scatter_event)
1770 call gs_op_r3_device(gs, u1, u2, u3, n, op, nc, lo, so, m, l, tid, &
1786 subroutine gs_op_r3_device(gs, u1, u2, u3, n, op, nc, lo, so, m, l, tid, &
1788 class(
gs_t),
intent(inout) :: gs
1789 integer,
intent(in) :: n, op, nc, lo, so, m, l, tid
1790 real(kind=
rp),
dimension(n),
intent(inout) :: u1, u2, u3
1791 type(c_ptr),
intent(inout) :: scatter_event
1792 type(c_ptr) :: sgs_d, col_d, col_event
1793 integer(c_intptr_t) :: sv_addr, off_bytes
1794 integer(c_size_t) :: colbytes
1795 real(c_rp) :: rp_dummy
1800 select type (b => gs%bcknd)
1802 on_host = b%shared_on_host
1803 sgs_d = b%shared_gs_d
1806 sv_addr = transfer(gs%shared_gs_v_d, sv_addr)
1807 colbytes = c_sizeof(rp_dummy) * int(l, c_size_t)
1808 off_bytes = int(l, c_intptr_t) * int(c_sizeof(rp_dummy), c_intptr_t)
1816 col_event = c_null_ptr
1818 col_event = scatter_event
1821 if (
pe_size .gt. 1 .and. n .gt. 0)
then
1822 call gs%comm%nbrecv_vec(tid, nc)
1826 call gs%bcknd%gather(gs%shared_gs, l, so, gs%shared_dof_gs, u1, n, &
1827 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1828 gs%shared_blk_off, op, .true.)
1831 gs%shared_gs_v(1:l) = gs%shared_gs(1:l)
1834 if (.not. c_associated(sgs_d))
then
1835 select type (b => gs%bcknd)
1837 sgs_d = b%shared_gs_d
1840 col_d = transfer(sv_addr, col_d)
1842 sync = .false., strm = gs%bcknd%gs_stream)
1845 call gs%bcknd%gather(gs%shared_gs, l, so, gs%shared_dof_gs, u2, n, &
1846 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1847 gs%shared_blk_off, op, .true.)
1849 gs%shared_gs_v(l + 1:2*l) = gs%shared_gs(1:l)
1851 col_d = transfer(sv_addr + off_bytes, col_d)
1853 sync = .false., strm = gs%bcknd%gs_stream)
1856 call gs%bcknd%gather(gs%shared_gs, l, so, gs%shared_dof_gs, u3, n, &
1857 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1858 gs%shared_blk_off, op, .true.)
1860 gs%shared_gs_v(2*l + 1:3*l) = gs%shared_gs(1:l)
1862 col_d = transfer(sv_addr + 2_c_intptr_t*off_bytes, col_d)
1864 sync = .false., strm = gs%bcknd%gs_stream)
1872 call gs%comm%nbsend_vec(gs%shared_gs_v, l, nc, tid, &
1873 gs%bcknd%gather_event, gs%bcknd%gs_stream)
1877 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u1, n, &
1878 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
1880 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u1, n, &
1881 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
1882 .false., c_null_ptr)
1883 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u2, n, &
1884 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
1886 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u2, n, &
1887 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
1888 .false., c_null_ptr)
1889 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u3, n, &
1890 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
1892 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u3, n, &
1893 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
1894 .false., c_null_ptr)
1898 if (
pe_size .gt. 1 .and. n .gt. 0)
then
1899 call gs%comm%nbwait_vec(gs%shared_gs_v, l, nc, op, gs%bcknd%gs_stream)
1902 gs%shared_gs(1:l) = gs%shared_gs_v(1:l)
1904 col_d = transfer(sv_addr, col_d)
1906 sync = .false., strm = gs%bcknd%gs_stream)
1908 call gs%bcknd%scatter(gs%shared_gs, l, gs%shared_dof_gs, u1, n, &
1909 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1910 gs%shared_blk_off, .true., col_event)
1913 gs%shared_gs(1:l) = gs%shared_gs_v(l + 1:2*l)
1915 col_d = transfer(sv_addr + off_bytes, col_d)
1917 sync = .false., strm = gs%bcknd%gs_stream)
1919 call gs%bcknd%scatter(gs%shared_gs, l, gs%shared_dof_gs, u2, n, &
1920 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1921 gs%shared_blk_off, .true., col_event)
1924 gs%shared_gs(1:l) = gs%shared_gs_v(2*l + 1:3*l)
1926 col_d = transfer(sv_addr + 2_c_intptr_t*off_bytes, col_d)
1928 sync = .false., strm = gs%bcknd%gs_stream)
1930 call gs%bcknd%scatter(gs%shared_gs, l, gs%shared_dof_gs, u3, n, &
1931 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1932 gs%shared_blk_off, .true., col_event)