609 subroutine gs_init_mapping(gs)
610 type(gs_t),
target,
intent(inout) :: gs
611 type(
mesh_t),
pointer :: msh
613 type(
stack_i4_t),
target :: local_dof, dof_local, shared_dof, dof_shared
614 type(
stack_i4_t),
target :: local_face_dof, face_dof_local
615 type(
stack_i4_t),
target :: shared_face_dof, face_dof_shared
616 integer :: i, j, k, l, lx, ly, lz, max_id, max_sid, id, lid, dm_size
622 sdm => gs%shared_dofs
627 dm_size =
dofmap%size()/lx
629 call dm%init(dm_size, i)
633 call sdm%init(
dofmap%size(), i)
636 call local_dof%init()
637 call dof_local%init()
639 call local_face_dof%init()
640 call face_dof_local%init()
642 call shared_dof%init()
643 call dof_shared%init()
645 call shared_face_dof%init()
646 call face_dof_shared%init()
658 if (
dofmap%shared_dof(1, 1, 1, i))
then
661 call shared_dof%push(id)
663 call dof_shared%push(lid)
669 call local_dof%push(id)
670 call dof_local%push(lid)
677 if (
dofmap%shared_dof(lx, 1, 1, i))
then
679 call shared_dof%push(id)
680 call dof_shared%push(lid)
683 call local_dof%push(id)
684 call dof_local%push(lid)
688 if (
dofmap%shared_dof(1, ly, 1, i))
then
690 call shared_dof%push(id)
691 call dof_shared%push(lid)
694 call local_dof%push(id)
695 call dof_local%push(lid)
699 if (
dofmap%shared_dof(lx, ly, 1, i))
then
701 call shared_dof%push(id)
702 call dof_shared%push(lid)
705 call local_dof%push(id)
706 call dof_local%push(lid)
710 if (
dofmap%shared_dof(1, 1, lz, i))
then
712 call shared_dof%push(id)
713 call dof_shared%push(lid)
716 call local_dof%push(id)
717 call dof_local%push(lid)
721 if (
dofmap%shared_dof(lx, 1, lz, i))
then
723 call shared_dof%push(id)
724 call dof_shared%push(lid)
727 call local_dof%push(id)
728 call dof_local%push(lid)
732 if (
dofmap%shared_dof(1, ly, lz, i))
then
734 call shared_dof%push(id)
735 call dof_shared%push(lid)
738 call local_dof%push(id)
739 call dof_local%push(lid)
743 if (
dofmap%shared_dof(lx, ly, lz, i))
then
745 call shared_dof%push(id)
746 call dof_shared%push(lid)
749 call local_dof%push(id)
750 call dof_local%push(lid)
767 if (
dofmap%shared_dof(2, 1, 1, i))
then
770 call shared_dof%push(id)
772 call dof_shared%push(id)
777 call local_dof%push(id)
779 call dof_local%push(id)
782 if (
dofmap%shared_dof(2, 1, lz, i))
then
785 call shared_dof%push(id)
787 call dof_shared%push(id)
792 call local_dof%push(id)
794 call dof_local%push(id)
798 if (
dofmap%shared_dof(2, ly, 1, i))
then
801 call shared_dof%push(id)
803 call dof_shared%push(id)
809 call local_dof%push(id)
811 call dof_local%push(id)
814 if (
dofmap%shared_dof(2, ly, lz, i))
then
817 call shared_dof%push(id)
819 call dof_shared%push(id)
824 call local_dof%push(id)
826 call dof_local%push(id)
833 if (
dofmap%shared_dof(1, 2, 1, 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)
848 if (
dofmap%shared_dof(1, 2, lz, i))
then
851 call shared_dof%push(id)
853 call dof_shared%push(id)
858 call local_dof%push(id)
860 call dof_local%push(id)
864 if (
dofmap%shared_dof(lx, 2, 1, i))
then
867 call shared_dof%push(id)
869 call dof_shared%push(id)
874 call local_dof%push(id)
876 call dof_local%push(id)
879 if (
dofmap%shared_dof(lx, 2, lz, i))
then
882 call shared_dof%push(id)
884 call dof_shared%push(id)
889 call local_dof%push(id)
891 call dof_local%push(id)
897 if (
dofmap%shared_dof(1, 1, 2, i))
then
900 call shared_dof%push(id)
902 call dof_shared%push(id)
907 call local_dof%push(id)
909 call dof_local%push(id)
913 if (
dofmap%shared_dof(lx, 1, 2, i))
then
916 call shared_dof%push(id)
918 call dof_shared%push(id)
923 call local_dof%push(id)
925 call dof_local%push(id)
929 if (
dofmap%shared_dof(1, ly, 2, i))
then
932 call shared_dof%push(id)
934 call dof_shared%push(id)
939 call local_dof%push(id)
941 call dof_local%push(id)
945 if (
dofmap%shared_dof(lx, ly, 2, i))
then
948 call shared_dof%push(id)
950 call dof_shared%push(id)
955 call local_dof%push(id)
957 call dof_local%push(id)
976 if (msh%facet_neigh(3, i) .ne. 0)
then
977 if (
dofmap%shared_dof(2, 1, 1, i))
then
980 call shared_face_dof%push(id)
982 call face_dof_shared%push(id)
987 call local_face_dof%push(id)
989 call face_dof_local%push(id)
994 if (msh%facet_neigh(4, i) .ne. 0)
then
995 if (
dofmap%shared_dof(2, ly, 1, i))
then
999 call shared_face_dof%push(id)
1001 call face_dof_shared%push(id)
1008 call local_face_dof%push(id)
1010 call face_dof_local%push(id)
1018 if (msh%facet_neigh(1, i) .ne. 0)
then
1019 if (
dofmap%shared_dof(1, 2, 1, i))
then
1022 call shared_face_dof%push(id)
1024 call face_dof_shared%push(id)
1029 call local_face_dof%push(id)
1031 call face_dof_local%push(id)
1036 if (msh%facet_neigh(2, i) .ne. 0)
then
1037 if (
dofmap%shared_dof(lx, 2, 1, i))
then
1041 call shared_face_dof%push(id)
1043 call face_dof_shared%push(id)
1049 call local_face_dof%push(id)
1051 call face_dof_local%push(id)
1060 if (msh%facet_neigh(1, i) .ne. 0)
then
1061 if (
dofmap%shared_dof(1, 2, 2, i))
then
1066 call shared_face_dof%push(id)
1068 call face_dof_shared%push(id)
1076 call local_face_dof%push(id)
1078 call face_dof_local%push(id)
1084 if (msh%facet_neigh(2, i) .ne. 0)
then
1085 if (
dofmap%shared_dof(lx, 2, 2, i))
then
1090 call shared_face_dof%push(id)
1092 call face_dof_shared%push(id)
1100 call local_face_dof%push(id)
1102 call face_dof_local%push(id)
1109 if (msh%facet_neigh(3, i) .ne. 0)
then
1110 if (
dofmap%shared_dof(2, 1, 2, i))
then
1115 call shared_face_dof%push(id)
1117 call face_dof_shared%push(id)
1125 call local_face_dof%push(id)
1127 call face_dof_local%push(id)
1133 if (msh%facet_neigh(4, i) .ne. 0)
then
1134 if (
dofmap%shared_dof(2, ly, 2, i))
then
1139 call shared_face_dof%push(id)
1141 call face_dof_shared%push(id)
1149 call local_face_dof%push(id)
1151 call face_dof_local%push(id)
1158 if (msh%facet_neigh(5, i) .ne. 0)
then
1159 if (
dofmap%shared_dof(2, 2, 1, i))
then
1164 call shared_face_dof%push(id)
1166 call face_dof_shared%push(id)
1174 call local_face_dof%push(id)
1176 call face_dof_local%push(id)
1182 if (msh%facet_neigh(6, i) .ne. 0)
then
1183 if (
dofmap%shared_dof(2, 2, lz, i))
then
1188 call shared_face_dof%push(id)
1190 call face_dof_shared%push(id)
1198 call local_face_dof%push(id)
1200 call face_dof_local%push(id)
1211 gs%nlocal = local_dof%size() + local_face_dof%size()
1212 gs%local_facet_offset = local_dof%size() + 1
1215 allocate(gs%local_dof_gs(gs%nlocal))
1222 select type (dof_array => local_dof%data)
1224 j = local_dof%size()
1226 gs%local_dof_gs(i) = dof_array(i)
1229 call local_dof%free()
1236 select type (dof_array => local_face_dof%data)
1238 do i = 1, local_face_dof%size()
1239 gs%local_dof_gs(i + j) = dof_array(i)
1242 call local_face_dof%free()
1245 allocate(gs%local_gs_dof(gs%nlocal))
1252 select type (dof_array => dof_local%data)
1254 j = dof_local%size()
1256 gs%local_gs_dof(i) = dof_array(i)
1259 call dof_local%free()
1264 select type (dof_array => face_dof_local%data)
1266 do i = 1, face_dof_local%size()
1267 gs%local_gs_dof(i+j) = dof_array(i)
1270 call face_dof_local%free()
1273 gs%nlocal, 1, gs%nlocal)
1276 gs%local_blk_off, gs%nlocal_blks, gs%nlocal, gs%local_facet_offset)
1279 allocate(gs%local_gs(gs%nlocal))
1281 gs%nshared = shared_dof%size() + shared_face_dof%size()
1282 gs%shared_facet_offset = shared_dof%size() + 1
1285 allocate(gs%shared_dof_gs(gs%nshared))
1292 select type (dof_array => shared_dof%data)
1294 j = shared_dof%size()
1296 gs%shared_dof_gs(i) = dof_array(i)
1299 call shared_dof%free()
1306 select type (dof_array => shared_face_dof%data)
1308 do i = 1, shared_face_dof%size()
1309 gs%shared_dof_gs(i + j) = dof_array(i)
1312 call shared_face_dof%free()
1315 allocate(gs%shared_gs_dof(gs%nshared))
1322 select type (dof_array => dof_shared%data)
1324 j = dof_shared%size()
1326 gs%shared_gs_dof(i) = dof_array(i)
1329 call dof_shared%free()
1334 select type (dof_array => face_dof_shared%data)
1336 do i = 1, face_dof_shared%size()
1337 gs%shared_gs_dof(i + j) = dof_array(i)
1340 call face_dof_shared%free()
1343 allocate(gs%shared_gs(gs%nshared))
1347 allocate(gs%shared_gs_v(
max(1,
gs_vec_nc * gs%nshared)))
1349 call device_map(gs%shared_gs_v, gs%shared_gs_v_d, &
1353 if (gs%nshared .gt. 0)
then
1355 gs%nshared, 1, gs%nshared)
1357 call gs_find_blks(gs%shared_dof_gs, gs%shared_blk_len, &
1358 gs%shared_blk_off, gs%nshared_blks, gs%nshared, &
1359 gs%shared_facet_offset)
1374 integer(kind=i8),
intent(inout) :: dof
1375 integer,
intent(inout) :: max_id
1378 if (map_%get(dof, id) .gt. 0)
then
1380 call map_%set(dof, max_id)
1388 integer,
intent(inout) :: n
1389 integer,
dimension(n),
intent(inout) :: dg
1390 integer,
dimension(n),
intent(inout) :: gd
1392 integer :: tmp, i, j, pivot
1396 pivot = dg((lo + hi) / 2)
1400 if (dg(i) .ge. pivot)
exit
1405 if (dg(j) .le. pivot)
exit
1416 else if (i .eq. j)
then
1430 integer,
intent(in) :: n
1431 integer,
intent(in) :: m
1432 integer,
dimension(n),
intent(inout) :: dg
1433 integer,
allocatable,
intent(inout) :: blk_len(:)
1434 integer,
allocatable,
intent(inout) :: blk_off(:)
1435 integer,
intent(inout) :: nblks
1437 integer :: id, count
1446 do while ( j+1 .le. n .and. dg(j+1) .eq. id)
1450 call blks%push(count)
1454 select type (blk_array => blks%data)
1457 allocate(blk_len(nblks))
1459 blk_len(i) = blk_array(i)
1461 allocate(blk_off(nblks))
1464 blk_off(i) = blk_off(i - 1) + blk_len(i - 1)
1806 subroutine gs_op_vector3(gs, u1, u2, u3, n, op, event)
1807 class(gs_t),
intent(inout) :: gs
1808 integer,
intent(in) :: n
1809 real(kind=
rp),
dimension(n),
intent(inout) :: u1, u2, u3
1810 type(c_ptr),
optional,
intent(inout) :: event
1811 integer :: m, l, op, lo, so, tid
1812 integer,
parameter :: nc = 3
1813 type(c_ptr) :: scatter_event
1817 if (.not. gs%comm%vec_supported)
then
1818 if (
present(event))
then
1819 call gs_op_vector(gs, u1, n, op, event)
1820 call gs_op_vector(gs, u2, n, op, event)
1821 call gs_op_vector(gs, u3, n, op, event)
1823 call gs_op_vector(gs, u1, n, op)
1824 call gs_op_vector(gs, u2, n, op)
1825 call gs_op_vector(gs, u3, n, op)
1830 lo = gs%local_facet_offset
1831 so = -gs%shared_facet_offset
1838 scatter_event = c_null_ptr
1839 if (
present(event)) scatter_event = event
1849 if (
pe_size .gt. 1 .and. n .gt. 0)
then
1850 call gs%comm%nbrecv_vec(tid, nc)
1851 call gs%bcknd%gather(gs%shared_gs_v(1), l, so, gs%shared_dof_gs, &
1852 u1, n, gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1853 gs%shared_blk_off, op, .true.)
1854 call gs%bcknd%gather(gs%shared_gs_v(l + 1), l, so, &
1855 gs%shared_dof_gs, u2, n, gs%shared_gs_dof, gs%nshared_blks, &
1856 gs%shared_blk_len, gs%shared_blk_off, op, .true.)
1857 call gs%bcknd%gather(gs%shared_gs_v(2*l + 1), l, so, &
1858 gs%shared_dof_gs, u3, n, gs%shared_gs_dof, gs%nshared_blks, &
1859 gs%shared_blk_len, gs%shared_blk_off, op, .true.)
1860 call gs%comm%nbsend_vec(gs%shared_gs_v, l, nc, tid, &
1861 gs%bcknd%gather_event, gs%bcknd%gs_stream)
1866 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u1, n, &
1867 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1868 gs%local_blk_off, op, .false.)
1869 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u1, n, &
1870 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1871 gs%local_blk_off, .false., c_null_ptr)
1872 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u2, n, &
1873 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1874 gs%local_blk_off, op, .false.)
1875 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u2, n, &
1876 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1877 gs%local_blk_off, .false., c_null_ptr)
1878 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u3, n, &
1879 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1880 gs%local_blk_off, op, .false.)
1881 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u3, n, &
1882 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1883 gs%local_blk_off, .false., c_null_ptr)
1886 if (
pe_size .gt. 1 .and. n .gt. 0)
then
1887 call gs%comm%nbwait_vec(gs%shared_gs_v, l, nc, op, &
1889 call gs%bcknd%scatter(gs%shared_gs_v(1), l, gs%shared_dof_gs, u1, &
1890 n, gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1891 gs%shared_blk_off, .true., scatter_event)
1892 call gs%bcknd%scatter(gs%shared_gs_v(l + 1), l, gs%shared_dof_gs, &
1893 u2, n, gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1894 gs%shared_blk_off, .true., scatter_event)
1895 call gs%bcknd%scatter(gs%shared_gs_v(2*l + 1), l, &
1896 gs%shared_dof_gs, u3, n, gs%shared_gs_dof, gs%nshared_blks, &
1897 gs%shared_blk_len, gs%shared_blk_off, .true., scatter_event)
1905 call gs_op_r3_device(gs, u1, u2, u3, n, op, nc, lo, so, m, l, tid, &
1921 subroutine gs_op_r3_device(gs, u1, u2, u3, n, op, nc, lo, so, m, l, tid, &
1923 class(gs_t),
intent(inout) :: gs
1924 integer,
intent(in) :: n, op, nc, lo, so, m, l, tid
1925 real(kind=
rp),
dimension(n),
intent(inout) :: u1, u2, u3
1926 type(c_ptr),
intent(inout) :: scatter_event
1927 type(c_ptr) :: sgs_d, col_d, col_event
1928 integer(c_intptr_t) :: sv_addr, off_bytes
1929 integer(c_size_t) :: colbytes
1930 real(c_rp) :: rp_dummy
1935 select type (b => gs%bcknd)
1937 on_host = b%shared_on_host
1938 sgs_d = b%shared_gs_d
1941 sv_addr = transfer(gs%shared_gs_v_d, sv_addr)
1942 colbytes = c_sizeof(rp_dummy) * int(l, c_size_t)
1943 off_bytes = int(l, c_intptr_t) * int(c_sizeof(rp_dummy), c_intptr_t)
1951 col_event = c_null_ptr
1953 col_event = scatter_event
1956 if (
pe_size .gt. 1 .and. n .gt. 0)
then
1957 call gs%comm%nbrecv_vec(tid, nc)
1961 call gs%bcknd%gather(gs%shared_gs, l, so, gs%shared_dof_gs, u1, n, &
1962 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1963 gs%shared_blk_off, op, .true.)
1966 gs%shared_gs_v(1:l) = gs%shared_gs(1:l)
1969 if (.not. c_associated(sgs_d))
then
1970 select type (b => gs%bcknd)
1972 sgs_d = b%shared_gs_d
1975 col_d = transfer(sv_addr, col_d)
1977 sync = .false., strm = gs%bcknd%gs_stream)
1980 call gs%bcknd%gather(gs%shared_gs, l, so, gs%shared_dof_gs, u2, n, &
1981 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1982 gs%shared_blk_off, op, .true.)
1984 gs%shared_gs_v(l + 1:2*l) = gs%shared_gs(1:l)
1986 col_d = transfer(sv_addr + off_bytes, col_d)
1988 sync = .false., strm = gs%bcknd%gs_stream)
1991 call gs%bcknd%gather(gs%shared_gs, l, so, gs%shared_dof_gs, u3, n, &
1992 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1993 gs%shared_blk_off, op, .true.)
1995 gs%shared_gs_v(2*l + 1:3*l) = gs%shared_gs(1:l)
1997 col_d = transfer(sv_addr + 2_c_intptr_t*off_bytes, col_d)
1999 sync = .false., strm = gs%bcknd%gs_stream)
2007 call gs%comm%nbsend_vec(gs%shared_gs_v, l, nc, tid, &
2008 gs%bcknd%gather_event, gs%bcknd%gs_stream)
2012 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u1, n, &
2013 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
2015 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u1, n, &
2016 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
2017 .false., c_null_ptr)
2018 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u2, n, &
2019 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
2021 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u2, n, &
2022 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
2023 .false., c_null_ptr)
2024 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u3, n, &
2025 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
2027 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u3, n, &
2028 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
2029 .false., c_null_ptr)
2033 if (
pe_size .gt. 1 .and. n .gt. 0)
then
2034 call gs%comm%nbwait_vec(gs%shared_gs_v, l, nc, op, gs%bcknd%gs_stream)
2037 gs%shared_gs(1:l) = gs%shared_gs_v(1:l)
2039 col_d = transfer(sv_addr, col_d)
2041 sync = .false., strm = gs%bcknd%gs_stream)
2043 call gs%bcknd%scatter(gs%shared_gs, l, gs%shared_dof_gs, u1, n, &
2044 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
2045 gs%shared_blk_off, .true., col_event)
2048 gs%shared_gs(1:l) = gs%shared_gs_v(l + 1:2*l)
2050 col_d = transfer(sv_addr + off_bytes, col_d)
2052 sync = .false., strm = gs%bcknd%gs_stream)
2054 call gs%bcknd%scatter(gs%shared_gs, l, gs%shared_dof_gs, u2, n, &
2055 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
2056 gs%shared_blk_off, .true., col_event)
2059 gs%shared_gs(1:l) = gs%shared_gs_v(2*l + 1:3*l)
2061 col_d = transfer(sv_addr + 2_c_intptr_t*off_bytes, col_d)
2063 sync = .false., strm = gs%bcknd%gs_stream)
2065 call gs%bcknd%scatter(gs%shared_gs, l, gs%shared_dof_gs, u3, n, &
2066 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
2067 gs%shared_blk_off, .true., col_event)