COMBINATORIAL_BLAS  1.6
SpParHelper.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* Parallel Combinatorial BLAS Library (for Graph Computations) */
3 /* version 1.6 -------------------------------------------------*/
4 /* date: 6/15/2017 ---------------------------------------------*/
5 /* authors: Ariful Azad, Aydin Buluc --------------------------*/
6 /****************************************************************/
7 /*
8  Copyright (c) 2010-2017, The Regents of the University of California
9 
10  Permission is hereby granted, free of charge, to any person obtaining a copy
11  of this software and associated documentation files (the "Software"), to deal
12  in the Software without restriction, including without limitation the rights
13  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14  copies of the Software, and to permit persons to whom the Software is
15  furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included in
18  all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26  THE SOFTWARE.
27  */
28 
29 
34 #ifndef _SP_PAR_HELPER_H_
35 #define _SP_PAR_HELPER_H_
36 
37 #include <vector>
38 #include <array>
39 #include <mpi.h>
40 #include "LocArr.h"
41 #include "CommGrid.h"
42 #include "MPIType.h"
43 #include "SpDefs.h"
44 #include "psort/psort.h"
45 
46 namespace combblas {
47 
49 {
50 public:
51  template <typename IT>
52  static void ReDistributeToVector(int * & map_scnt, std::vector< std::vector< IT > > & locs_send,
53  std::vector< std::vector< std::string > > & data_send, std::vector<std::array<char, MAXVERTNAME>> & distmapper_array, const MPI_Comm & comm);
54 
55  template<typename KEY, typename VAL, typename IT>
56  static void GlobalSelect(IT gl_rank, std::pair<KEY,VAL> * & low, std::pair<KEY,VAL> * & upp, std::pair<KEY,VAL> * array, IT length, const MPI_Comm & comm);
57 
58  template<typename KEY, typename VAL, typename IT>
59  static void BipartiteSwap(std::pair<KEY,VAL> * low, std::pair<KEY,VAL> * array, IT length, int nfirsthalf, int color, const MPI_Comm & comm);
60 
61  // Necessary because psort creates three 2D vectors of size p-by-p
62  // One of those vector with 8 byte data uses 8*(4096)^2 = 128 MB space
63  // Per processor extra storage becomes:
64  // 24 MB with 1K processors
65  // 96 MB with 2K processors
66  // 384 MB with 4K processors
67  // 1.5 GB with 8K processors
68  template<typename KEY, typename VAL, typename IT>
69  static void MemoryEfficientPSort(std::pair<KEY,VAL> * array, IT length, IT * dist, const MPI_Comm & comm);
70 
71  template<typename KEY, typename VAL, typename IT>
72  static std::vector<std::pair<KEY,VAL>> KeyValuePSort(std::pair<KEY,VAL> * array, IT length, IT * dist, const MPI_Comm & comm);
73 
74  template<typename KEY, typename VAL, typename IT>
75  static void DebugPrintKeys(std::pair<KEY,VAL> * array, IT length, IT * dist, MPI_Comm & World);
76 
77  template<typename IT, typename NT, typename DER>
78  static void FetchMatrix(SpMat<IT,NT,DER> & MRecv, const std::vector<IT> & essentials, std::vector<MPI_Win> & arrwin, int ownind);
79 
80  template<typename IT, typename NT, typename DER>
81  static void BCastMatrix(MPI_Comm & comm1d, SpMat<IT,NT,DER> & Matrix, const std::vector<IT> & essentials, int root);
82 
83  template<typename IT, typename NT, typename DER>
84  static void GatherMatrix(MPI_Comm & comm1d, SpMat<IT,NT,DER> & Matrix, int root);
85 
86  template<typename IT, typename NT, typename DER>
87  static void SetWindows(MPI_Comm & comm1d, const SpMat< IT,NT,DER > & Matrix, std::vector<MPI_Win> & arrwin);
88 
89  template <typename IT, typename NT, typename DER>
90  static void GetSetSizes(const SpMat<IT,NT,DER> & Matrix, IT ** & sizes, MPI_Comm & comm1d);
91 
92  template <typename IT, typename DER>
93  static void AccessNFetch(DER * & Matrix, int owner, std::vector<MPI_Win> & arrwin, MPI_Group & group, IT ** sizes);
94 
95  template <typename IT, typename DER>
96  static void LockNFetch(DER * & Matrix, int owner, std::vector<MPI_Win> & arrwin, MPI_Group & group, IT ** sizes);
97 
98  static void StartAccessEpoch(int owner, std::vector<MPI_Win> & arrwin, MPI_Group & group);
99  static void PostExposureEpoch(int self, std::vector<MPI_Win> & arrwin, MPI_Group & group);
100  static void LockWindows(int ownind, std::vector<MPI_Win> & arrwin);
101  static void UnlockWindows(int ownind, std::vector<MPI_Win> & arrwin);
102 
103  static void Print(const std::string & s);
104  static void Print(const std::string & s, MPI_Comm & world);
105  static void PrintFile(const std::string & s, const std::string & filename);
106  static void PrintFile(const std::string & s, const std::string & filename, MPI_Comm & world);
107  static void check_newline(int *bytes_read, int bytes_requested, char *buf);
108  static bool FetchBatch(MPI_File & infile, MPI_Offset & curpos, MPI_Offset end_fpos, bool firstcall, std::vector<std::string> & lines, int myrank);
109 
110  static void WaitNFree(std::vector<MPI_Win> & arrwin);
111  static void FreeWindows(std::vector<MPI_Win> & arrwin);
112 };
113 
114 }
115 
116 #include "SpParHelper.cpp"
117 
118 #endif
static void LockNFetch(DER *&Matrix, int owner, std::vector< MPI_Win > &arrwin, MPI_Group &group, IT **sizes)
static void AccessNFetch(DER *&Matrix, int owner, std::vector< MPI_Win > &arrwin, MPI_Group &group, IT **sizes)
static void StartAccessEpoch(int owner, std::vector< MPI_Win > &arrwin, MPI_Group &group)
static void GetSetSizes(const SpMat< IT, NT, DER > &Matrix, IT **&sizes, MPI_Comm &comm1d)
static void GatherMatrix(MPI_Comm &comm1d, SpMat< IT, NT, DER > &Matrix, int root)
static void BipartiteSwap(std::pair< KEY, VAL > *low, std::pair< KEY, VAL > *array, IT length, int nfirsthalf, int color, const MPI_Comm &comm)
static void WaitNFree(std::vector< MPI_Win > &arrwin)
static void FetchMatrix(SpMat< IT, NT, DER > &MRecv, const std::vector< IT > &essentials, std::vector< MPI_Win > &arrwin, int ownind)
static void MemoryEfficientPSort(std::pair< KEY, VAL > *array, IT length, IT *dist, const MPI_Comm &comm)
static void Print(const std::string &s)
static void GlobalSelect(IT gl_rank, std::pair< KEY, VAL > *&low, std::pair< KEY, VAL > *&upp, std::pair< KEY, VAL > *array, IT length, const MPI_Comm &comm)
static void BCastMatrix(MPI_Comm &comm1d, SpMat< IT, NT, DER > &Matrix, const std::vector< IT > &essentials, int root)
static std::vector< std::pair< KEY, VAL > > KeyValuePSort(std::pair< KEY, VAL > *array, IT length, IT *dist, const MPI_Comm &comm)
static void check_newline(int *bytes_read, int bytes_requested, char *buf)
static void LockWindows(int ownind, std::vector< MPI_Win > &arrwin)
static void ReDistributeToVector(int *&map_scnt, std::vector< std::vector< IT > > &locs_send, std::vector< std::vector< std::string > > &data_send, std::vector< std::array< char, MAXVERTNAME >> &distmapper_array, const MPI_Comm &comm)
Definition: SpParHelper.cpp:35
static void DebugPrintKeys(std::pair< KEY, VAL > *array, IT length, IT *dist, MPI_Comm &World)
static void UnlockWindows(int ownind, std::vector< MPI_Win > &arrwin)
static bool FetchBatch(MPI_File &infile, MPI_Offset &curpos, MPI_Offset end_fpos, bool firstcall, std::vector< std::string > &lines, int myrank)
Definition: CCGrid.h:4
static void PrintFile(const std::string &s, const std::string &filename)
static void PostExposureEpoch(int self, std::vector< MPI_Win > &arrwin, MPI_Group &group)
static void FreeWindows(std::vector< MPI_Win > &arrwin)
static void SetWindows(MPI_Comm &comm1d, const SpMat< IT, NT, DER > &Matrix, std::vector< MPI_Win > &arrwin)