600 subroutine gs_init_mapping(gs)
601 type(gs_t),
target,
intent(inout) :: gs
602 type(
mesh_t),
pointer :: msh
604 type(
stack_i4_t),
target :: local_dof, dof_local, shared_dof, dof_shared
605 type(
stack_i4_t),
target :: local_face_dof, face_dof_local
606 type(
stack_i4_t),
target :: shared_face_dof, face_dof_shared
607 integer :: i, j, k, l, lx, ly, lz, max_id, max_sid, id, lid, dm_size
613 sdm => gs%shared_dofs
618 dm_size =
dofmap%size()/lx
620 call dm%init(dm_size, i)
624 call sdm%init(
dofmap%size(), i)
627 call local_dof%init()
628 call dof_local%init()
630 call local_face_dof%init()
631 call face_dof_local%init()
633 call shared_dof%init()
634 call dof_shared%init()
636 call shared_face_dof%init()
637 call face_dof_shared%init()
649 if (
dofmap%shared_dof(1, 1, 1, i))
then
652 call shared_dof%push(id)
654 call dof_shared%push(lid)
660 call local_dof%push(id)
661 call dof_local%push(lid)
668 if (
dofmap%shared_dof(lx, 1, 1, i))
then
670 call shared_dof%push(id)
671 call dof_shared%push(lid)
674 call local_dof%push(id)
675 call dof_local%push(lid)
679 if (
dofmap%shared_dof(1, ly, 1, i))
then
681 call shared_dof%push(id)
682 call dof_shared%push(lid)
685 call local_dof%push(id)
686 call dof_local%push(lid)
690 if (
dofmap%shared_dof(lx, ly, 1, i))
then
692 call shared_dof%push(id)
693 call dof_shared%push(lid)
696 call local_dof%push(id)
697 call dof_local%push(lid)
701 if (
dofmap%shared_dof(1, 1, lz, i))
then
703 call shared_dof%push(id)
704 call dof_shared%push(lid)
707 call local_dof%push(id)
708 call dof_local%push(lid)
712 if (
dofmap%shared_dof(lx, 1, lz, i))
then
714 call shared_dof%push(id)
715 call dof_shared%push(lid)
718 call local_dof%push(id)
719 call dof_local%push(lid)
723 if (
dofmap%shared_dof(1, ly, lz, i))
then
725 call shared_dof%push(id)
726 call dof_shared%push(lid)
729 call local_dof%push(id)
730 call dof_local%push(lid)
734 if (
dofmap%shared_dof(lx, ly, lz, i))
then
736 call shared_dof%push(id)
737 call dof_shared%push(lid)
740 call local_dof%push(id)
741 call dof_local%push(lid)
758 if (
dofmap%shared_dof(2, 1, 1, i))
then
761 call shared_dof%push(id)
763 call dof_shared%push(id)
768 call local_dof%push(id)
770 call dof_local%push(id)
773 if (
dofmap%shared_dof(2, 1, lz, i))
then
776 call shared_dof%push(id)
778 call dof_shared%push(id)
783 call local_dof%push(id)
785 call dof_local%push(id)
789 if (
dofmap%shared_dof(2, ly, 1, i))
then
792 call shared_dof%push(id)
794 call dof_shared%push(id)
800 call local_dof%push(id)
802 call dof_local%push(id)
805 if (
dofmap%shared_dof(2, ly, lz, i))
then
808 call shared_dof%push(id)
810 call dof_shared%push(id)
815 call local_dof%push(id)
817 call dof_local%push(id)
824 if (
dofmap%shared_dof(1, 2, 1, i))
then
827 call shared_dof%push(id)
829 call dof_shared%push(id)
834 call local_dof%push(id)
836 call dof_local%push(id)
839 if (
dofmap%shared_dof(1, 2, lz, i))
then
842 call shared_dof%push(id)
844 call dof_shared%push(id)
849 call local_dof%push(id)
851 call dof_local%push(id)
855 if (
dofmap%shared_dof(lx, 2, 1, i))
then
858 call shared_dof%push(id)
860 call dof_shared%push(id)
865 call local_dof%push(id)
867 call dof_local%push(id)
870 if (
dofmap%shared_dof(lx, 2, lz, i))
then
873 call shared_dof%push(id)
875 call dof_shared%push(id)
880 call local_dof%push(id)
882 call dof_local%push(id)
888 if (
dofmap%shared_dof(1, 1, 2, i))
then
891 call shared_dof%push(id)
893 call dof_shared%push(id)
898 call local_dof%push(id)
900 call dof_local%push(id)
904 if (
dofmap%shared_dof(lx, 1, 2, i))
then
907 call shared_dof%push(id)
909 call dof_shared%push(id)
914 call local_dof%push(id)
916 call dof_local%push(id)
920 if (
dofmap%shared_dof(1, ly, 2, i))
then
923 call shared_dof%push(id)
925 call dof_shared%push(id)
930 call local_dof%push(id)
932 call dof_local%push(id)
936 if (
dofmap%shared_dof(lx, ly, 2, i))
then
939 call shared_dof%push(id)
941 call dof_shared%push(id)
946 call local_dof%push(id)
948 call dof_local%push(id)
967 if (msh%facet_neigh(3, i) .ne. 0)
then
968 if (
dofmap%shared_dof(2, 1, 1, i))
then
971 call shared_face_dof%push(id)
973 call face_dof_shared%push(id)
978 call local_face_dof%push(id)
980 call face_dof_local%push(id)
985 if (msh%facet_neigh(4, i) .ne. 0)
then
986 if (
dofmap%shared_dof(2, ly, 1, i))
then
990 call shared_face_dof%push(id)
992 call face_dof_shared%push(id)
999 call local_face_dof%push(id)
1001 call face_dof_local%push(id)
1009 if (msh%facet_neigh(1, i) .ne. 0)
then
1010 if (
dofmap%shared_dof(1, 2, 1, i))
then
1013 call shared_face_dof%push(id)
1015 call face_dof_shared%push(id)
1020 call local_face_dof%push(id)
1022 call face_dof_local%push(id)
1027 if (msh%facet_neigh(2, i) .ne. 0)
then
1028 if (
dofmap%shared_dof(lx, 2, 1, i))
then
1032 call shared_face_dof%push(id)
1034 call face_dof_shared%push(id)
1040 call local_face_dof%push(id)
1042 call face_dof_local%push(id)
1051 if (msh%facet_neigh(1, i) .ne. 0)
then
1052 if (
dofmap%shared_dof(1, 2, 2, i))
then
1057 call shared_face_dof%push(id)
1059 call face_dof_shared%push(id)
1067 call local_face_dof%push(id)
1069 call face_dof_local%push(id)
1075 if (msh%facet_neigh(2, i) .ne. 0)
then
1076 if (
dofmap%shared_dof(lx, 2, 2, i))
then
1081 call shared_face_dof%push(id)
1083 call face_dof_shared%push(id)
1091 call local_face_dof%push(id)
1093 call face_dof_local%push(id)
1100 if (msh%facet_neigh(3, i) .ne. 0)
then
1101 if (
dofmap%shared_dof(2, 1, 2, i))
then
1106 call shared_face_dof%push(id)
1108 call face_dof_shared%push(id)
1116 call local_face_dof%push(id)
1118 call face_dof_local%push(id)
1124 if (msh%facet_neigh(4, i) .ne. 0)
then
1125 if (
dofmap%shared_dof(2, ly, 2, i))
then
1130 call shared_face_dof%push(id)
1132 call face_dof_shared%push(id)
1140 call local_face_dof%push(id)
1142 call face_dof_local%push(id)
1149 if (msh%facet_neigh(5, i) .ne. 0)
then
1150 if (
dofmap%shared_dof(2, 2, 1, i))
then
1155 call shared_face_dof%push(id)
1157 call face_dof_shared%push(id)
1165 call local_face_dof%push(id)
1167 call face_dof_local%push(id)
1173 if (msh%facet_neigh(6, i) .ne. 0)
then
1174 if (
dofmap%shared_dof(2, 2, lz, i))
then
1179 call shared_face_dof%push(id)
1181 call face_dof_shared%push(id)
1189 call local_face_dof%push(id)
1191 call face_dof_local%push(id)
1202 gs%nlocal = local_dof%size() + local_face_dof%size()
1203 gs%local_facet_offset = local_dof%size() + 1
1206 allocate(gs%local_dof_gs(gs%nlocal))
1213 select type (dof_array => local_dof%data)
1215 j = local_dof%size()
1217 gs%local_dof_gs(i) = dof_array(i)
1220 call local_dof%free()
1227 select type (dof_array => local_face_dof%data)
1229 do i = 1, local_face_dof%size()
1230 gs%local_dof_gs(i + j) = dof_array(i)
1233 call local_face_dof%free()
1236 allocate(gs%local_gs_dof(gs%nlocal))
1243 select type (dof_array => dof_local%data)
1245 j = dof_local%size()
1247 gs%local_gs_dof(i) = dof_array(i)
1250 call dof_local%free()
1255 select type (dof_array => face_dof_local%data)
1257 do i = 1, face_dof_local%size()
1258 gs%local_gs_dof(i+j) = dof_array(i)
1261 call face_dof_local%free()
1264 gs%nlocal, 1, gs%nlocal)
1267 gs%local_blk_off, gs%nlocal_blks, gs%nlocal, gs%local_facet_offset)
1270 allocate(gs%local_gs(gs%nlocal))
1272 gs%nshared = shared_dof%size() + shared_face_dof%size()
1273 gs%shared_facet_offset = shared_dof%size() + 1
1276 allocate(gs%shared_dof_gs(gs%nshared))
1283 select type (dof_array => shared_dof%data)
1285 j = shared_dof%size()
1287 gs%shared_dof_gs(i) = dof_array(i)
1290 call shared_dof%free()
1297 select type (dof_array => shared_face_dof%data)
1299 do i = 1, shared_face_dof%size()
1300 gs%shared_dof_gs(i + j) = dof_array(i)
1303 call shared_face_dof%free()
1306 allocate(gs%shared_gs_dof(gs%nshared))
1313 select type (dof_array => dof_shared%data)
1315 j = dof_shared%size()
1317 gs%shared_gs_dof(i) = dof_array(i)
1320 call dof_shared%free()
1325 select type (dof_array => face_dof_shared%data)
1327 do i = 1, face_dof_shared%size()
1328 gs%shared_gs_dof(i + j) = dof_array(i)
1331 call face_dof_shared%free()
1334 allocate(gs%shared_gs(gs%nshared))
1338 allocate(gs%shared_gs_v(
max(1,
gs_vec_nc * gs%nshared)))
1340 call device_map(gs%shared_gs_v, gs%shared_gs_v_d, &
1344 if (gs%nshared .gt. 0)
then
1346 gs%nshared, 1, gs%nshared)
1348 call gs_find_blks(gs%shared_dof_gs, gs%shared_blk_len, &
1349 gs%shared_blk_off, gs%nshared_blks, gs%nshared, &
1350 gs%shared_facet_offset)
1365 integer(kind=i8),
intent(inout) :: dof
1366 integer,
intent(inout) :: max_id
1369 if (map_%get(dof, id) .gt. 0)
then
1371 call map_%set(dof, max_id)
1379 integer,
intent(inout) :: n
1380 integer,
dimension(n),
intent(inout) :: dg
1381 integer,
dimension(n),
intent(inout) :: gd
1383 integer :: tmp, i, j, pivot
1387 pivot = dg((lo + hi) / 2)
1391 if (dg(i) .ge. pivot)
exit
1396 if (dg(j) .le. pivot)
exit
1407 else if (i .eq. j)
then
1421 integer,
intent(in) :: n
1422 integer,
intent(in) :: m
1423 integer,
dimension(n),
intent(inout) :: dg
1424 integer,
allocatable,
intent(inout) :: blk_len(:)
1425 integer,
allocatable,
intent(inout) :: blk_off(:)
1426 integer,
intent(inout) :: nblks
1428 integer :: id, count
1437 do while ( j+1 .le. n .and. dg(j+1) .eq. id)
1441 call blks%push(count)
1445 select type (blk_array => blks%data)
1448 allocate(blk_len(nblks))
1450 blk_len(i) = blk_array(i)
1452 allocate(blk_off(nblks))
1455 blk_off(i) = blk_off(i - 1) + blk_len(i - 1)
1797 subroutine gs_op_vector3(gs, u1, u2, u3, n, op, event)
1798 class(gs_t),
intent(inout) :: gs
1799 integer,
intent(in) :: n
1800 real(kind=
rp),
dimension(n),
intent(inout) :: u1, u2, u3
1801 type(c_ptr),
optional,
intent(inout) :: event
1802 integer :: m, l, op, lo, so, tid
1803 integer,
parameter :: nc = 3
1804 type(c_ptr) :: scatter_event
1808 if (.not. gs%comm%vec_supported)
then
1809 if (
present(event))
then
1810 call gs_op_vector(gs, u1, n, op, event)
1811 call gs_op_vector(gs, u2, n, op, event)
1812 call gs_op_vector(gs, u3, n, op, event)
1814 call gs_op_vector(gs, u1, n, op)
1815 call gs_op_vector(gs, u2, n, op)
1816 call gs_op_vector(gs, u3, n, op)
1821 lo = gs%local_facet_offset
1822 so = -gs%shared_facet_offset
1829 scatter_event = c_null_ptr
1830 if (
present(event)) scatter_event = event
1840 if (
pe_size .gt. 1 .and. n .gt. 0)
then
1841 call gs%comm%nbrecv_vec(tid, nc)
1842 call gs%bcknd%gather(gs%shared_gs_v(1), l, so, gs%shared_dof_gs, &
1843 u1, n, gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1844 gs%shared_blk_off, op, .true.)
1845 call gs%bcknd%gather(gs%shared_gs_v(l + 1), l, so, &
1846 gs%shared_dof_gs, u2, n, gs%shared_gs_dof, gs%nshared_blks, &
1847 gs%shared_blk_len, gs%shared_blk_off, op, .true.)
1848 call gs%bcknd%gather(gs%shared_gs_v(2*l + 1), l, so, &
1849 gs%shared_dof_gs, u3, n, gs%shared_gs_dof, gs%nshared_blks, &
1850 gs%shared_blk_len, gs%shared_blk_off, op, .true.)
1851 call gs%comm%nbsend_vec(gs%shared_gs_v, l, nc, tid, &
1852 gs%bcknd%gather_event, gs%bcknd%gs_stream)
1857 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u1, n, &
1858 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1859 gs%local_blk_off, op, .false.)
1860 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u1, n, &
1861 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1862 gs%local_blk_off, .false., c_null_ptr)
1863 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u2, n, &
1864 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1865 gs%local_blk_off, op, .false.)
1866 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u2, n, &
1867 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1868 gs%local_blk_off, .false., c_null_ptr)
1869 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u3, n, &
1870 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1871 gs%local_blk_off, op, .false.)
1872 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u3, n, &
1873 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, &
1874 gs%local_blk_off, .false., c_null_ptr)
1877 if (
pe_size .gt. 1 .and. n .gt. 0)
then
1878 call gs%comm%nbwait_vec(gs%shared_gs_v, l, nc, op, &
1880 call gs%bcknd%scatter(gs%shared_gs_v(1), l, gs%shared_dof_gs, u1, &
1881 n, gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1882 gs%shared_blk_off, .true., scatter_event)
1883 call gs%bcknd%scatter(gs%shared_gs_v(l + 1), l, gs%shared_dof_gs, &
1884 u2, n, gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1885 gs%shared_blk_off, .true., scatter_event)
1886 call gs%bcknd%scatter(gs%shared_gs_v(2*l + 1), l, &
1887 gs%shared_dof_gs, u3, n, gs%shared_gs_dof, gs%nshared_blks, &
1888 gs%shared_blk_len, gs%shared_blk_off, .true., scatter_event)
1896 call gs_op_r3_device(gs, u1, u2, u3, n, op, nc, lo, so, m, l, tid, &
1912 subroutine gs_op_r3_device(gs, u1, u2, u3, n, op, nc, lo, so, m, l, tid, &
1914 class(gs_t),
intent(inout) :: gs
1915 integer,
intent(in) :: n, op, nc, lo, so, m, l, tid
1916 real(kind=
rp),
dimension(n),
intent(inout) :: u1, u2, u3
1917 type(c_ptr),
intent(inout) :: scatter_event
1918 type(c_ptr) :: sgs_d, col_d, col_event
1919 integer(c_intptr_t) :: sv_addr, off_bytes
1920 integer(c_size_t) :: colbytes
1921 real(c_rp) :: rp_dummy
1926 select type (b => gs%bcknd)
1928 on_host = b%shared_on_host
1929 sgs_d = b%shared_gs_d
1932 sv_addr = transfer(gs%shared_gs_v_d, sv_addr)
1933 colbytes = c_sizeof(rp_dummy) * int(l, c_size_t)
1934 off_bytes = int(l, c_intptr_t) * int(c_sizeof(rp_dummy), c_intptr_t)
1942 col_event = c_null_ptr
1944 col_event = scatter_event
1947 if (
pe_size .gt. 1 .and. n .gt. 0)
then
1948 call gs%comm%nbrecv_vec(tid, nc)
1952 call gs%bcknd%gather(gs%shared_gs, l, so, gs%shared_dof_gs, u1, n, &
1953 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1954 gs%shared_blk_off, op, .true.)
1957 gs%shared_gs_v(1:l) = gs%shared_gs(1:l)
1960 if (.not. c_associated(sgs_d))
then
1961 select type (b => gs%bcknd)
1963 sgs_d = b%shared_gs_d
1966 col_d = transfer(sv_addr, col_d)
1968 sync = .false., strm = gs%bcknd%gs_stream)
1971 call gs%bcknd%gather(gs%shared_gs, l, so, gs%shared_dof_gs, u2, n, &
1972 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1973 gs%shared_blk_off, op, .true.)
1975 gs%shared_gs_v(l + 1:2*l) = gs%shared_gs(1:l)
1977 col_d = transfer(sv_addr + off_bytes, col_d)
1979 sync = .false., strm = gs%bcknd%gs_stream)
1982 call gs%bcknd%gather(gs%shared_gs, l, so, gs%shared_dof_gs, u3, n, &
1983 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
1984 gs%shared_blk_off, op, .true.)
1986 gs%shared_gs_v(2*l + 1:3*l) = gs%shared_gs(1:l)
1988 col_d = transfer(sv_addr + 2_c_intptr_t*off_bytes, col_d)
1990 sync = .false., strm = gs%bcknd%gs_stream)
1998 call gs%comm%nbsend_vec(gs%shared_gs_v, l, nc, tid, &
1999 gs%bcknd%gather_event, gs%bcknd%gs_stream)
2003 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u1, n, &
2004 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
2006 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u1, n, &
2007 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
2008 .false., c_null_ptr)
2009 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u2, n, &
2010 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
2012 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u2, n, &
2013 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
2014 .false., c_null_ptr)
2015 call gs%bcknd%gather(gs%local_gs, m, lo, gs%local_dof_gs, u3, n, &
2016 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
2018 call gs%bcknd%scatter(gs%local_gs, m, gs%local_dof_gs, u3, n, &
2019 gs%local_gs_dof, gs%nlocal_blks, gs%local_blk_len, gs%local_blk_off, &
2020 .false., c_null_ptr)
2024 if (
pe_size .gt. 1 .and. n .gt. 0)
then
2025 call gs%comm%nbwait_vec(gs%shared_gs_v, l, nc, op, gs%bcknd%gs_stream)
2028 gs%shared_gs(1:l) = gs%shared_gs_v(1:l)
2030 col_d = transfer(sv_addr, col_d)
2032 sync = .false., strm = gs%bcknd%gs_stream)
2034 call gs%bcknd%scatter(gs%shared_gs, l, gs%shared_dof_gs, u1, n, &
2035 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
2036 gs%shared_blk_off, .true., col_event)
2039 gs%shared_gs(1:l) = gs%shared_gs_v(l + 1:2*l)
2041 col_d = transfer(sv_addr + off_bytes, col_d)
2043 sync = .false., strm = gs%bcknd%gs_stream)
2045 call gs%bcknd%scatter(gs%shared_gs, l, gs%shared_dof_gs, u2, n, &
2046 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
2047 gs%shared_blk_off, .true., col_event)
2050 gs%shared_gs(1:l) = gs%shared_gs_v(2*l + 1:3*l)
2052 col_d = transfer(sv_addr + 2_c_intptr_t*off_bytes, col_d)
2054 sync = .false., strm = gs%bcknd%gs_stream)
2056 call gs%bcknd%scatter(gs%shared_gs, l, gs%shared_dof_gs, u3, n, &
2057 gs%shared_gs_dof, gs%nshared_blks, gs%shared_blk_len, &
2058 gs%shared_blk_off, .true., col_event)