35 #ifndef GRAPH_GENERATOR_SEQ 36 #define GRAPH_GENERATOR_SEQ 48 template <
typename IT>
54 template <
typename IT>
60 template <
typename IT>
67 nedges = (rank == nprocs-1)? (globalm - rank * (globalm / nprocs)) : (globalm / nprocs);
69 FILE * infp = fopen(filename,
"rb");
71 IT read_offset_start, read_offset_end;
72 read_offset_start = rank * 8 * (globalm / nprocs);
73 read_offset_end = (rank+1) * 8 * (globalm / nprocs);
74 if (rank == nprocs - 1)
75 read_offset_end = 8*globalm;
79 commGrid->OpenDebugFile(
"BinRead", oput);
82 oput <<
"File exists" << std::endl;
83 oput <<
"Trying to read " << nedges <<
" edges out of " << globalm << std::endl;
87 oput <<
"File does not exist" << std::endl;
91 uint32_t * gen_edges =
new uint32_t[2*nedges];
92 fseek(infp, read_offset_start, SEEK_SET);
93 fread(gen_edges, 2*nedges,
sizeof(uint32_t), infp);
95 oput <<
"Freads done " << std::endl;
96 for(IT i=0; i< 2*nedges; ++i)
97 edges[i] = (IT) gen_edges[i];
98 oput <<
"Puts done " << std::endl;
108 template <
typename IT>
112 MPI_Comm World =
commGrid->GetWorld();
113 MPI_Comm_rank(World, &rank);
114 MPI_Comm_size(World, &nprocs);
116 MPI_File_open(World, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &thefile);
118 IT * prelens =
new IT[nprocs];
119 prelens[
rank] = 2*nedges;
120 MPI_Allgather(MPI_IN_PLACE, 0, MPIType<IT>(), prelens, 1, MPIType<IT>(),
commGrid->GetWorld());
121 IT lengthuntil = accumulate(prelens, prelens+rank, 0);
125 MPI_File_set_view(thefile,
int64_t(lengthuntil *
sizeof(IT)), MPIType<IT>(), MPIType<IT>(),
"native", MPI_INFO_NULL);
126 MPI_File_write(thefile, edges, prelens[rank], MPIType<IT>(), NULL);
127 MPI_File_close(&thefile);
131 template <
typename IT>
135 MPI_Comm World =
commGrid->GetWorld();
136 MPI_Comm_rank(World, &rank);
137 MPI_Comm_size(World, &nprocs);
139 MPI_File_open(World, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &thefile);
141 IT * prelens =
new IT[nprocs];
142 prelens[
rank] = 2*nedges;
143 MPI_Allgather(MPI_IN_PLACE, 0, MPIType<IT>(), prelens, 1, MPIType<IT>(),
commGrid->GetWorld());
144 IT lengthuntil = accumulate(prelens, prelens+rank, static_cast<IT>(0));
148 MPI_File_set_view(thefile,
int64_t(lengthuntil *
sizeof(uint32_t)), MPI_UNSIGNED, MPI_UNSIGNED,
"native", MPI_INFO_NULL);
149 uint32_t * gen_edges =
new uint32_t[prelens[
rank]];
150 for(IT i=0; i< prelens[
rank]; ++i)
151 gen_edges[i] = (uint32_t) edges[i];
153 MPI_File_write(thefile, gen_edges, prelens[rank], MPI_UNSIGNED, NULL);
154 MPI_File_close(&thefile);
161 template <
typename IT>
164 if(edges)
delete [] edges;
165 if(pedges)
delete [] pedges;
169 template <
typename IT>
182 edges =
new IT[2*memedges];
189 template <
typename IT>
194 while (nedges > 0 && edges[2*(nedges-1) + 0] == -1)
200 for (IT i = 0; i < (nedges-1); i++)
202 if (edges[2*i + 0] == -1)
206 edges[2*i + 0] = edges[2*(nedges-1) + 0];
207 edges[2*i + 1] = edges[2*(nedges-1) + 1];
208 edges[2*(nedges-1) + 0] = -1;
210 while (nedges > 0 && edges[2*(nedges-1) + 0] == -1)
222 template <
typename IT>
225 if(packed && (!scramble))
227 SpParHelper::Print(
"WARNING: Packed version does always generate scrambled vertex identifiers\n");
230 globalV = ((
int64_t)1)<< log_numverts;
242 uint_fast32_t seed[5];
249 uint64_t seed2 = time(NULL);
264 nedges = globaledges/
size;
267 for (IT i = 0; i < nedges; i++)
273 for(IT i=0; i < nedges; ++i)
293 template <
typename IT>
296 IT maxedges = DEL.memedges;
302 IT perstage = maxedges / stages;
304 int nproc =(DEL.
commGrid)->GetSize();
306 IT * dist =
new IT[nproc];
313 for(IT s=0; s< stages; ++s)
317 double st = MPI_Wtime();
320 IT n_sofar = s*perstage;
321 IT n_thisstage = ((s==(stages-1))? (maxedges - n_sofar): perstage);
323 std::pair<double, std::pair<IT,IT> >* vecpair =
new std::pair<double, std::pair<IT,IT> >[n_thisstage];
324 dist[
rank] = n_thisstage;
325 MPI_Allgather(MPI_IN_PLACE, 1, MPIType<IT>(), dist, 1, MPIType<IT>(), DEL.
commGrid->GetWorld());
327 for (IT i = 0; i < n_thisstage; i++)
329 vecpair[i].first = M.
rand();
330 vecpair[i].second.first = DEL.edges[2*(i+n_sofar)];
331 vecpair[i].second.second = DEL.edges[2*(i+n_sofar)+1];
337 for (IT i = 0; i < n_thisstage; i++)
339 DEL.edges[2*(i+n_sofar)] = vecpair[i].second.first;
340 DEL.edges[2*(i+n_sofar)+1] = vecpair[i].second.second;
344 double et = MPI_Wtime();
345 std::ostringstream timeinfo;
346 timeinfo <<
"Stage " << s <<
" in " << et-st <<
" seconds" << std::endl;
363 template <
typename IU>
366 int nprocs = DEL.
commGrid->GetSize();
368 MPI_Comm World = DEL.
commGrid->GetWorld();
374 IU locrows = globalPerm.MyLocLength();
378 bool* renamed =
new bool[locedgelist];
379 std::fill_n(renamed, locedgelist, 0);
382 IU * localPerm = NULL;
394 for (
int round = 0; round < nprocs; round++)
400 localPerm =
new IU[permsize];
401 std::copy(globalPerm.arr.begin(), globalPerm.arr.end(), localPerm);
403 MPI_Bcast(&permsize, 1, MPIType<IU>(), round, World);
406 localPerm =
new IU[permsize];
408 MPI_Bcast(localPerm, permsize, MPIType<IU>(), round, World);
411 for (
typename std::vector<IU>::size_type j = 0; j < (unsigned)locedgelist ; j++)
414 if (startInd <= DEL.edges[j] && DEL.edges[j] < (startInd + permsize) && !renamed[j])
416 DEL.edges[j] = localPerm[DEL.edges[j]-startInd];
420 startInd += permsize;
IT getNumLocalEdges() const
void GenGraph500Data(double initiator[4], int log_numverts, int edgefactor, bool scramble=false, bool packed=false)
static void make_graph(int log_numverts, int64_t M, int64_t *nedges_ptr, packed_edge **result_ptr, MPI_Comm &world)
static int64_t scramble(int64_t v0, int lgN, uint64_t val0, uint64_t val1)
MPI_Datatype MPIType< uint64_t >(void)
void make_mrg_seed(uint64_t userseed1, uint64_t userseed2, uint_fast32_t *seed)
friend void PermEdges(DistEdgeList< IU > &DEL)
static void MemoryEfficientPSort(std::pair< KEY, VAL > *array, IT length, IT *dist, const MPI_Comm &comm)
int64_t getGlobalV() const
static void Print(const std::string &s)
void iota(IT globalsize, NT first)
void Dump64bit(std::string filename)
void Dump32bit(std::string filename)
friend void RenameVertices(DistEdgeList< IU > &DEL)
static mrg_state MakeScrambleValues(uint64_t &val0, uint64_t &val1, const uint_fast32_t seed[])
std::shared_ptr< CommGrid > commGrid
void generate_kronecker(int rank, int size, const uint_fast32_t seed[5], int logN, int64_t M, const double initiator[], int64_t *const edges)