76 type(mpi_grp_t) :: mpi_grp
77 integer(int64) :: np_global
79 integer,
allocatable :: np_local_vec(:)
80 integer(int64),
allocatable :: istart_vec(:)
85 integer(int64) :: istart
86 integer,
allocatable :: part(:)
101 type(partition_t),
intent(out) :: partition
102 integer(int64),
intent(in) :: np_global
103 type(mpi_grp_t),
intent(in) :: mpi_grp
106 integer(int64) :: iend
111 partition%mpi_grp = mpi_grp
112 partition%np_global = np_global
113 partition%npart = mpi_grp%size
114 partition%partno = mpi_grp%rank + 1
116 safe_allocate(partition%np_local_vec(1:partition%npart))
117 safe_allocate(partition%istart_vec(1:partition%npart))
120 do ipart = 1, partition%npart
123 partition%istart_vec(ipart) = (ipart-1) * np_global/partition%npart + 1
124 iend = ipart * np_global/partition%npart
125 partition%np_local_vec(ipart) =
i8_to_i4(iend - partition%istart_vec(ipart) + 1)
127 partition%istart = partition%istart_vec(partition%partno)
128 partition%np_local = partition%np_local_vec(partition%partno)
131 safe_allocate(partition%part(1:partition%np_local))
138 type(partition_t),
intent(inout) :: partition
142 safe_deallocate_a(partition%part)
149 type(partition_t),
intent(inout) :: partition
150 integer,
intent(in) :: part(:)
154 partition%part(1:partition%np_local) = part(1:partition%np_local)
166 type(partition_t),
intent(in) :: partition
167 character(len=*),
intent(in) :: dir
168 character(len=*),
intent(in) :: filename
169 integer,
intent(out) :: ierr
172 character(len=MAX_PATH_LEN) :: full_filename
177 full_filename = trim(dir)//
'/'//trim(filename)
182 if (err /= 0) ierr = ierr + 1
184 call partition%mpi_grp%bcast(ierr, 1, mpi_integer, 0)
186 assert(all(partition%part(:) > 0))
195 partition%np_local, partition%part, err)
197 if (err /= 0) ierr = ierr + 2
211 use iso_c_binding,
only: c_sizeof
213 character(len=*),
intent(in) :: dir
214 character(len=*),
intent(in) :: filename
215 integer,
intent(out) :: ierr
218 integer(int64) :: np, file_size
219 integer,
allocatable :: scounts(:)
220 integer(int64),
allocatable :: sdispls(:)
221 character(len=MAX_PATH_LEN) :: full_filename
226 full_filename = trim(dir)//
'/'//trim(filename)
229 write(
message(1),
'(a,i8)')
"Info: number of points in the partition (in root process) =",
size(partition%part)
235 assert(np == partition%np_global)
239 call mpi_world%bcast(err, 1, mpi_integer, 0)
240 call mpi_world%bcast(file_size, 1, mpi_integer8, 0)
248 if (file_size - 64 /= partition%np_global * c_sizeof(int(0)))
then
255 safe_allocate(scounts(1:partition%npart))
256 safe_allocate(sdispls(1:partition%npart))
258 scounts = partition%np_local_vec
259 sdispls = partition%istart_vec - 1
261 assert(sum(scounts(:)) == partition%np_global)
266 partition%np_local, partition%part, err)
268 if (err /= 0) ierr = ierr + 4
271 if (any(partition%part(:) <= 0))
then
272 write(
message(1),
'(a)')
'Internal error: some elements of partition are <= 0.'
273 write(
message(2),*)
'filename = ', full_filename
274 write(
message(3),*)
'scounts = ', scounts(:)
275 write(
message(4),*)
'sdispls = ', sdispls(:)
279 safe_deallocate_a(scounts)
280 safe_deallocate_a(sdispls)
288 integer(int64),
intent(out) :: istart
289 integer,
intent(out) :: np_local
293 istart = partition%istart
294 np_local = partition%np_local
304 integer,
intent(out) :: part_global(:)
305 integer,
optional,
intent(in) :: root
307 integer(int64),
allocatable :: rdispls(:)
308 integer,
allocatable :: rcounts(:)
312 safe_allocate(rdispls(1:partition%npart))
313 safe_allocate(rcounts(1:partition%npart))
315 rcounts = partition%np_local_vec
316 rdispls = partition%istart_vec - 1
318 assert(all(partition%part(1:partition%np_local) > 0))
320 if (
present(root))
then
321 call partition%mpi_grp%gatherv(partition%part, partition%np_local, mpi_integer, &
322 part_global, rcounts, rdispls, mpi_integer, root)
324 call partition%mpi_grp%allgatherv(partition%part, partition%np_local, mpi_integer, &
325 part_global, rcounts, rdispls, mpi_integer)
328 if (.not.
present(root) .or. partition%mpi_grp%rank == 0)
then
329 assert(all(part_global(:) > 0))
333 part_global = partition%part
336 safe_deallocate_a(rdispls)
337 safe_deallocate_a(rcounts)
349 integer,
intent(in) :: np
350 integer(int64),
intent(in) :: points(:)
351 integer,
intent(out) :: partno(:)
353 integer :: ip, nproc, rnp
354 integer(int64),
allocatable :: sbuffer(:), rbuffer(:)
355 integer,
allocatable :: scounts(:), rcounts(:)
356 integer,
allocatable :: sdispls(:), rdispls(:)
357 integer,
allocatable :: ipos(:), order(:)
361 safe_allocate(scounts(1:partition%npart))
362 safe_allocate(rcounts(1:partition%npart))
363 safe_allocate(sdispls(1:partition%npart))
364 safe_allocate(rdispls(1:partition%npart))
372 scounts(nproc) = scounts(nproc) + 1
377 call partition%mpi_grp%alltoall(scounts, 1, mpi_integer, &
378 rcounts, 1, mpi_integer)
383 do ip = 2, partition%npart
384 sdispls(ip) = sdispls(ip-1) + scounts(ip-1)
385 rdispls(ip) = rdispls(ip-1) + rcounts(ip-1)
390 safe_allocate(sbuffer(1:np))
391 safe_allocate(rbuffer(1:rnp))
394 safe_allocate(ipos(1:partition%npart))
395 safe_allocate(order(1:np))
402 ipos(nproc) = ipos(nproc) + 1
405 order(ip) = sdispls(nproc) + ipos(nproc)
406 sbuffer(order(ip)) = points(ip)
408 safe_deallocate_a(ipos)
411 call partition%mpi_grp%alltoallv(sbuffer, scounts, sdispls, mpi_integer8, &
412 rbuffer, rcounts, rdispls, mpi_integer8)
416 if (rbuffer(ip) == 0) cycle
417 rbuffer(ip) = partition%part(rbuffer(ip) - partition%istart + 1)
421 call partition%mpi_grp%alltoallv(rbuffer, rcounts, rdispls, mpi_integer8, &
422 sbuffer, scounts, sdispls, mpi_integer8)
426 partno(ip) =
i8_to_i4(sbuffer(order(ip)))
430 safe_deallocate_a(order)
431 safe_deallocate_a(sbuffer)
432 safe_deallocate_a(scounts)
433 safe_deallocate_a(sdispls)
434 safe_deallocate_a(rbuffer)
435 safe_deallocate_a(rcounts)
436 safe_deallocate_a(rdispls)
444 integer(int64),
intent(in) :: np
445 integer(int64),
intent(in) :: points(:)
446 integer,
intent(out) :: partno(:)
448 integer(int64) :: rounds, offset, iround
452 rounds = np/huge(0_int32)
453 do iround = 1, rounds
454 offset = (iround - 1)*huge(0_int32) + 1
456 partno(offset:offset+huge(0_int32)))
458 offset = rounds*huge(0_int32) + 1
470 integer,
contiguous,
intent(inout) :: np_local_vec(:)
472 integer,
allocatable :: np_local_vec_tmp(:)
477 assert(ubound(np_local_vec, 1) >= partition%npart)
478 assert(partition%npart > 0)
479 assert(all(partition%part(:) > 0))
480 safe_allocate(np_local_vec_tmp(1:partition%npart))
484 do ip = 1, partition%np_local
485 np_local_vec_tmp(partition%part(ip)) = np_local_vec_tmp(partition%part(ip)) + 1
489 call partition%mpi_grp%allreduce(np_local_vec_tmp, np_local_vec, partition%npart, mpi_integer, mpi_sum)
490 safe_deallocate_a(np_local_vec_tmp)
499 npart = partition%npart
506 integer,
intent(in) :: local_point
507 part = partition%part(local_point)
515 integer(int64),
intent(in) :: global_point
517 if (global_point == 0)
then
518 part = partition%partno
520 part =
i8_to_i4((partition%npart*global_point - 1)/partition%np_global + 1)
530 integer(int64),
contiguous,
intent(inout) :: rbuffer(:)
531 integer,
intent(out) :: np_local
534 integer(int64) :: istart
535 integer(int64),
allocatable :: sdispls(:), rdispls(:), sbuffer(:)
536 integer,
allocatable :: scounts(:), rcounts(:)
540 safe_allocate(sdispls(1:partition%npart))
541 safe_allocate(scounts(1:partition%npart))
542 safe_allocate(rcounts(1:partition%npart))
545 istart = partition%istart - 1
549 do ip = 1, partition%np_local
550 ipart = partition%part(ip)
551 scounts(ipart) = scounts(ipart) + 1
556 do ipart = 2, partition%npart
557 sdispls(ipart) = sdispls(ipart-1) + scounts(ipart-1)
561 np_local = sum(scounts)
563 safe_allocate(sbuffer(1:np_local))
565 ipart = partition%part(ip)
566 scounts(ipart) = scounts(ipart) + 1
567 sbuffer(sdispls(ipart) + scounts(ipart)) = ip + istart
571 call partition%mpi_grp%alltoall(scounts, 1, mpi_integer, &
572 rcounts, 1, mpi_integer)
575 np_local = sum(rcounts)
576 safe_allocate(rdispls(1:partition%npart))
577 assert(ubound(rbuffer, 1) >= np_local)
580 do ipart = 2, partition%npart
581 rdispls(ipart) = rcounts(ipart-1) + rdispls(ipart-1)
585 call partition%mpi_grp%alltoallv(sbuffer, scounts, sdispls, mpi_integer8, &
586 rbuffer, rcounts, rdispls, mpi_integer8)
588 safe_deallocate_a(sdispls)
589 safe_deallocate_a(scounts)
590 safe_deallocate_a(sbuffer)
591 safe_deallocate_a(rcounts)
592 safe_deallocate_a(rdispls)
subroutine, public io_binary_get_info(fname, np, file_size, ierr)
subroutine, public iwrite_header(fname, np_global, ierr)
subroutine, public messages_info(no_lines, iunit, verbose_limit, stress, all_nodes, namespace)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
integer, parameter, public c_mpi_file_read
subroutine, public mpi_debug_in(comm, index)
subroutine, public mpi_debug_out(comm, index)
integer, parameter, public c_mpi_file_write
logical function mpi_grp_is_root(grp)
Is the current MPI process of grpcomm, root.
type(mpi_grp_t), public mpi_world
subroutine, public partition_init(partition, np_global, mpi_grp)
initialize the partition table
pure integer function partition_get_number(partition, global_point)
Returns the partition number for a given global index If the index is zero, return local partition.
pure integer function, public partition_get_npart(partition)
Returns the total number of partitions.
subroutine, public partition_set(partition, part)
subroutine partition_get_partition_number_4(partition, np, points, partno)
Given a list of global indices, return the partition number where those points are stored....
subroutine, public partition_get_np_local(partition, np_local_vec)
Given the partition, returns the corresponding number of local points that each partition has.
pure integer function, public partition_get_part(partition, local_point)
Returns the partition of the local point.
subroutine partition_get_partition_number_8(partition, np, points, partno)
subroutine, public partition_dump(partition, dir, filename, ierr)
write the partition data
subroutine, public partition_get_local(partition, rbuffer, np_local)
Calculates the local vector of all partitions in parallel. Local vector stores the global point indic...
subroutine, public partition_end(partition)
subroutine, public partition_load(partition, dir, filename, ierr)
read the partition data
subroutine, public partition_get_local_size(partition, istart, np_local)
subroutine, public partition_get_global(partition, part_global, root)
Returns the global partition. If root is present, the partition is gathered only in that node....
The partition is an array that contains the mapping between some global index and a process,...