12 #include "Tpetra_MultiVector_decl.hpp"
16 #include "Teuchos_XMLParameterListHelpers.hpp"
26 const string& delimiters =
" \f\n\r\t\v" )
28 return s.substr( 0, s.find_last_not_of( delimiters ) + 1 );
33 const string& delimiters =
" \f\n\r\t\v" )
35 return s.substr( s.find_first_not_of( delimiters ) );
40 const string& delimiters =
" \f\n\r\t\v" )
46 void readGeoGenParams(
string paramFileName, Teuchos::ParameterList &geoparams,
const RCP<
const Teuchos::Comm<int> > & comm){
47 std::string input =
"";
49 for(
int i = 0; i < 25000; ++i){
54 if(comm->getRank() == 0){
56 std::fstream inParam(paramFileName.c_str());
64 getline (inParam,tmp);
65 while (!inParam.eof()){
72 getline (inParam,tmp);
75 for (
size_t i = 0; i < input.size(); ++i){
83 int size = input.size();
87 comm->broadcast(0,
sizeof(
int), (
char*) &size);
89 throw "File " + paramFileName +
" cannot be opened.";
91 comm->broadcast(0, size, inp);
92 std::istringstream inParam(inp);
94 getline (inParam,str);
95 while (!inParam.eof()){
97 size_t pos = str.find(
'=');
98 if(pos == std::string::npos){
99 throw "Invalid Line:" + str +
" in parameter file";
101 string paramname =
trim_copy(str.substr(0,pos));
102 string paramvalue =
trim_copy(str.substr(pos + 1));
103 geoparams.set(paramname, paramvalue);
105 getline (inParam,str);
110 for(
int i = 0; args[i] != 0; i++)
115 std::stringstream stream(std::stringstream::in | std::stringstream::out);
116 stream << argumentline;
117 getline(stream, argumentid,
'=');
121 stream >> argumentValue;
125 template <
typename part_t>
132 part_t &nz,
bool ÷_prime,
int &ranks_per_node,
string &taskGraphFile,
string &taskCoordFile){
134 bool isprocset =
false;
137 for(
int i = 0; i < narg; ++i){
140 string identifier =
"";
144 if(identifier ==
"PROC"){
145 std::stringstream stream(std::stringstream::in | std::stringstream::out);
147 getline(stream, procF,
'=');
152 else if(identifier ==
"NX"){
153 std::stringstream stream(std::stringstream::in | std::stringstream::out);
155 getline(stream, tmp2,
'=');
160 else if(identifier ==
"NY"){
161 std::stringstream stream(std::stringstream::in | std::stringstream::out);
163 getline(stream, tmp2,
'=');
168 else if(identifier ==
"NZ"){
169 std::stringstream stream(std::stringstream::in | std::stringstream::out);
171 getline(stream, tmp2,
'=');
176 else if(identifier ==
"DP"){
177 std::stringstream stream(std::stringstream::in | std::stringstream::out);
179 getline(stream, tmp2,
'=');
182 if (val) divide_prime =
true;
185 else if(identifier ==
"RPN"){
186 std::stringstream stream(std::stringstream::in | std::stringstream::out);
188 getline(stream, tmp2,
'=');
189 stream >> ranks_per_node;
191 }
else if(identifier ==
"TG"){
192 std::stringstream stream(std::stringstream::in | std::stringstream::out);
194 getline(stream, taskGraphFile,
'=');
196 stream >> taskGraphFile;
198 else if(identifier ==
"TC"){
199 std::stringstream stream(std::stringstream::in | std::stringstream::out);
201 getline(stream, taskCoordFile,
'=');
202 stream >> taskCoordFile;
206 throw "Invalid argument at " + tmp;
210 if(!(ispartset >= 3&& isprocset)){
211 throw "(PROC && PART) are mandatory arguments.";
215 int main(
int narg,
char *arg[]){
217 Tpetra::ScopeGuard tscope(&narg, &arg);
219 typedef Tpetra::MultiVector<zscalar_t, zlno_t, zgno_t, znode_t>
tMVector_t;
236 string taskGraphFile =
"";
237 string taskCoordFile =
"";
238 bool divide_prime =
false;
239 part_t jobX = 1, jobY = 1, jobZ = 1;
240 string procfile =
"";
241 int rank_per_node = 16;
243 const RCP<Comm<int> > commN;
244 RCP<Comm<int> >comm = Teuchos::rcp_const_cast<Comm<int> >
245 (Teuchos::DefaultComm<int>::getDefaultSerialComm(commN));
247 part_t *task_communication_xadj_ = NULL;
248 part_t *task_communication_adj_ = NULL;
249 zscalar_t *task_communication_adjw_ = NULL;
256 jobX, jobY, jobZ, divide_prime, rank_per_node, taskGraphFile, taskCoordFile);
260 numParts = jobZ*jobY*jobX;
264 if (taskGraphFile ==
"" || taskCoordFile ==
"")
267 partCenters =
new zscalar_t * [coordDim];
268 for(
int i = 0; i < coordDim; ++i){
269 partCenters[i] =
new zscalar_t[numParts];
273 task_communication_xadj_ =
new part_t [numParts+1];
274 task_communication_adj_ =
new part_t [numParts * 6];
277 task_communication_xadj_[0] = 0;
278 for (part_t i = 0; i < numParts; ++i) {
280 int y = (i / (jobX)) % jobY;
281 int z = (i / (jobX)) / jobY;
282 partCenters[0][i] = x;
283 partCenters[1][i] = y;
284 partCenters[2][i] = z;
287 task_communication_adj_[prevNCount++] = i - 1;
290 task_communication_adj_[prevNCount++] = i + 1;
293 task_communication_adj_[prevNCount++] = i - jobX;
296 task_communication_adj_[prevNCount++] = i + jobX;
299 task_communication_adj_[prevNCount++] = i - jobX * jobY;
302 task_communication_adj_[prevNCount++] = i + jobX * jobY;
304 task_communication_xadj_[i+1] = prevNCount;
309 FILE *f2 = fopen(taskGraphFile.c_str(),
"rb");
311 fread(&numParts,
sizeof(
int),1,f2);
312 fread(&ne,
sizeof(
int),1,f2);
315 std::cout <<
"numParts:" << numParts <<
" ne:" << ne << std::endl;
317 task_communication_xadj_ =
new part_t [numParts+1];
318 task_communication_adj_ =
new part_t [ne];
319 task_communication_adjw_ =
new zscalar_t [ne];
321 fread((
void *)task_communication_xadj_,
sizeof(
int),numParts + 1,f2);
322 fread((
void *)task_communication_adj_,
sizeof(
int),ne ,f2);
323 fread((
void *)task_communication_adjw_,
sizeof(
double),ne,f2);
326 f2 = fopen(taskCoordFile.c_str(),
"rb");
327 fread((
void *)&numParts,
sizeof(
int),1,f2);
328 fread((
void *)&coordDim,
sizeof(
int),1,f2);
330 std::cout <<
"numParts:" << numParts <<
" coordDim:" << coordDim << std::endl;
332 partCenters =
new zscalar_t * [coordDim];
333 for(
int i = 0; i < coordDim; ++i){
334 partCenters[i] =
new zscalar_t[numParts];
335 fread((
void *) partCenters[i],
sizeof(
double),numParts, f2);
344 std::vector < std::vector <zscalar_t> > proc_coords(procDim);
345 std::fstream m(procfile.c_str());
346 procCoordinates =
new zscalar_t * [procDim];
352 proc_coords[0].push_back(a);
353 proc_coords[1].push_back(b);
354 proc_coords[2].push_back(c);
361 for(
int ii = 0; ii < procDim; ++ii){
362 procCoordinates[ii] =
new zscalar_t[numProcs];
363 for (
int j = 0; j < numProcs; ++j){
364 procCoordinates[ii][j] = proc_coords[ii][j];
368 std::cout <<
"numProcs:" << numProcs << std::endl;
382 Teuchos::RCP<const Teuchos::Comm<int> > tcomm =Tpetra::getDefaultComm();
383 part_t *proc_to_task_xadj_ =
new part_t[numProcs+1];
384 part_t *proc_to_task_adj_ =
new part_t[numParts];
405 part_t *partArray = NULL;
406 int partArraysize = -1;
411 part_t *machineDimensions = NULL;
414 Zoltan2::coordinateTaskMapperInterface<part_t, zscalar_t, zscalar_t>(
424 task_communication_xadj_,
425 task_communication_adj_,
426 task_communication_adjw_,
432 Kokkos::View<part_t*, Kokkos::HostSpace,
433 Kokkos::MemoryUnmanaged>(partArray,(partArraysize == -1 ? 0 : partArraysize)),
434 machineDimensions, rank_per_node, divide_prime
437 if (tcomm->getRank() == 0){
438 std::cout <<
"PASS" << std::endl;
445 delete [] proc_to_task_xadj_;
446 delete [] proc_to_task_adj_;
447 delete [] task_communication_xadj_;
448 delete [] task_communication_adj_;
449 delete [] task_communication_adjw_;
451 for (
int i = 0; i < coordDim; i++)
delete [] partCenters[i];
452 delete [] partCenters;
453 for (
int i = 0; i < procDim; i++)
delete [] procCoordinates[i];
454 delete [] procCoordinates;
456 catch(std::string &s){
457 std::cerr << s << std::endl;
461 std::cerr << s << std::endl;
string trim_right_copy(const string &s, const string &delimiters=" \f\n\r\t\v")
void readGeoGenParams(string paramFileName, Teuchos::ParameterList &geoparams, const RCP< const Teuchos::Comm< int > > &comm)
int main(int narg, char **arg)
common code used by tests
string trim_copy(const string &s, const string &delimiters=" \f\n\r\t\v")
SparseMatrixAdapter_t::part_t part_t
An adapter for Xpetra::MultiVector.
void getArgVals(int narg, char **arg, int &numTeams, int &numParts, float &imbalance, string &pqParts, int &opt, std::string &fname, std::string &pfname, int &k, int &migration_check_option, int &migration_all_to_all_type, zscalar_t &migration_imbalance_cut_off, int &migration_processor_assignment_type, int &migration_doMigration_type, bool &uvm, bool &print_details, bool &test_boxes, bool &rectilinear, int &mj_premigration_option, int &mj_coordinate_cutoff)
static const std::string fail
string convert_to_string(char *args)
string trim_left_copy(const string &s, const string &delimiters=" \f\n\r\t\v")
bool getArgumentValue(string &argumentid, double &argumentValue, string argumentline)
Tpetra::MultiVector< zscalar_t, zlno_t, zgno_t, znode_t > tMVector_t