635 subroutine gs_init_mapping(gs)
636 type(gs_t),
target,
intent(inout) :: gs
637 type(
mesh_t),
pointer :: msh
639 type(
stack_i4_t),
target :: local_dof, dof_local, shared_dof, dof_shared
640 type(
stack_i4_t),
target :: local_face_dof, face_dof_local
641 type(
stack_i4_t),
target :: shared_face_dof, face_dof_shared
642 integer :: i, j, k, l, lx, ly, lz, max_id, max_sid, id, lid, dm_size
649 sdm => gs%shared_dofs
654 dm_size =
dofmap%size()/lx
659 sdm_size = min(count(
dofmap%shared_dof),
dofmap%size() / 2) * 2
661 call dm%init(dm_size, i)
665 call sdm%init(
max(sdm_size, 1), i)
668 call local_dof%init()
669 call dof_local%init()
671 call local_face_dof%init()
672 call face_dof_local%init()
674 call shared_dof%init()
675 call dof_shared%init()
677 call shared_face_dof%init()
678 call face_dof_shared%init()
690 if (
dofmap%shared_dof(1, 1, 1, i))
then
693 call shared_dof%push(id)
695 call dof_shared%push(lid)
701 call local_dof%push(id)
702 call dof_local%push(lid)
709 if (
dofmap%shared_dof(lx, 1, 1, i))
then
711 call shared_dof%push(id)
712 call dof_shared%push(lid)
715 call local_dof%push(id)
716 call dof_local%push(lid)
720 if (
dofmap%shared_dof(1, ly, 1, i))
then
722 call shared_dof%push(id)
723 call dof_shared%push(lid)
726 call local_dof%push(id)
727 call dof_local%push(lid)
731 if (
dofmap%shared_dof(lx, ly, 1, i))
then
733 call shared_dof%push(id)
734 call dof_shared%push(lid)
737 call local_dof%push(id)
738 call dof_local%push(lid)
742 if (
dofmap%shared_dof(1, 1, lz, i))
then
744 call shared_dof%push(id)
745 call dof_shared%push(lid)
748 call local_dof%push(id)
749 call dof_local%push(lid)
753 if (
dofmap%shared_dof(lx, 1, lz, i))
then
755 call shared_dof%push(id)
756 call dof_shared%push(lid)
759 call local_dof%push(id)
760 call dof_local%push(lid)
764 if (
dofmap%shared_dof(1, ly, lz, i))
then
766 call shared_dof%push(id)
767 call dof_shared%push(lid)
770 call local_dof%push(id)
771 call dof_local%push(lid)
775 if (
dofmap%shared_dof(lx, ly, lz, i))
then
777 call shared_dof%push(id)
778 call dof_shared%push(lid)
781 call local_dof%push(id)
782 call dof_local%push(lid)
799 if (
dofmap%shared_dof(2, 1, 1, i))
then
802 call shared_dof%push(id)
804 call dof_shared%push(id)
809 call local_dof%push(id)
811 call dof_local%push(id)
814 if (
dofmap%shared_dof(2, 1, 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)
830 if (
dofmap%shared_dof(2, ly, 1, i))
then
833 call shared_dof%push(id)
835 call dof_shared%push(id)
841 call local_dof%push(id)
843 call dof_local%push(id)
846 if (
dofmap%shared_dof(2, ly, lz, i))
then
849 call shared_dof%push(id)
851 call dof_shared%push(id)
856 call local_dof%push(id)
858 call dof_local%push(id)
865 if (
dofmap%shared_dof(1, 2, 1, i))
then
868 call shared_dof%push(id)
870 call dof_shared%push(id)
875 call local_dof%push(id)
877 call dof_local%push(id)
880 if (
dofmap%shared_dof(1, 2, lz, i))
then
883 call shared_dof%push(id)
885 call dof_shared%push(id)
890 call local_dof%push(id)
892 call dof_local%push(id)
896 if (
dofmap%shared_dof(lx, 2, 1, i))
then
899 call shared_dof%push(id)
901 call dof_shared%push(id)
906 call local_dof%push(id)
908 call dof_local%push(id)
911 if (
dofmap%shared_dof(lx, 2, lz, i))
then
914 call shared_dof%push(id)
916 call dof_shared%push(id)
921 call local_dof%push(id)
923 call dof_local%push(id)
929 if (
dofmap%shared_dof(1, 1, 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, 1, 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)
961 if (
dofmap%shared_dof(1, ly, 2, i))
then
964 call shared_dof%push(id)
966 call dof_shared%push(id)
971 call local_dof%push(id)
973 call dof_local%push(id)
977 if (
dofmap%shared_dof(lx, ly, 2, i))
then
980 call shared_dof%push(id)
982 call dof_shared%push(id)
987 call local_dof%push(id)
989 call dof_local%push(id)
1008 if (msh%facet_neigh(3, i) .ne. 0)
then
1009 if (
dofmap%shared_dof(2, 1, 1, i))
then
1012 call shared_face_dof%push(id)
1014 call face_dof_shared%push(id)
1019 call local_face_dof%push(id)
1021 call face_dof_local%push(id)
1026 if (msh%facet_neigh(4, i) .ne. 0)
then
1027 if (
dofmap%shared_dof(2, ly, 1, i))
then
1031 call shared_face_dof%push(id)
1033 call face_dof_shared%push(id)
1040 call local_face_dof%push(id)
1042 call face_dof_local%push(id)
1050 if (msh%facet_neigh(1, i) .ne. 0)
then
1051 if (
dofmap%shared_dof(1, 2, 1, i))
then
1054 call shared_face_dof%push(id)
1056 call face_dof_shared%push(id)
1061 call local_face_dof%push(id)
1063 call face_dof_local%push(id)
1068 if (msh%facet_neigh(2, i) .ne. 0)
then
1069 if (
dofmap%shared_dof(lx, 2, 1, i))
then
1073 call shared_face_dof%push(id)
1075 call face_dof_shared%push(id)
1081 call local_face_dof%push(id)
1083 call face_dof_local%push(id)
1092 if (msh%facet_neigh(1, i) .ne. 0)
then
1093 if (
dofmap%shared_dof(1, 2, 2, i))
then
1098 call shared_face_dof%push(id)
1100 call face_dof_shared%push(id)
1108 call local_face_dof%push(id)
1110 call face_dof_local%push(id)
1116 if (msh%facet_neigh(2, i) .ne. 0)
then
1117 if (
dofmap%shared_dof(lx, 2, 2, i))
then
1122 call shared_face_dof%push(id)
1124 call face_dof_shared%push(id)
1132 call local_face_dof%push(id)
1134 call face_dof_local%push(id)
1141 if (msh%facet_neigh(3, i) .ne. 0)
then
1142 if (
dofmap%shared_dof(2, 1, 2, i))
then
1147 call shared_face_dof%push(id)
1149 call face_dof_shared%push(id)
1157 call local_face_dof%push(id)
1159 call face_dof_local%push(id)
1165 if (msh%facet_neigh(4, i) .ne. 0)
then
1166 if (
dofmap%shared_dof(2, ly, 2, i))
then
1171 call shared_face_dof%push(id)
1173 call face_dof_shared%push(id)
1181 call local_face_dof%push(id)
1183 call face_dof_local%push(id)
1190 if (msh%facet_neigh(5, i) .ne. 0)
then
1191 if (
dofmap%shared_dof(2, 2, 1, i))
then
1196 call shared_face_dof%push(id)
1198 call face_dof_shared%push(id)
1206 call local_face_dof%push(id)
1208 call face_dof_local%push(id)
1214 if (msh%facet_neigh(6, i) .ne. 0)
then
1215 if (
dofmap%shared_dof(2, 2, lz, i))
then
1220 call shared_face_dof%push(id)
1222 call face_dof_shared%push(id)
1230 call local_face_dof%push(id)
1232 call face_dof_local%push(id)
1243 gs%nlocal = local_dof%size() + local_face_dof%size()
1244 gs%local_facet_offset = local_dof%size() + 1
1247 allocate(gs%local_dof_gs(gs%nlocal))
1254 select type (dof_array => local_dof%data)
1256 j = local_dof%size()
1258 gs%local_dof_gs(i) = dof_array(i)
1261 call local_dof%free()
1268 select type (dof_array => local_face_dof%data)
1270 do i = 1, local_face_dof%size()
1271 gs%local_dof_gs(i + j) = dof_array(i)
1274 call local_face_dof%free()
1277 allocate(gs%local_gs_dof(gs%nlocal))
1284 select type (dof_array => dof_local%data)
1286 j = dof_local%size()
1288 gs%local_gs_dof(i) = dof_array(i)
1291 call dof_local%free()
1296 select type (dof_array => face_dof_local%data)
1298 do i = 1, face_dof_local%size()
1299 gs%local_gs_dof(i+j) = dof_array(i)
1302 call face_dof_local%free()
1305 gs%nlocal, 1, gs%nlocal)
1308 gs%local_blk_off, gs%nlocal_blks, gs%nlocal, gs%local_facet_offset)
1311 allocate(gs%local_gs(gs%nlocal))
1313 gs%nshared = shared_dof%size() + shared_face_dof%size()
1314 gs%shared_facet_offset = shared_dof%size() + 1
1317 allocate(gs%shared_dof_gs(gs%nshared))
1324 select type (dof_array => shared_dof%data)
1326 j = shared_dof%size()
1328 gs%shared_dof_gs(i) = dof_array(i)
1331 call shared_dof%free()
1338 select type (dof_array => shared_face_dof%data)
1340 do i = 1, shared_face_dof%size()
1341 gs%shared_dof_gs(i + j) = dof_array(i)
1344 call shared_face_dof%free()
1347 allocate(gs%shared_gs_dof(gs%nshared))
1354 select type (dof_array => dof_shared%data)
1356 j = dof_shared%size()
1358 gs%shared_gs_dof(i) = dof_array(i)
1361 call dof_shared%free()
1366 select type (dof_array => face_dof_shared%data)
1368 do i = 1, face_dof_shared%size()
1369 gs%shared_gs_dof(i + j) = dof_array(i)
1372 call face_dof_shared%free()
1375 allocate(gs%shared_gs(gs%nshared))
1380 if (gs%nshared .gt. 0)
then
1382 gs%nshared, 1, gs%nshared)
1384 call gs_find_blks(gs%shared_dof_gs, gs%shared_blk_len, &
1385 gs%shared_blk_off, gs%nshared_blks, gs%nshared, &
1386 gs%shared_facet_offset)
1401 integer(kind=i8),
intent(inout) :: dof
1402 integer,
intent(inout) :: max_id
1405 if (map_%get(dof, id) .gt. 0)
then
1407 call map_%set(dof, max_id)
1415 integer,
intent(inout) :: n
1416 integer,
dimension(n),
intent(inout) :: dg
1417 integer,
dimension(n),
intent(inout) :: gd
1419 integer :: tmp, i, j, pivot
1423 pivot = dg((lo + hi) / 2)
1427 if (dg(i) .ge. pivot)
exit
1432 if (dg(j) .le. pivot)
exit
1443 else if (i .eq. j)
then
1457 integer,
intent(in) :: n
1458 integer,
intent(in) :: m
1459 integer,
dimension(n),
intent(inout) :: dg
1460 integer,
allocatable,
intent(inout) :: blk_len(:)
1461 integer,
allocatable,
intent(inout) :: blk_off(:)
1462 integer,
intent(inout) :: nblks
1464 integer :: id, count
1473 do while ( j+1 .le. n .and. dg(j+1) .eq. id)
1477 call blks%push(count)
1481 select type (blk_array => blks%data)
1484 allocate(blk_len(nblks))
1486 blk_len(i) = blk_array(i)
1488 allocate(blk_off(nblks))
1491 blk_off(i) = blk_off(i - 1) + blk_len(i - 1)
1833 subroutine gs_op_vector3(gs, u1, u2, u3, n, op, event)
1834 class(gs_t),
intent(inout) :: gs
1835 integer,
intent(in) :: n
1836 real(kind=
rp),
dimension(n),
intent(inout) :: u1, u2, u3
1837 type(c_ptr),
optional,
intent(inout) :: event
1838 integer :: m, l, op, lo, so, tid
1839 integer,
parameter :: nc = 3
1840 type(c_ptr) :: scatter_event
1844 if (.not. gs%comm%vec_supported)
then
1845 if (
present(event))
then
1846 call gs_op_vector(gs, u1, n, op, event)
1847 call gs_op_vector(gs, u2, n, op, event)
1848 call gs_op_vector(gs, u3, n, op, event)
1850 call gs_op_vector(gs, u1, n, op)
1851 call gs_op_vector(gs, u2, n, op)
1852 call gs_op_vector(gs, u3, n, op)
1861 if (
pe_size .gt. 1 .and. n .gt. 0)
call gs_vec_alloc(gs)
1863 lo = gs%local_facet_offset
1864 so = -gs%shared_facet_offset
1871 scatter_event = c_null_ptr
1872 if (
present(event)) scatter_event = event
1882 if (
pe_size .gt. 1 .and. n .gt. 0)
then
1883 call gs%comm%nbrecv_vec(tid, nc)
1884 call gs%bcknd%gather(gs%shared_gs_v(1), l, so, gs%shared_dof_gs, &
1885 u1, n, gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1886 gs%shared_blk_off, op, .true.)
1887 call gs%bcknd%gather(gs%shared_gs_v(l + 1), l, so, &
1888 gs%shared_dof_gs, u2, n, gs%shared_gs_dof, gs%nshared_blks, &
1889 gs%shared_blk_len, gs%shared_blk_off, op, .true.)
1890 call gs%bcknd%gather(gs%shared_gs_v(2*l + 1), l, so, &
1891 gs%shared_dof_gs, u3, n, gs%shared_gs_dof, gs%nshared_blks, &
1892 gs%shared_blk_len, gs%shared_blk_off, op, .true.)
1893 call gs%comm%nbsend_vec(gs%shared_gs_v, l, nc, tid, &
1894 gs%bcknd%gather_event, gs%bcknd%gs_stream)
1899 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u1, n, &
1900 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1901 gs%local_blk_off, op, .false.)
1902 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u1, n, &
1903 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1904 gs%local_blk_off, .false., c_null_ptr)
1905 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u2, n, &
1906 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1907 gs%local_blk_off, op, .false.)
1908 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u2, n, &
1909 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1910 gs%local_blk_off, .false., c_null_ptr)
1911 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u3, n, &
1912 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1913 gs%local_blk_off, op, .false.)
1914 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u3, n, &
1915 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1916 gs%local_blk_off, .false., c_null_ptr)
1919 if (
pe_size .gt. 1 .and. n .gt. 0)
then
1920 call gs%comm%nbwait_vec(gs%shared_gs_v, l, nc, op, &
1922 call gs%bcknd%scatter(gs%shared_gs_v(1), l, gs%shared_dof_gs, u1, &
1923 n, gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1924 gs%shared_blk_off, .true., scatter_event)
1925 call gs%bcknd%scatter(gs%shared_gs_v(l + 1), l, gs%shared_dof_gs, &
1926 u2, n, gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1927 gs%shared_blk_off, .true., scatter_event)
1928 call gs%bcknd%scatter(gs%shared_gs_v(2*l + 1), l, &
1929 gs%shared_dof_gs, u3, n, gs%shared_gs_dof, gs%nshared_blks, &
1930 gs%shared_blk_len, gs%shared_blk_off, .true., scatter_event)
1938 call gs_op_r3_device(gs, u1, u2, u3, n, op, nc, lo, so, m, l, tid, &
1954 subroutine gs_op_r3_device(gs, u1, u2, u3, n, op, nc, lo, so, m, l, tid, &
1956 class(gs_t),
intent(inout) :: gs
1957 integer,
intent(in) :: n, op, nc, lo, so, m, l, tid
1958 real(kind=
rp),
dimension(n),
intent(inout) :: u1, u2, u3
1959 type(c_ptr),
intent(inout) :: scatter_event
1960 type(c_ptr) :: sgs_d, col_d, col_event
1961 integer(c_intptr_t) :: sv_addr, off_bytes
1962 integer(c_size_t) :: colbytes
1963 real(c_rp) :: rp_dummy
1968 select type (b => gs%bcknd)
1970 on_host = b%shared_on_host
1971 sgs_d = b%shared_gs_d
1974 sv_addr = transfer(gs%shared_gs_v_d, sv_addr)
1975 colbytes = c_sizeof(rp_dummy) * int(l, c_size_t)
1976 off_bytes = int(l, c_intptr_t) * int(c_sizeof(rp_dummy), c_intptr_t)
1984 col_event = c_null_ptr
1986 col_event = scatter_event
1989 if (
pe_size .gt. 1 .and. n .gt. 0)
then
1990 call gs%comm%nbrecv_vec(tid, nc)
1994 call gs%bcknd%gather(gs%shared_gs, l, so, gs%shared_dof_gs, u1, n, &
1995 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1996 gs%shared_blk_off, op, .true.)
1999 gs%shared_gs_v(1:l) = gs%shared_gs(1:l)
2002 if (.not. c_associated(sgs_d))
then
2003 select type (b => gs%bcknd)
2005 sgs_d = b%shared_gs_d
2008 col_d = transfer(sv_addr, col_d)
2010 sync = .false., strm = gs%bcknd%gs_stream)
2013 call gs%bcknd%gather(gs%shared_gs, l, so, gs%shared_dof_gs, u2, n, &
2014 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
2015 gs%shared_blk_off, op, .true.)
2017 gs%shared_gs_v(l + 1:2*l) = gs%shared_gs(1:l)
2019 col_d = transfer(sv_addr + off_bytes, col_d)
2021 sync = .false., strm = gs%bcknd%gs_stream)
2024 call gs%bcknd%gather(gs%shared_gs, l, so, gs%shared_dof_gs, u3, n, &
2025 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
2026 gs%shared_blk_off, op, .true.)
2028 gs%shared_gs_v(2*l + 1:3*l) = gs%shared_gs(1:l)
2030 col_d = transfer(sv_addr + 2_c_intptr_t*off_bytes, col_d)
2032 sync = .false., strm = gs%bcknd%gs_stream)
2040 call gs%comm%nbsend_vec(gs%shared_gs_v, l, nc, tid, &
2041 gs%bcknd%gather_event, gs%bcknd%gs_stream)
2045 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u1, n, &
2046 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
2048 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u1, n, &
2049 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
2050 .false., c_null_ptr)
2051 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u2, n, &
2052 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
2054 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u2, n, &
2055 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
2056 .false., c_null_ptr)
2057 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u3, n, &
2058 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
2060 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u3, n, &
2061 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
2062 .false., c_null_ptr)
2066 if (
pe_size .gt. 1 .and. n .gt. 0)
then
2067 call gs%comm%nbwait_vec(gs%shared_gs_v, l, nc, op, gs%bcknd%gs_stream)
2070 gs%shared_gs(1:l) = gs%shared_gs_v(1:l)
2072 col_d = transfer(sv_addr, col_d)
2074 sync = .false., strm = gs%bcknd%gs_stream)
2076 call gs%bcknd%scatter(gs%shared_gs, l, gs%shared_dof_gs, u1, n, &
2077 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
2078 gs%shared_blk_off, .true., col_event)
2081 gs%shared_gs(1:l) = gs%shared_gs_v(l + 1:2*l)
2083 col_d = transfer(sv_addr + off_bytes, col_d)
2085 sync = .false., strm = gs%bcknd%gs_stream)
2087 call gs%bcknd%scatter(gs%shared_gs, l, gs%shared_dof_gs, u2, n, &
2088 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
2089 gs%shared_blk_off, .true., col_event)
2092 gs%shared_gs(1:l) = gs%shared_gs_v(2*l + 1:3*l)
2094 col_d = transfer(sv_addr + 2_c_intptr_t*off_bytes, col_d)
2096 sync = .false., strm = gs%bcknd%gs_stream)
2098 call gs%bcknd%scatter(gs%shared_gs, l, gs%shared_dof_gs, u3, n, &
2099 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
2100 gs%shared_blk_off, .true., col_event)