35 #ifndef GRAPH_GENERATOR_SEQ
36 #define GRAPH_GENERATOR_SEQ
47 template <
typename IT>
50 commGrid.reset(
new CommGrid(MPI_COMM_WORLD, 0, 0));
53 template <
typename IT>
56 commGrid.reset(
new CommGrid(MPI_COMM_WORLD, 0, 0));
58 int nprocs = commGrid->GetSize();
59 int rank = commGrid->GetRank();
60 nedges = (rank == nprocs-1)? (globalm - rank * (globalm / nprocs)) : (globalm / nprocs);
62 FILE * infp = fopen(filename,
"rb");
64 IT read_offset_start, read_offset_end;
65 read_offset_start = rank * 8 * (globalm / nprocs);
66 read_offset_end = (rank+1) * 8 * (globalm / nprocs);
67 if (rank == nprocs - 1)
68 read_offset_end = 8*globalm;
72 commGrid->OpenDebugFile(
"BinRead", oput);
75 oput <<
"File exists" << endl;
76 oput <<
"Trying to read " << nedges <<
" edges out of " << globalm << endl;
80 oput <<
"File does not exist" << endl;
84 uint32_t * gen_edges =
new uint32_t[2*nedges];
85 fseek(infp, read_offset_start, SEEK_SET);
86 fread(gen_edges, 2*nedges,
sizeof(uint32_t), infp);
88 oput <<
"Freads done " << endl;
89 for(IT i=0; i< 2*nedges; ++i)
90 edges[i] = (IT) gen_edges[i];
91 oput <<
"Puts done " << endl;
97 template <
typename IT>
101 MPI_Comm World = commGrid->GetWorld();
102 MPI_Comm_rank(World, &rank);
103 MPI_Comm_size(World, &nprocs);
105 MPI_File_open(World, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &thefile);
107 IT * prelens =
new IT[nprocs];
108 prelens[rank] = 2*nedges;
109 MPI_Allgather(MPI_IN_PLACE, 0, MPIType<IT>(), prelens, 1, MPIType<IT>(), commGrid->GetWorld());
110 IT lengthuntil = accumulate(prelens, prelens+rank, 0);
114 MPI_File_set_view(thefile,
int64_t(lengthuntil *
sizeof(IT)), MPIType<IT>(), MPIType<IT>(),
"native", MPI_INFO_NULL);
115 MPI_File_write(thefile, edges, prelens[rank], MPIType<IT>(), NULL);
116 MPI_File_close(&thefile);
120 template <
typename IT>
124 MPI_Comm World = commGrid->GetWorld();
125 MPI_Comm_rank(World, &rank);
126 MPI_Comm_size(World, &nprocs);
128 MPI_File_open(World, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &thefile);
130 IT * prelens =
new IT[nprocs];
131 prelens[rank] = 2*nedges;
132 MPI_Allgather(MPI_IN_PLACE, 0, MPIType<IT>(), prelens, 1, MPIType<IT>(), commGrid->GetWorld());
133 IT lengthuntil = accumulate(prelens, prelens+rank, static_cast<IT>(0));
137 MPI_File_set_view(thefile,
int64_t(lengthuntil *
sizeof(uint32_t)), MPI_UNSIGNED, MPI_UNSIGNED,
"native", MPI_INFO_NULL);
138 uint32_t * gen_edges =
new uint32_t[prelens[rank]];
139 for(IT i=0; i< prelens[rank]; ++i)
140 gen_edges[i] = (uint32_t) edges[i];
142 MPI_File_write(thefile, gen_edges, prelens[rank], MPI_UNSIGNED, NULL);
143 MPI_File_close(&thefile);
149 template <
typename IT>
152 if(edges)
delete [] edges;
153 if(pedges)
delete [] pedges;
157 template <
typename IT>
170 edges =
new IT[2*memedges];
177 template <
typename IT>
182 while (nedges > 0 && edges[2*(nedges-1) + 0] == -1)
188 for (IT i = 0; i < (nedges-1); i++)
190 if (edges[2*i + 0] == -1)
194 edges[2*i + 0] = edges[2*(nedges-1) + 0];
195 edges[2*i + 1] = edges[2*(nedges-1) + 1];
196 edges[2*(nedges-1) + 0] = -1;
198 while (nedges > 0 && edges[2*(nedges-1) + 0] == -1)
210 template <
typename IT>
213 if(packed && (!scramble))
215 SpParHelper::Print(
"WARNING: Packed version does always generate scrambled vertex identifiers\n");
218 globalV = ((
int64_t)1)<< log_numverts;
230 uint_fast32_t seed[5];
232 uint64_t
size = (uint64_t) commGrid->GetSize();
233 uint64_t
rank = (uint64_t) commGrid->GetRank();
237 uint64_t seed2 = time(NULL);
252 nedges = globaledges/size;
255 for (IT i = 0; i < nedges; i++)
261 for(IT i=0; i < nedges; ++i)
281 template <
typename IT>
284 IT maxedges = DEL.memedges;
290 IT perstage = maxedges / stages;
292 int nproc =(DEL.commGrid)->GetSize();
293 int rank = (DEL.commGrid)->GetRank();
294 IT * dist =
new IT[nproc];
297 for(IT s=0; s< stages; ++s)
301 double st = MPI_Wtime();
304 IT n_sofar = s*perstage;
305 IT n_thisstage = ((s==(stages-1))? (maxedges - n_sofar): perstage);
307 pair<double, pair<IT,IT> >* vecpair =
new pair<double, pair<IT,IT> >[n_thisstage];
308 dist[rank] = n_thisstage;
309 MPI_Allgather(MPI_IN_PLACE, 1, MPIType<IT>(), dist, 1, MPIType<IT>(), DEL.commGrid->GetWorld());
311 for (IT i = 0; i < n_thisstage; i++)
313 vecpair[i].first = M.
rand();
314 vecpair[i].second.first = DEL.edges[2*(i+n_sofar)];
315 vecpair[i].second.second = DEL.edges[2*(i+n_sofar)+1];
321 for (IT i = 0; i < n_thisstage; i++)
323 DEL.edges[2*(i+n_sofar)] = vecpair[i].second.first;
324 DEL.edges[2*(i+n_sofar)+1] = vecpair[i].second.second;
328 double et = MPI_Wtime();
329 ostringstream timeinfo;
330 timeinfo <<
"Stage " << s <<
" in " << et-st <<
" seconds" << endl;
347 template <
typename IU>
350 int nprocs = DEL.commGrid->GetSize();
351 int rank = DEL.commGrid->GetRank();
352 MPI_Comm World = DEL.commGrid->GetWorld();
358 IU locrows = globalPerm.MyLocLength();
362 bool* renamed =
new bool[locedgelist];
363 fill_n(renamed, locedgelist, 0);
366 IU * localPerm = NULL;
378 for (
int round = 0; round < nprocs; round++)
384 localPerm =
new IU[permsize];
385 copy(globalPerm.arr.begin(), globalPerm.arr.end(), localPerm);
387 MPI_Bcast(&permsize, 1, MPIType<IU>(), round, World);
390 localPerm =
new IU[permsize];
392 MPI_Bcast(localPerm, permsize, MPIType<IU>(), round, World);
395 for (
typename vector<IU>::size_type j = 0; j < (unsigned)locedgelist ; j++)
398 if (startInd <= DEL.edges[j] && DEL.edges[j] < (startInd + permsize) && !renamed[j])
400 DEL.edges[j] = localPerm[DEL.edges[j]-startInd];
404 startInd += permsize;