// @HEADER // ***************************************************************************** // Zoltan Toolkit for Load-balancing, Partitioning, Ordering and Coloring // // Copyright 2012 NTESS and the Zoltan contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #include #include #include #include "par_tflops_special_const.h" #include "zoltan_mem.h" #include "zz_const.h" #ifdef __cplusplus /* if C++, define the rest of this header file as extern C */ extern "C" { #endif /* Generic Tflops_special routines to avoid certain types of collective communication routines. */ void Zoltan_RB_scan_double( double *wtok, /* in: local weight */ double *wtupto, /* out: sum of weights for processors <= rank */ int count, /* number of elements to scan */ MPI_Comm local_comm, /* MPI Communicator */ int proc, /* global processor number */ int rank, /* rank in this partition */ int num_procs /* number of processors in this partition */ ) { int to; /* communication partner (global) */ int tor; /* rank of partner in this partition */ int nprocs_large; /* power of 2 processor that contains num_procs */ int hbit; /* 2^hbit = nprocs_large */ int mask; /* mask to determine communication partner */ int i; /* loop index */ int tag = 32108; /* message tag */ double *tmpin; /* temporary double array to recieve */ double *tmpout; /* temporary double array to send */ double temp[2]; /* temp buffer to avoid malloc when count==1 */ MPI_Status status; /* this subroutine performs a scan operation summing doubles on a subset of a set of processors for Tflops_Special */ if (count==0) return; else if (count==1){ /* avoid malloc */ tmpin = temp; tmpout = &temp[1]; } else /* count>1 */ { tmpin = (double *) ZOLTAN_MALLOC(2*count*sizeof(double)); tmpout = tmpin + count; } /* Find next lower power of 2. */ for (hbit = 0; (num_procs >> hbit) != 0; hbit++); nprocs_large = 1 << hbit; if (nprocs_large == 2*num_procs) nprocs_large = num_procs; for (i=0; i1 */ { tmp = (double *) ZOLTAN_MALLOC(count*sizeof(double)); } /* Find next lower power of 2. */ for (hbit = 0; (nprocs >> hbit) != 1; hbit++); nprocs_small = 1 << hbit; if (nprocs_small * 2 == nprocs) { nprocs_small *= 2; hbit++; } to = proclower + (rank ^ nprocs_small); if (rank & nprocs_small) { /* processors greater than largest power of 2 */ MPI_Send(x, count, MPI_DOUBLE, to, tag, comm); tag += hbit + 1; MPI_Recv(x, count, MPI_DOUBLE, to, tag, comm, &status); } else { /* processors within greatest power of 2 */ if (rank + nprocs_small < nprocs) { MPI_Recv(tmp, count, MPI_DOUBLE, to, tag, comm, &status); for (i=0; i> 1; mask; mask >>= 1) { /* binary exchange */ tag++; partner = proclower + (rank ^ mask); MPI_Send(x, count, MPI_DOUBLE, partner, tag, comm); MPI_Recv(tmp, count, MPI_DOUBLE, partner, tag, comm, &status); for (i=0; i1 */ { tmp = (double *) ZOLTAN_MALLOC(count*sizeof(double)); } /* Find next lower power of 2. */ for (hbit = 0; (nprocs >> hbit) != 1; hbit++); nprocs_small = 1 << hbit; if (nprocs_small * 2 == nprocs) { nprocs_small *= 2; hbit++; } to = proclower + (rank ^ nprocs_small); if (rank & nprocs_small) { /* processors greater than largest power of 2 */ MPI_Send(x, count, MPI_DOUBLE, to, tag, comm); tag += hbit + 1; MPI_Recv(x, count, MPI_DOUBLE, to, tag, comm, &status); } else { /* processors within greatest power of 2 */ if (rank + nprocs_small < nprocs) { MPI_Recv(tmp, count, MPI_DOUBLE, to, tag, comm, &status); for (i=0; i x[i]) x[i] = tmp[i]; } for (mask = nprocs_small >> 1; mask; mask >>= 1) { /* binary exchange */ tag++; partner = proclower + (rank ^ mask); MPI_Send(x, count, MPI_DOUBLE, partner, tag, comm); MPI_Recv(tmp, count, MPI_DOUBLE, partner, tag, comm, &status); for (i=0; i x[i]) x[i] = tmp[i]; } tag++; if (rank + nprocs_small < nprocs) MPI_Send(x, count, MPI_DOUBLE, to, tag, comm); } if (count!=1) ZOLTAN_FREE(&tmp); } /* * I don't have time to write a fan out. Root sends doubles * to every other process. * TODO write this for real. */ void Zoltan_RB_bcast_doubles( double *x, /* doubles to be broadcast */ int num_doubles, int proclower, /* real rank of smallest processor in partition */ int rootrank, /* rank in partition to send the double */ int rank, /* my rank in partition */ int nprocs, /* number of processors in partition */ MPI_Comm comm ) { int tag = 32280; int i; MPI_Status status; if (rank != rootrank){ MPI_Recv(x, num_doubles, MPI_DOUBLE, proclower + rootrank, tag, comm, &status); } else{ for (i=0; i