00001
00011 #ifndef __PAR_UTILS_H_
00012 #define __PAR_UTILS_H_
00013
00014 #define KEEP_HIGH 100
00015 #define KEEP_LOW 101
00016
00017 #ifdef __DEBUG__
00018 #ifndef __DEBUG_PAR__
00019 #define __DEBUG_PAR__
00020 #endif
00021 #endif
00022
00023 #include "mpi.h"
00024 #include <vector>
00025 #include "dendro.h"
00026
00027 #ifdef PETSC_USE_LOG
00028
00029 #include "petscsys.h"
00030
00031 namespace par {
00032 extern int sortEvent;
00033 extern int concatEvent;
00034 extern int remdupEvent;
00035 extern int partwEvent;
00036 extern int searchEvent;
00037 extern int parScatterEvent;
00038 extern int a2avWaitEvent;
00039 extern int all2AllvSparseEvent;
00040 extern int all2AllvDenseEvent;
00041 extern int allGatherEvent;
00042 extern int reduceEvent;
00043 extern int sendRecvEvent;
00044 extern int allReduceEvent;
00045 extern int all2AllEvent;
00046 extern int allGathervEvent;
00047 extern int gatherEvent;
00048 extern int scanEvent;
00049 extern int bcastEvent;
00050 extern int splitComm2wayEvent;
00051 extern int splitCommEvent;
00052 }
00053
00054 #define PROF_A2AV_WAIT_BEGIN PetscLogEventBegin(a2avWaitEvent,0,0,0,0);
00055 #define PROF_A2AV_WAIT_END PetscLogEventEnd(a2avWaitEvent,0,0,0,0);
00056
00057 #define PROF_SPLIT_COMM_2WAY_BEGIN \
00058 PetscFunctionBegin; \
00059 PetscLogEventBegin(splitComm2wayEvent,0,0,0,0);
00060 #define PROF_SPLIT_COMM_2WAY_END \
00061 PetscLogEventEnd(splitComm2wayEvent,0,0,0,0); \
00062 PetscFunctionReturn(0);
00063
00064 #define PROF_SPLIT_COMM_BEGIN \
00065 PetscFunctionBegin; \
00066 PetscLogEventBegin(splitCommEvent,0,0,0,0);
00067 #define PROF_SPLIT_COMM_END \
00068 PetscLogEventEnd(splitCommEvent,0,0,0,0); \
00069 PetscFunctionReturn(0);
00070
00071 #define PROF_SEARCH_BEGIN \
00072 PetscFunctionBegin; \
00073 PetscLogEventBegin(searchEvent,0,0,0,0);
00074 #define PROF_SEARCH_END \
00075 PetscLogEventEnd(searchEvent,0,0,0,0); \
00076 PetscFunctionReturn(0);
00077
00078 #define PROF_PAR_CONCAT_BEGIN \
00079 PetscFunctionBegin; \
00080 PetscLogEventBegin(concatEvent,0,0,0,0);
00081 #define PROF_PAR_CONCAT_END \
00082 PetscLogEventEnd(concatEvent,0,0,0,0); \
00083 PetscFunctionReturn(0);
00084
00085 #define PROF_PAR_SCATTER_BEGIN \
00086 PetscFunctionBegin; \
00087 PetscLogEventBegin(parScatterEvent,0,0,0,0);
00088 #define PROF_PAR_SCATTER_END \
00089 PetscLogEventEnd(parScatterEvent,0,0,0,0); \
00090 PetscFunctionReturn(0);
00091
00092 #define PROF_PAR_SENDRECV_BEGIN \
00093 PetscFunctionBegin; \
00094 PetscLogEventBegin(sendRecvEvent,0,0,0,0);
00095 #define PROF_PAR_SENDRECV_END \
00096 PetscLogEventEnd(sendRecvEvent,0,0,0,0); \
00097 PetscFunctionReturn(0);
00098
00099 #define PROF_PAR_BCAST_BEGIN \
00100 PetscFunctionBegin; \
00101 PetscLogEventBegin(bcastEvent,0,0,0,0);
00102 #define PROF_PAR_BCAST_END \
00103 PetscLogEventEnd(bcastEvent,0,0,0,0); \
00104 PetscFunctionReturn(0);
00105
00106 #define PROF_PAR_SCAN_BEGIN \
00107 PetscFunctionBegin; \
00108 PetscLogEventBegin(scanEvent,0,0,0,0);
00109 #define PROF_PAR_SCAN_END \
00110 PetscLogEventEnd(scanEvent,0,0,0,0); \
00111 PetscFunctionReturn(0);
00112
00113 #define PROF_PAR_GATHER_BEGIN \
00114 PetscFunctionBegin; \
00115 PetscLogEventBegin(gatherEvent,0,0,0,0);
00116 #define PROF_PAR_GATHER_END \
00117 PetscLogEventEnd(gatherEvent,0,0,0,0); \
00118 PetscFunctionReturn(0);
00119
00120 #define PROF_PAR_REDUCE_BEGIN \
00121 PetscFunctionBegin; \
00122 PetscLogEventBegin(reduceEvent,0,0,0,0);
00123 #define PROF_PAR_REDUCE_END \
00124 PetscLogEventEnd(reduceEvent,0,0,0,0); \
00125 PetscFunctionReturn(0);
00126
00127 #define PROF_PAR_ALLREDUCE_BEGIN \
00128 PetscFunctionBegin; \
00129 PetscLogEventBegin(allReduceEvent,0,0,0,0);
00130 #define PROF_PAR_ALLREDUCE_END \
00131 PetscLogEventEnd(allReduceEvent,0,0,0,0); \
00132 PetscFunctionReturn(0);
00133
00134 #define PROF_PAR_ALL2ALL_BEGIN \
00135 PetscFunctionBegin; \
00136 PetscLogEventBegin(all2AllEvent,0,0,0,0);
00137 #define PROF_PAR_ALL2ALL_END \
00138 PetscLogEventEnd(all2AllEvent,0,0,0,0); \
00139 PetscFunctionReturn(0);
00140
00141 #define PROF_PAR_ALLGATHER_BEGIN \
00142 PetscFunctionBegin; \
00143 PetscLogEventBegin(allGatherEvent,0,0,0,0);
00144 #define PROF_PAR_ALLGATHER_END \
00145 PetscLogEventEnd(allGatherEvent,0,0,0,0); \
00146 PetscFunctionReturn(0);
00147
00148 #define PROF_PAR_ALLGATHERV_BEGIN \
00149 PetscFunctionBegin; \
00150 PetscLogEventBegin(allGathervEvent,0,0,0,0);
00151 #define PROF_PAR_ALLGATHERV_END \
00152 PetscLogEventEnd(allGathervEvent,0,0,0,0); \
00153 PetscFunctionReturn(0);
00154
00155 #define PROF_PAR_ALL2ALLV_SPARSE_BEGIN \
00156 PetscFunctionBegin; \
00157 PetscLogEventBegin(all2AllvSparseEvent,0,0,0,0);
00158 #define PROF_PAR_ALL2ALLV_SPARSE_END \
00159 PetscLogEventEnd(all2AllvSparseEvent,0,0,0,0); \
00160 PetscFunctionReturn(0);
00161
00162 #define PROF_PAR_ALL2ALLV_DENSE_BEGIN \
00163 PetscFunctionBegin; \
00164 PetscLogEventBegin(all2AllvDenseEvent,0,0,0,0);
00165 #define PROF_PAR_ALL2ALLV_DENSE_END \
00166 PetscLogEventEnd(all2AllvDenseEvent,0,0,0,0); \
00167 PetscFunctionReturn(0);
00168
00169 #define PROF_SORT_BEGIN \
00170 PetscFunctionBegin; \
00171 PetscLogEventBegin(sortEvent,0,0,0,0);
00172 #define PROF_SORT_END \
00173 PetscLogEventEnd(sortEvent,0,0,0,0); \
00174 PetscFunctionReturn(0);
00175
00176 #define PROF_REMDUP_BEGIN \
00177 PetscFunctionBegin; \
00178 PetscLogEventBegin(remdupEvent,0,0,0,0);
00179 #define PROF_REMDUP_END \
00180 PetscLogEventEnd(remdupEvent,0,0,0,0); \
00181 PetscFunctionReturn(0);
00182
00183 #define PROF_PARTW_BEGIN \
00184 PetscFunctionBegin; \
00185 PetscLogEventBegin(partwEvent,0,0,0,0);
00186 #define PROF_PARTW_END \
00187 PetscLogEventEnd(partwEvent,0,0,0,0); \
00188 PetscFunctionReturn(0);
00189
00190 #else
00191
00192 #define PROF_A2AV_WAIT_BEGIN
00193 #define PROF_SPLIT_COMM_2WAY_BEGIN
00194 #define PROF_SPLIT_COMM_BEGIN
00195 #define PROF_SEARCH_BEGIN
00196 #define PROF_PAR_SCATTER_BEGIN
00197 #define PROF_PAR_SENDRECV_BEGIN
00198 #define PROF_PAR_BCAST_BEGIN
00199 #define PROF_PAR_GATHER_BEGIN
00200 #define PROF_PAR_SCAN_BEGIN
00201 #define PROF_PAR_REDUCE_BEGIN
00202 #define PROF_PAR_ALLREDUCE_BEGIN
00203 #define PROF_PAR_ALL2ALL_BEGIN
00204 #define PROF_PAR_ALLGATHERV_BEGIN
00205 #define PROF_PAR_ALLGATHER_BEGIN
00206 #define PROF_PAR_ALL2ALLV_SPARSE_BEGIN
00207 #define PROF_PAR_ALL2ALLV_DENSE_BEGIN
00208 #define PROF_PAR_CONCAT_BEGIN
00209 #define PROF_SORT_BEGIN
00210 #define PROF_REMDUP_BEGIN
00211 #define PROF_PARTW_BEGIN
00212
00213 #define PROF_A2AV_WAIT_END
00214 #define PROF_SPLIT_COMM_2WAY_END return 1;
00215 #define PROF_SPLIT_COMM_END return 1;
00216 #define PROF_SEARCH_END return 1;
00217 #define PROF_PAR_SCATTER_END return 1;
00218 #define PROF_PAR_SENDRECV_END return 1;
00219 #define PROF_PAR_BCAST_END return 1;
00220 #define PROF_PAR_GATHER_END return 1;
00221 #define PROF_PAR_SCAN_END return 1;
00222 #define PROF_PAR_REDUCE_END return 1;
00223 #define PROF_PAR_ALLREDUCE_END return 1;
00224 #define PROF_PAR_ALL2ALL_END return 1;
00225 #define PROF_PAR_ALLGATHERV_END return 1;
00226 #define PROF_PAR_ALLGATHER_END return 1;
00227 #define PROF_PAR_ALL2ALLV_SPARSE_END return 1;
00228 #define PROF_PAR_ALL2ALLV_DENSE_END return 1;
00229 #define PROF_PAR_CONCAT_END return 1;
00230 #define PROF_SORT_END return 1;
00231 #define PROF_REMDUP_END return 1;
00232 #define PROF_PARTW_END return 1;
00233
00234 #endif
00235
00242 namespace par {
00243
00244 template <typename T>
00245 int Mpi_Issend(T* buf, int count, int dest, int tag, MPI_Comm comm, MPI_Request* request);
00246
00247 template <typename T>
00248 int Mpi_Recv(T* buf, int count, int source, int tag, MPI_Comm comm, MPI_Status* status);
00249
00250 template <typename T>
00251 int Mpi_Irecv(T* buf, int count, int source, int tag, MPI_Comm comm, MPI_Request* request);
00252
00256 template <typename T>
00257 int Mpi_Gather( T* sendBuffer, T* recvBuffer, int count, int root, MPI_Comm comm);
00258
00262 template <typename T, typename S>
00263 int Mpi_Sendrecv( T* sendBuf, int sendCount, int dest, int sendTag,
00264 S* recvBuf, int recvCount, int source, int recvTag,
00265 MPI_Comm comm, MPI_Status* status);
00266
00270 template <typename T>
00271 int Mpi_Bcast( T* buffer, int count, int root, MPI_Comm comm);
00272
00276 template <typename T>
00277 int Mpi_Scan( T* sendbuf, T* recvbuf, int count, MPI_Op op, MPI_Comm comm);
00278
00282 template <typename T>
00283 int Mpi_Reduce( T* sendbuf, T* recvbuf, int count, MPI_Op op, int root, MPI_Comm comm);
00284
00288 template <typename T>
00289 int Mpi_Allreduce( T* sendbuf, T* recvbuf, int count, MPI_Op op, MPI_Comm comm);
00290
00294 template <typename T>
00295 int Mpi_Alltoall(T* sendbuf, T* recvbuf, int count, MPI_Comm comm);
00296
00300 template <typename T>
00301 int Mpi_Allgatherv(T* sendbuf, int sendcount, T* recvbuf,
00302 int* recvcounts, int* displs, MPI_Comm comm);
00303
00307 template <typename T>
00308 int Mpi_Allgather(T* sendbuf, T* recvbuf, int count, MPI_Comm comm);
00309
00313 template <typename T>
00314 int Mpi_Alltoallv_sparse(T* sendbuf, int* sendcnts, int* sdispls,
00315 T* recvbuf, int* recvcnts, int* rdispls, MPI_Comm comm);
00316
00320 template <typename T>
00321 int Mpi_Alltoallv_dense(T* sendbuf, int* sendcnts, int* sdispls,
00322 T* recvbuf, int* recvcnts, int* rdispls, MPI_Comm comm);
00323
00335 template <typename T>
00336 int scatterValues(std::vector<T> & in, std::vector<T> & out,
00337 DendroIntL outSz, MPI_Comm comm );
00338
00352 template <typename T>
00353 int maxLowerBound(const std::vector<T> & keys, const std::vector<T> & searchList,
00354 std::vector<T> & results, MPI_Comm comm);
00355
00356 template<typename T>
00357 unsigned int defaultWeight(const T *a);
00358
00370 template<typename T>
00371 int partitionW(std::vector<T>& vec,
00372 unsigned int (*getWeight)(const T *), MPI_Comm comm);
00373
00386 template<typename T>
00387 int concatenate(std::vector<T> & listA,
00388 std::vector<T> & listB, MPI_Comm comm);
00389
00405 template<typename T>
00406 int sampleSort(std::vector<T>& in, std::vector<T> & out, MPI_Comm comm);
00407
00416 template<typename T>
00417 int removeDuplicates(std::vector<T>& nodes, bool isSorted, MPI_Comm comm);
00418
00428 int splitComm2way(bool iAmEmpty, MPI_Comm* new_comm, MPI_Comm orig_comm);
00429
00439 int splitComm2way(const bool* isEmptyList, MPI_Comm* new_comm, MPI_Comm orig_comm);
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451 int splitCommUsingSplittingRank(int splittingRank, MPI_Comm* new_comm, MPI_Comm orig_comm);
00452
00462 unsigned int splitCommBinary( MPI_Comm orig_comm, MPI_Comm* new_comm);
00463
00464
00473 unsigned int splitCommBinaryNoFlip( MPI_Comm orig_comm, MPI_Comm* new_comm);
00474
00500 template <typename T>
00501 void MergeLists( std::vector<T> &listA, std::vector<T> &listB, int KEEP_WHAT) ;
00502
00511 template <typename T>
00512 void MergeSplit( std::vector<T> &local_list, int which_keys, int partner, MPI_Comm comm);
00513
00517 template <typename T>
00518 void Par_bitonic_sort_incr( std::vector<T> &local_list, int proc_set_size, MPI_Comm comm );
00519
00523 template <typename T>
00524 void Par_bitonic_sort_decr( std::vector<T> &local_list, int proc_set_size, MPI_Comm comm);
00525
00529 template <typename T>
00530 void Par_bitonic_merge_incr( std::vector<T> &local_list, int proc_set_size, MPI_Comm comm );
00531
00541 template <typename T>
00542 void bitonicSort_binary(std::vector<T> & in, MPI_Comm comm) ;
00543
00556 template <typename T>
00557 void bitonicSort(std::vector<T> & in, MPI_Comm comm) ;
00558
00559 }
00560
00561 #include "parUtils.txx"
00562
00563 #endif
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578