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(:)
100 type(partition_t),
intent(out) :: partition
101 integer(int64),
intent(in) :: np_global
102 type(mpi_grp_t),
intent(in) :: mpi_grp
105 integer(int64) :: iend
110 partition%mpi_grp = mpi_grp
111 partition%np_global = np_global
112 partition%npart = mpi_grp%size
113 partition%partno = mpi_grp%rank + 1
115 safe_allocate(partition%np_local_vec(1:partition%npart))
116 safe_allocate(partition%istart_vec(1:partition%npart))
119 do ipart = 1, partition%npart
122 partition%istart_vec(ipart) = (ipart-1) * np_global/partition%npart + 1
123 iend = ipart * np_global/partition%npart
124 partition%np_local_vec(ipart) =
i8_to_i4(iend - partition%istart_vec(ipart) + 1)
126 partition%istart = partition%istart_vec(partition%partno)
127 partition%np_local = partition%np_local_vec(partition%partno)
130 safe_allocate(partition%part(1:partition%np_local))
137 type(partition_t),
intent(inout) :: partition
141 safe_deallocate_a(partition%part)
142 safe_deallocate_a(partition%np_local_vec)
143 safe_deallocate_a(partition%istart_vec)
150 type(partition_t),
intent(inout) :: partition
151 integer,
intent(in) :: part(:)
155 partition%part(1:partition%np_local) = part(1:partition%np_local)
167 type(partition_t),
intent(in) :: partition
168 character(len=*),
intent(in) :: dir
169 character(len=*),
intent(in) :: filename
170 integer,
intent(out) :: ierr
173 character(len=MAX_PATH_LEN) :: full_filename
178 full_filename = trim(dir)//
'/'//trim(filename)
181 if (partition%mpi_grp%is_root())
then
183 if (err /= 0) ierr = ierr + 1
185 call partition%mpi_grp%bcast(ierr, 1, mpi_integer, 0)
187 assert(all(partition%part(:) > 0))
200 partition%np_local, partition%part, err)
202 if (err /= 0) ierr = ierr + 2
216 use iso_c_binding,
only: c_sizeof
218 character(len=*),
intent(in) :: dir
219 character(len=*),
intent(in) :: filename
220 integer,
intent(out) :: ierr
223 integer(int64) :: np, file_size
224 integer,
allocatable :: scounts(:)
225 integer(int64),
allocatable :: sdispls(:)
226 character(len=MAX_PATH_LEN) :: full_filename
231 full_filename = trim(dir)//
'/'//trim(filename)
234 write(
message(1),
'(a,i8)')
"Info: number of points in the partition (in root process) =",
size(partition%part)
243 assert(np == partition%np_global)
247 call mpi_world%bcast(err, 1, mpi_integer, 0)
248 call mpi_world%bcast(file_size, 1, mpi_integer8, 0)
256 if (file_size - 64 /= partition%np_global * c_sizeof(int(0)))
then
263 safe_allocate(scounts(1:partition%npart))
264 safe_allocate(sdispls(1:partition%npart))
266 scounts(:) = partition%np_local_vec(:)
267 sdispls(:) = partition%istart_vec(:) - 1
269 assert(sum(scounts(:)) == partition%np_global)
274 partition%np_local, partition%part, err)
276 if (err /= 0) ierr = ierr + 4
279 if (any(partition%part(:) <= 0))
then
280 write(
message(1),
'(a)')
'Internal error: some elements of partition are <= 0.'
281 write(
message(2),*)
'filename = ', full_filename
282 write(
message(3),*)
'scounts = ', scounts(:)
283 write(
message(4),*)
'sdispls = ', sdispls(:)
287 safe_deallocate_a(scounts)
288 safe_deallocate_a(sdispls)
296 integer(int64),
intent(out) :: istart
297 integer,
intent(out) :: np_local
301 istart = partition%istart
302 np_local = partition%np_local
312 integer,
intent(out) :: part_global(:)
313 integer,
optional,
intent(in) :: root
315 integer(int64),
allocatable :: rdispls(:)
316 integer,
allocatable :: rcounts(:)
320 safe_allocate(rdispls(1:partition%npart))
321 safe_allocate(rcounts(1:partition%npart))
323 rcounts(:) = partition%np_local_vec(:)
324 rdispls(:) = partition%istart_vec(:) - 1
326 assert(all(partition%part(1:partition%np_local) > 0))
328 if (
present(root))
then
329 call partition%mpi_grp%gatherv(partition%part, partition%np_local, mpi_integer, &
330 part_global, rcounts, rdispls, mpi_integer, root)
332 call partition%mpi_grp%allgatherv(partition%part, partition%np_local, mpi_integer, &
333 part_global, rcounts, rdispls, mpi_integer)
336 if (.not.
present(root) .or. partition%mpi_grp%is_root())
then
337 assert(all(part_global(:) > 0))
341 part_global = partition%part
344 safe_deallocate_a(rdispls)
345 safe_deallocate_a(rcounts)
357 integer,
intent(in) :: np
358 integer(int64),
intent(in) :: points(:)
359 integer,
intent(out) :: partno(:)
361 integer :: ip, nproc, rnp
362 integer(int64),
allocatable :: sbuffer(:), rbuffer(:)
363 integer,
allocatable :: scounts(:), rcounts(:)
364 integer,
allocatable :: sdispls(:), rdispls(:)
365 integer,
allocatable :: ipos(:), order(:)
369 safe_allocate(scounts(1:partition%npart))
370 safe_allocate(rcounts(1:partition%npart))
371 safe_allocate(sdispls(1:partition%npart))
372 safe_allocate(rdispls(1:partition%npart))
380 scounts(nproc) = scounts(nproc) + 1
385 call partition%mpi_grp%alltoall(scounts, 1, mpi_integer, &
386 rcounts, 1, mpi_integer)
391 do ip = 2, partition%npart
392 sdispls(ip) = sdispls(ip-1) + scounts(ip-1)
393 rdispls(ip) = rdispls(ip-1) + rcounts(ip-1)
398 safe_allocate(sbuffer(1:np))
399 safe_allocate(rbuffer(1:rnp))
402 safe_allocate(ipos(1:partition%npart))
403 safe_allocate(order(1:np))
410 ipos(nproc) = ipos(nproc) + 1
413 order(ip) = sdispls(nproc) + ipos(nproc)
414 sbuffer(order(ip)) = points(ip)
416 safe_deallocate_a(ipos)
419 call partition%mpi_grp%alltoallv(sbuffer, scounts, sdispls, mpi_integer8, &
420 rbuffer, rcounts, rdispls, mpi_integer8)
424 if (rbuffer(ip) == 0) cycle
425 rbuffer(ip) = partition%part(rbuffer(ip) - partition%istart + 1)
429 call partition%mpi_grp%alltoallv(rbuffer, rcounts, rdispls, mpi_integer8, &
430 sbuffer, scounts, sdispls, mpi_integer8)
434 partno(ip) =
i8_to_i4(sbuffer(order(ip)))
438 safe_deallocate_a(order)
439 safe_deallocate_a(sbuffer)
440 safe_deallocate_a(scounts)
441 safe_deallocate_a(sdispls)
442 safe_deallocate_a(rbuffer)
443 safe_deallocate_a(rcounts)
444 safe_deallocate_a(rdispls)
452 integer(int64),
intent(in) :: np
453 integer(int64),
intent(in) :: points(:)
454 integer,
intent(out) :: partno(:)
456 integer(int64) :: rounds, offset, iround
460 rounds = np/huge(0_int32)
461 do iround = 1, rounds
462 offset = (iround - 1)*huge(0_int32) + 1
464 partno(offset:offset+huge(0_int32)))
466 offset = rounds*huge(0_int32) + 1
478 integer,
contiguous,
intent(inout) :: np_local_vec(:)
480 integer,
allocatable :: np_local_vec_tmp(:)
485 assert(ubound(np_local_vec, 1) >= partition%npart)
486 assert(partition%npart > 0)
487 assert(all(partition%part(:) > 0))
488 safe_allocate(np_local_vec_tmp(1:partition%npart))
492 do ip = 1, partition%np_local
493 np_local_vec_tmp(partition%part(ip)) = np_local_vec_tmp(partition%part(ip)) + 1
497 call partition%mpi_grp%allreduce(np_local_vec_tmp, np_local_vec, partition%npart, mpi_integer, mpi_sum)
498 safe_deallocate_a(np_local_vec_tmp)
507 npart = partition%npart
514 integer,
intent(in) :: local_point
515 part = partition%part(local_point)
523 integer(int64),
intent(in) :: global_point
525 if (global_point == 0)
then
526 part = partition%partno
528 part =
i8_to_i4((partition%npart*global_point - 1)/partition%np_global + 1)
538 integer(int64),
contiguous,
intent(inout) :: rbuffer(:)
539 integer,
intent(out) :: np_local
542 integer(int64) :: istart
543 integer(int64),
allocatable :: sdispls(:), rdispls(:), sbuffer(:)
544 integer,
allocatable :: scounts(:), rcounts(:)
548 safe_allocate(sdispls(1:partition%npart))
549 safe_allocate(scounts(1:partition%npart))
550 safe_allocate(rcounts(1:partition%npart))
553 istart = partition%istart - 1
557 do ip = 1, partition%np_local
558 ipart = partition%part(ip)
559 scounts(ipart) = scounts(ipart) + 1
564 do ipart = 2, partition%npart
565 sdispls(ipart) = sdispls(ipart-1) + scounts(ipart-1)
569 np_local = sum(scounts)
571 safe_allocate(sbuffer(1:np_local))
573 ipart = partition%part(ip)
574 scounts(ipart) = scounts(ipart) + 1
575 sbuffer(sdispls(ipart) + scounts(ipart)) = ip + istart
579 call partition%mpi_grp%alltoall(scounts, 1, mpi_integer, &
580 rcounts, 1, mpi_integer)
583 np_local = sum(rcounts)
584 safe_allocate(rdispls(1:partition%npart))
585 assert(ubound(rbuffer, 1) >= np_local)
588 do ipart = 2, partition%npart
589 rdispls(ipart) = rcounts(ipart-1) + rdispls(ipart-1)
593 call partition%mpi_grp%alltoallv(sbuffer, scounts, sdispls, mpi_integer8, &
594 rbuffer, rcounts, rdispls, mpi_integer8)
596 safe_deallocate_a(sdispls)
597 safe_deallocate_a(scounts)
598 safe_deallocate_a(sbuffer)
599 safe_deallocate_a(rcounts)
600 safe_deallocate_a(rdispls)
subroutine, public io_binary_get_info(fname, np, file_size, ierr)
subroutine, public iwrite_header(fname, np_global, ierr)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, 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
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,...