514 type(
gs_t),
target,
intent(inout) :: gs
515 type(
mesh_t),
pointer :: msh
517 type(
stack_i4_t),
target :: local_dof, dof_local, shared_dof, dof_shared
518 type(
stack_i4_t),
target :: local_face_dof, face_dof_local
519 type(
stack_i4_t),
target :: shared_face_dof, face_dof_shared
520 integer :: i, j, k, l, lx, ly, lz, max_id, max_sid, id, lid, dm_size
526 sdm => gs%shared_dofs
531 dm_size =
dofmap%size()/lx
533 call dm%init(dm_size, i)
537 call sdm%init(
dofmap%size(), i)
540 call local_dof%init()
541 call dof_local%init()
543 call local_face_dof%init()
544 call face_dof_local%init()
546 call shared_dof%init()
547 call dof_shared%init()
549 call shared_face_dof%init()
550 call face_dof_shared%init()
562 if (
dofmap%shared_dof(1, 1, 1, i))
then
565 call shared_dof%push(id)
567 call dof_shared%push(lid)
573 call local_dof%push(id)
574 call dof_local%push(lid)
581 if (
dofmap%shared_dof(lx, 1, 1, i))
then
583 call shared_dof%push(id)
584 call dof_shared%push(lid)
587 call local_dof%push(id)
588 call dof_local%push(lid)
592 if (
dofmap%shared_dof(1, ly, 1, i))
then
594 call shared_dof%push(id)
595 call dof_shared%push(lid)
598 call local_dof%push(id)
599 call dof_local%push(lid)
603 if (
dofmap%shared_dof(lx, ly, 1, i))
then
605 call shared_dof%push(id)
606 call dof_shared%push(lid)
609 call local_dof%push(id)
610 call dof_local%push(lid)
614 if (
dofmap%shared_dof(1, 1, lz, i))
then
616 call shared_dof%push(id)
617 call dof_shared%push(lid)
620 call local_dof%push(id)
621 call dof_local%push(lid)
625 if (
dofmap%shared_dof(lx, 1, lz, i))
then
627 call shared_dof%push(id)
628 call dof_shared%push(lid)
631 call local_dof%push(id)
632 call dof_local%push(lid)
636 if (
dofmap%shared_dof(1, ly, lz, i))
then
638 call shared_dof%push(id)
639 call dof_shared%push(lid)
642 call local_dof%push(id)
643 call dof_local%push(lid)
647 if (
dofmap%shared_dof(lx, ly, lz, i))
then
649 call shared_dof%push(id)
650 call dof_shared%push(lid)
653 call local_dof%push(id)
654 call dof_local%push(lid)
671 if (
dofmap%shared_dof(2, 1, 1, i))
then
674 call shared_dof%push(id)
676 call dof_shared%push(id)
681 call local_dof%push(id)
683 call dof_local%push(id)
686 if (
dofmap%shared_dof(2, 1, lz, i))
then
689 call shared_dof%push(id)
691 call dof_shared%push(id)
696 call local_dof%push(id)
698 call dof_local%push(id)
702 if (
dofmap%shared_dof(2, ly, 1, i))
then
705 call shared_dof%push(id)
707 call dof_shared%push(id)
713 call local_dof%push(id)
715 call dof_local%push(id)
718 if (
dofmap%shared_dof(2, ly, lz, i))
then
721 call shared_dof%push(id)
723 call dof_shared%push(id)
728 call local_dof%push(id)
730 call dof_local%push(id)
737 if (
dofmap%shared_dof(1, 2, 1, i))
then
740 call shared_dof%push(id)
742 call dof_shared%push(id)
747 call local_dof%push(id)
749 call dof_local%push(id)
752 if (
dofmap%shared_dof(1, 2, lz, i))
then
755 call shared_dof%push(id)
757 call dof_shared%push(id)
762 call local_dof%push(id)
764 call dof_local%push(id)
768 if (
dofmap%shared_dof(lx, 2, 1, i))
then
771 call shared_dof%push(id)
773 call dof_shared%push(id)
778 call local_dof%push(id)
780 call dof_local%push(id)
783 if (
dofmap%shared_dof(lx, 2, lz, i))
then
786 call shared_dof%push(id)
788 call dof_shared%push(id)
793 call local_dof%push(id)
795 call dof_local%push(id)
801 if (
dofmap%shared_dof(1, 1, 2, i))
then
804 call shared_dof%push(id)
806 call dof_shared%push(id)
811 call local_dof%push(id)
813 call dof_local%push(id)
817 if (
dofmap%shared_dof(lx, 1, 2, i))
then
820 call shared_dof%push(id)
822 call dof_shared%push(id)
827 call local_dof%push(id)
829 call dof_local%push(id)
833 if (
dofmap%shared_dof(1, ly, 2, i))
then
836 call shared_dof%push(id)
838 call dof_shared%push(id)
843 call local_dof%push(id)
845 call dof_local%push(id)
849 if (
dofmap%shared_dof(lx, ly, 2, i))
then
852 call shared_dof%push(id)
854 call dof_shared%push(id)
859 call local_dof%push(id)
861 call dof_local%push(id)
880 if (msh%facet_neigh(3, i) .ne. 0)
then
881 if (
dofmap%shared_dof(2, 1, 1, i))
then
884 call shared_face_dof%push(id)
886 call face_dof_shared%push(id)
891 call local_face_dof%push(id)
893 call face_dof_local%push(id)
898 if (msh%facet_neigh(4, i) .ne. 0)
then
899 if (
dofmap%shared_dof(2, ly, 1, i))
then
903 call shared_face_dof%push(id)
905 call face_dof_shared%push(id)
912 call local_face_dof%push(id)
914 call face_dof_local%push(id)
922 if (msh%facet_neigh(1, i) .ne. 0)
then
923 if (
dofmap%shared_dof(1, 2, 1, i))
then
926 call shared_face_dof%push(id)
928 call face_dof_shared%push(id)
933 call local_face_dof%push(id)
935 call face_dof_local%push(id)
940 if (msh%facet_neigh(2, i) .ne. 0)
then
941 if (
dofmap%shared_dof(lx, 2, 1, i))
then
945 call shared_face_dof%push(id)
947 call face_dof_shared%push(id)
953 call local_face_dof%push(id)
955 call face_dof_local%push(id)
964 if (msh%facet_neigh(1, i) .ne. 0)
then
965 if (
dofmap%shared_dof(1, 2, 2, i))
then
970 call shared_face_dof%push(id)
972 call face_dof_shared%push(id)
980 call local_face_dof%push(id)
982 call face_dof_local%push(id)
988 if (msh%facet_neigh(2, i) .ne. 0)
then
989 if (
dofmap%shared_dof(lx, 2, 2, i))
then
994 call shared_face_dof%push(id)
996 call face_dof_shared%push(id)
1004 call local_face_dof%push(id)
1006 call face_dof_local%push(id)
1013 if (msh%facet_neigh(3, i) .ne. 0)
then
1014 if (
dofmap%shared_dof(2, 1, 2, i))
then
1019 call shared_face_dof%push(id)
1021 call face_dof_shared%push(id)
1029 call local_face_dof%push(id)
1031 call face_dof_local%push(id)
1037 if (msh%facet_neigh(4, i) .ne. 0)
then
1038 if (
dofmap%shared_dof(2, ly, 2, i))
then
1043 call shared_face_dof%push(id)
1045 call face_dof_shared%push(id)
1053 call local_face_dof%push(id)
1055 call face_dof_local%push(id)
1062 if (msh%facet_neigh(5, i) .ne. 0)
then
1063 if (
dofmap%shared_dof(2, 2, 1, i))
then
1068 call shared_face_dof%push(id)
1070 call face_dof_shared%push(id)
1078 call local_face_dof%push(id)
1080 call face_dof_local%push(id)
1086 if (msh%facet_neigh(6, i) .ne. 0)
then
1087 if (
dofmap%shared_dof(2, 2, lz, i))
then
1092 call shared_face_dof%push(id)
1094 call face_dof_shared%push(id)
1102 call local_face_dof%push(id)
1104 call face_dof_local%push(id)
1115 gs%nlocal = local_dof%size() + local_face_dof%size()
1116 gs%local_facet_offset = local_dof%size() + 1
1119 allocate(gs%local_dof_gs(gs%nlocal))
1126 select type (dof_array => local_dof%data)
1128 j = local_dof%size()
1130 gs%local_dof_gs(i) = dof_array(i)
1133 call local_dof%free()
1140 select type (dof_array => local_face_dof%data)
1142 do i = 1, local_face_dof%size()
1143 gs%local_dof_gs(i + j) = dof_array(i)
1146 call local_face_dof%free()
1149 allocate(gs%local_gs_dof(gs%nlocal))
1156 select type (dof_array => dof_local%data)
1158 j = dof_local%size()
1160 gs%local_gs_dof(i) = dof_array(i)
1163 call dof_local%free()
1168 select type (dof_array => face_dof_local%data)
1170 do i = 1, face_dof_local%size()
1171 gs%local_gs_dof(i+j) = dof_array(i)
1174 call face_dof_local%free()
1177 gs%nlocal, 1, gs%nlocal)
1180 gs%local_blk_off, gs%nlocal_blks, gs%nlocal, gs%local_facet_offset)
1183 allocate(gs%local_gs(gs%nlocal))
1185 gs%nshared = shared_dof%size() + shared_face_dof%size()
1186 gs%shared_facet_offset = shared_dof%size() + 1
1189 allocate(gs%shared_dof_gs(gs%nshared))
1196 select type (dof_array => shared_dof%data)
1198 j = shared_dof%size()
1200 gs%shared_dof_gs(i) = dof_array(i)
1203 call shared_dof%free()
1210 select type (dof_array => shared_face_dof%data)
1212 do i = 1, shared_face_dof%size()
1213 gs%shared_dof_gs(i + j) = dof_array(i)
1216 call shared_face_dof%free()
1219 allocate(gs%shared_gs_dof(gs%nshared))
1226 select type (dof_array => dof_shared%data)
1228 j = dof_shared%size()
1230 gs%shared_gs_dof(i) = dof_array(i)
1233 call dof_shared%free()
1238 select type (dof_array => face_dof_shared%data)
1240 do i = 1, face_dof_shared%size()
1241 gs%shared_gs_dof(i + j) = dof_array(i)
1244 call face_dof_shared%free()
1247 allocate(gs%shared_gs(gs%nshared))
1251 allocate(gs%shared_gs_v(
max(1,
gs_vec_nc * gs%nshared)))
1253 call device_map(gs%shared_gs_v, gs%shared_gs_v_d, &
1257 if (gs%nshared .gt. 0)
then
1259 gs%nshared, 1, gs%nshared)
1261 call gs_find_blks(gs%shared_dof_gs, gs%shared_blk_len, &
1262 gs%shared_blk_off, gs%nshared_blks, gs%nshared, &
1263 gs%shared_facet_offset)
1278 integer(kind=i8),
intent(inout) :: dof
1279 integer,
intent(inout) :: max_id
1282 if (map_%get(dof, id) .gt. 0)
then
1284 call map_%set(dof, max_id)
1292 integer,
intent(inout) :: n
1293 integer,
dimension(n),
intent(inout) :: dg
1294 integer,
dimension(n),
intent(inout) :: gd
1296 integer :: tmp, i, j, pivot
1300 pivot = dg((lo + hi) / 2)
1304 if (dg(i) .ge. pivot)
exit
1309 if (dg(j) .le. pivot)
exit
1320 else if (i .eq. j)
then
1334 integer,
intent(in) :: n
1335 integer,
intent(in) :: m
1336 integer,
dimension(n),
intent(inout) :: dg
1337 integer,
allocatable,
intent(inout) :: blk_len(:)
1338 integer,
allocatable,
intent(inout) :: blk_off(:)
1339 integer,
intent(inout) :: nblks
1341 integer :: id, count
1350 do while ( j+1 .le. n .and. dg(j+1) .eq. id)
1354 call blks%push(count)
1358 select type (blk_array => blks%data)
1361 allocate(blk_len(nblks))
1363 blk_len(i) = blk_array(i)
1365 allocate(blk_off(nblks))
1368 blk_off(i) = blk_off(i - 1) + blk_len(i - 1)
1711 class(
gs_t),
intent(inout) :: gs
1712 integer,
intent(in) :: n
1713 real(kind=
rp),
dimension(n),
intent(inout) :: u1, u2, u3
1714 type(c_ptr),
optional,
intent(inout) :: event
1715 integer :: m, l, op, lo, so, tid
1716 integer,
parameter :: nc = 3
1717 type(c_ptr) :: scatter_event
1721 if (.not. gs%comm%vec_supported)
then
1722 if (
present(event))
then
1734 lo = gs%local_facet_offset
1735 so = -gs%shared_facet_offset
1742 scatter_event = c_null_ptr
1743 if (
present(event)) scatter_event = event
1753 if (
pe_size .gt. 1 .and. n .gt. 0)
then
1754 call gs%comm%nbrecv_vec(tid, nc)
1755 call gs%bcknd%gather(gs%shared_gs_v(1), l, so, gs%shared_dof_gs, &
1756 u1, n, gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1757 gs%shared_blk_off, op, .true.)
1758 call gs%bcknd%gather(gs%shared_gs_v(l + 1), l, so, &
1759 gs%shared_dof_gs, u2, n, gs%shared_gs_dof, gs%nshared_blks, &
1760 gs%shared_blk_len, gs%shared_blk_off, op, .true.)
1761 call gs%bcknd%gather(gs%shared_gs_v(2*l + 1), l, so, &
1762 gs%shared_dof_gs, u3, n, gs%shared_gs_dof, gs%nshared_blks, &
1763 gs%shared_blk_len, gs%shared_blk_off, op, .true.)
1764 call gs%comm%nbsend_vec(gs%shared_gs_v, l, nc, tid, &
1765 gs%bcknd%gather_event, gs%bcknd%gs_stream)
1770 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u1, n, &
1771 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1772 gs%local_blk_off, op, .false.)
1773 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u1, n, &
1774 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1775 gs%local_blk_off, .false., c_null_ptr)
1776 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u2, n, &
1777 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1778 gs%local_blk_off, op, .false.)
1779 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u2, n, &
1780 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1781 gs%local_blk_off, .false., c_null_ptr)
1782 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u3, n, &
1783 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1784 gs%local_blk_off, op, .false.)
1785 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u3, n, &
1786 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1787 gs%local_blk_off, .false., c_null_ptr)
1790 if (
pe_size .gt. 1 .and. n .gt. 0)
then
1791 call gs%comm%nbwait_vec(gs%shared_gs_v, l, nc, op, &
1793 call gs%bcknd%scatter(gs%shared_gs_v(1), l, gs%shared_dof_gs, u1, &
1794 n, gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1795 gs%shared_blk_off, .true., scatter_event)
1796 call gs%bcknd%scatter(gs%shared_gs_v(l + 1), l, gs%shared_dof_gs, &
1797 u2, n, gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1798 gs%shared_blk_off, .true., scatter_event)
1799 call gs%bcknd%scatter(gs%shared_gs_v(2*l + 1), l, &
1800 gs%shared_dof_gs, u3, n, gs%shared_gs_dof, gs%nshared_blks, &
1801 gs%shared_blk_len, gs%shared_blk_off, .true., scatter_event)
1809 call gs_op_r3_device(gs, u1, u2, u3, n, op, nc, lo, so, m, l, tid, &
1825 subroutine gs_op_r3_device(gs, u1, u2, u3, n, op, nc, lo, so, m, l, tid, &
1827 class(
gs_t),
intent(inout) :: gs
1828 integer,
intent(in) :: n, op, nc, lo, so, m, l, tid
1829 real(kind=
rp),
dimension(n),
intent(inout) :: u1, u2, u3
1830 type(c_ptr),
intent(inout) :: scatter_event
1831 type(c_ptr) :: sgs_d, col_d, col_event
1832 integer(c_intptr_t) :: sv_addr, off_bytes
1833 integer(c_size_t) :: colbytes
1834 real(c_rp) :: rp_dummy
1839 select type (b => gs%bcknd)
1841 on_host = b%shared_on_host
1842 sgs_d = b%shared_gs_d
1845 sv_addr = transfer(gs%shared_gs_v_d, sv_addr)
1846 colbytes = c_sizeof(rp_dummy) * int(l, c_size_t)
1847 off_bytes = int(l, c_intptr_t) * int(c_sizeof(rp_dummy), c_intptr_t)
1855 col_event = c_null_ptr
1857 col_event = scatter_event
1860 if (
pe_size .gt. 1 .and. n .gt. 0)
then
1861 call gs%comm%nbrecv_vec(tid, nc)
1865 call gs%bcknd%gather(gs%shared_gs, l, so, gs%shared_dof_gs, u1, n, &
1866 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1867 gs%shared_blk_off, op, .true.)
1870 gs%shared_gs_v(1:l) = gs%shared_gs(1:l)
1873 if (.not. c_associated(sgs_d))
then
1874 select type (b => gs%bcknd)
1876 sgs_d = b%shared_gs_d
1879 col_d = transfer(sv_addr, col_d)
1881 sync = .false., strm = gs%bcknd%gs_stream)
1884 call gs%bcknd%gather(gs%shared_gs, l, so, gs%shared_dof_gs, u2, n, &
1885 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1886 gs%shared_blk_off, op, .true.)
1888 gs%shared_gs_v(l + 1:2*l) = gs%shared_gs(1:l)
1890 col_d = transfer(sv_addr + off_bytes, col_d)
1892 sync = .false., strm = gs%bcknd%gs_stream)
1895 call gs%bcknd%gather(gs%shared_gs, l, so, gs%shared_dof_gs, u3, n, &
1896 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1897 gs%shared_blk_off, op, .true.)
1899 gs%shared_gs_v(2*l + 1:3*l) = gs%shared_gs(1:l)
1901 col_d = transfer(sv_addr + 2_c_intptr_t*off_bytes, col_d)
1903 sync = .false., strm = gs%bcknd%gs_stream)
1911 call gs%comm%nbsend_vec(gs%shared_gs_v, l, nc, tid, &
1912 gs%bcknd%gather_event, gs%bcknd%gs_stream)
1916 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u1, n, &
1917 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
1919 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u1, n, &
1920 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
1921 .false., c_null_ptr)
1922 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u2, n, &
1923 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
1925 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u2, n, &
1926 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
1927 .false., c_null_ptr)
1928 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u3, n, &
1929 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
1931 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u3, n, &
1932 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
1933 .false., c_null_ptr)
1937 if (
pe_size .gt. 1 .and. n .gt. 0)
then
1938 call gs%comm%nbwait_vec(gs%shared_gs_v, l, nc, op, gs%bcknd%gs_stream)
1941 gs%shared_gs(1:l) = gs%shared_gs_v(1:l)
1943 col_d = transfer(sv_addr, col_d)
1945 sync = .false., strm = gs%bcknd%gs_stream)
1947 call gs%bcknd%scatter(gs%shared_gs, l, gs%shared_dof_gs, u1, n, &
1948 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1949 gs%shared_blk_off, .true., col_event)
1952 gs%shared_gs(1:l) = gs%shared_gs_v(l + 1:2*l)
1954 col_d = transfer(sv_addr + off_bytes, col_d)
1956 sync = .false., strm = gs%bcknd%gs_stream)
1958 call gs%bcknd%scatter(gs%shared_gs, l, gs%shared_dof_gs, u2, n, &
1959 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1960 gs%shared_blk_off, .true., col_event)
1963 gs%shared_gs(1:l) = gs%shared_gs_v(2*l + 1:3*l)
1965 col_d = transfer(sv_addr + 2_c_intptr_t*off_bytes, col_d)
1967 sync = .false., strm = gs%bcknd%gs_stream)
1969 call gs%bcknd%scatter(gs%shared_gs, l, gs%shared_dof_gs, u3, n, &
1970 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1971 gs%shared_blk_off, .true., col_event)