3 #include "Tpetra_MultiVector_decl.hpp"
7 #include "Teuchos_XMLParameterListHelpers.hpp"
17 const string& delimiters =
" \f\n\r\t\v" )
19 return s.substr( 0, s.find_last_not_of( delimiters ) + 1 );
24 const string& delimiters =
" \f\n\r\t\v" )
26 return s.substr( s.find_first_not_of( delimiters ) );
31 const string& delimiters =
" \f\n\r\t\v" )
37 void readGeoGenParams(
string paramFileName, Teuchos::ParameterList &geoparams,
const RCP<
const Teuchos::Comm<int> > & comm){
38 std::string input =
"";
40 for(
int i = 0; i < 25000; ++i){
45 if(comm->getRank() == 0){
47 std::fstream inParam(paramFileName.c_str());
55 getline (inParam,tmp);
56 while (!inParam.eof()){
63 getline (inParam,tmp);
66 for (
size_t i = 0; i < input.size(); ++i){
74 int size = input.size();
78 comm->broadcast(0,
sizeof(
int), (
char*) &size);
80 throw "File " + paramFileName +
" cannot be opened.";
82 comm->broadcast(0, size, inp);
83 std::istringstream inParam(inp);
85 getline (inParam,str);
86 while (!inParam.eof()){
88 size_t pos = str.find(
'=');
89 if(pos == std::string::npos){
90 throw "Invalid Line:" + str +
" in parameter file";
92 string paramname =
trim_copy(str.substr(0,pos));
93 string paramvalue =
trim_copy(str.substr(pos + 1));
94 geoparams.set(paramname, paramvalue);
96 getline (inParam,str);
101 for(
int i = 0; args[i] != 0; i++)
106 std::stringstream stream(std::stringstream::in | std::stringstream::out);
107 stream << argumentline;
108 getline(stream, argumentid,
'=');
112 stream >> argumentValue;
116 template <
typename part_t>
123 part_t &nz,
bool ÷_prime,
int &ranks_per_node,
string &taskGraphFile,
string &taskCoordFile){
125 bool isprocset =
false;
128 for(
int i = 0; i < narg; ++i){
131 string identifier =
"";
135 if(identifier ==
"PROC"){
136 std::stringstream stream(std::stringstream::in | std::stringstream::out);
138 getline(stream, procF,
'=');
143 else if(identifier ==
"NX"){
144 std::stringstream stream(std::stringstream::in | std::stringstream::out);
146 getline(stream, tmp2,
'=');
151 else if(identifier ==
"NY"){
152 std::stringstream stream(std::stringstream::in | std::stringstream::out);
154 getline(stream, tmp2,
'=');
159 else if(identifier ==
"NZ"){
160 std::stringstream stream(std::stringstream::in | std::stringstream::out);
162 getline(stream, tmp2,
'=');
167 else if(identifier ==
"DP"){
168 std::stringstream stream(std::stringstream::in | std::stringstream::out);
170 getline(stream, tmp2,
'=');
173 if (val) divide_prime =
true;
176 else if(identifier ==
"RPN"){
177 std::stringstream stream(std::stringstream::in | std::stringstream::out);
179 getline(stream, tmp2,
'=');
180 stream >> ranks_per_node;
182 }
else if(identifier ==
"TG"){
183 std::stringstream stream(std::stringstream::in | std::stringstream::out);
185 getline(stream, taskGraphFile,
'=');
187 stream >> taskGraphFile;
189 else if(identifier ==
"TC"){
190 std::stringstream stream(std::stringstream::in | std::stringstream::out);
192 getline(stream, taskCoordFile,
'=');
193 stream >> taskCoordFile;
197 throw "Invalid argument at " + tmp;
201 if(!(ispartset >= 3&& isprocset)){
202 throw "(PROC && PART) are mandatory arguments.";
206 int main(
int narg,
char *arg[]){
208 Tpetra::ScopeGuard tscope(&narg, &arg);
210 typedef Tpetra::MultiVector<zscalar_t, zlno_t, zgno_t, znode_t>
tMVector_t;
227 string taskGraphFile =
"";
228 string taskCoordFile =
"";
229 bool divide_prime =
false;
230 part_t jobX = 1, jobY = 1, jobZ = 1;
231 string procfile =
"";
232 int rank_per_node = 16;
234 const RCP<Comm<int> > commN;
235 RCP<Comm<int> >comm = Teuchos::rcp_const_cast<Comm<int> >
236 (Teuchos::DefaultComm<int>::getDefaultSerialComm(commN));
238 part_t *task_communication_xadj_ = NULL;
239 part_t *task_communication_adj_ = NULL;
240 zscalar_t *task_communication_adjw_ = NULL;
247 jobX, jobY, jobZ, divide_prime, rank_per_node, taskGraphFile, taskCoordFile);
251 numParts = jobZ*jobY*jobX;
255 if (taskGraphFile ==
"" || taskCoordFile ==
"")
258 partCenters =
new zscalar_t * [coordDim];
259 for(
int i = 0; i < coordDim; ++i){
260 partCenters[i] =
new zscalar_t[numParts];
264 task_communication_xadj_ =
new part_t [numParts+1];
265 task_communication_adj_ =
new part_t [numParts * 6];
268 task_communication_xadj_[0] = 0;
269 for (part_t i = 0; i < numParts; ++i) {
271 int y = (i / (jobX)) % jobY;
272 int z = (i / (jobX)) / jobY;
273 partCenters[0][i] = x;
274 partCenters[1][i] = y;
275 partCenters[2][i] = z;
278 task_communication_adj_[prevNCount++] = i - 1;
281 task_communication_adj_[prevNCount++] = i + 1;
284 task_communication_adj_[prevNCount++] = i - jobX;
287 task_communication_adj_[prevNCount++] = i + jobX;
290 task_communication_adj_[prevNCount++] = i - jobX * jobY;
293 task_communication_adj_[prevNCount++] = i + jobX * jobY;
295 task_communication_xadj_[i+1] = prevNCount;
300 FILE *f2 = fopen(taskGraphFile.c_str(),
"rb");
302 fread(&numParts,
sizeof(
int),1,f2);
303 fread(&ne,
sizeof(
int),1,f2);
306 std::cout <<
"numParts:" << numParts <<
" ne:" << ne << std::endl;
308 task_communication_xadj_ =
new part_t [numParts+1];
309 task_communication_adj_ =
new part_t [ne];
310 task_communication_adjw_ =
new zscalar_t [ne];
312 fread((
void *)task_communication_xadj_,
sizeof(
int),numParts + 1,f2);
313 fread((
void *)task_communication_adj_,
sizeof(
int),ne ,f2);
314 fread((
void *)task_communication_adjw_,
sizeof(
double),ne,f2);
317 f2 = fopen(taskCoordFile.c_str(),
"rb");
318 fread((
void *)&numParts,
sizeof(
int),1,f2);
319 fread((
void *)&coordDim,
sizeof(
int),1,f2);
321 std::cout <<
"numParts:" << numParts <<
" coordDim:" << coordDim << std::endl;
323 partCenters =
new zscalar_t * [coordDim];
324 for(
int i = 0; i < coordDim; ++i){
325 partCenters[i] =
new zscalar_t[numParts];
326 fread((
void *) partCenters[i],
sizeof(
double),numParts, f2);
335 std::vector < std::vector <zscalar_t> > proc_coords(procDim);
336 std::fstream m(procfile.c_str());
337 procCoordinates =
new zscalar_t * [procDim];
343 proc_coords[0].push_back(a);
344 proc_coords[1].push_back(b);
345 proc_coords[2].push_back(c);
352 for(
int ii = 0; ii < procDim; ++ii){
353 procCoordinates[ii] =
new zscalar_t[numProcs];
354 for (
int j = 0; j < numProcs; ++j){
355 procCoordinates[ii][j] = proc_coords[ii][j];
359 std::cout <<
"numProcs:" << numProcs << std::endl;
373 Teuchos::RCP<const Teuchos::Comm<int> > tcomm =Tpetra::getDefaultComm();
374 part_t *proc_to_task_xadj_ =
new part_t[numProcs+1];
375 part_t *proc_to_task_adj_ =
new part_t[numParts];
396 part_t *partArray = NULL;
397 int partArraysize = -1;
402 part_t *machineDimensions = NULL;
405 Zoltan2::coordinateTaskMapperInterface<part_t, zscalar_t, zscalar_t>(
415 task_communication_xadj_,
416 task_communication_adj_,
417 task_communication_adjw_,
424 machineDimensions, rank_per_node, divide_prime
427 if (tcomm->getRank() == 0){
428 std::cout <<
"PASS" << std::endl;
435 delete [] proc_to_task_xadj_;
436 delete [] proc_to_task_adj_;
437 delete [] task_communication_xadj_;
438 delete [] task_communication_adj_;
439 delete [] task_communication_adjw_;
441 for (
int i = 0; i < coordDim; i++)
delete [] partCenters[i];
442 delete [] partCenters;
443 for (
int i = 0; i < procDim; i++)
delete [] procCoordinates[i];
444 delete [] procCoordinates;
446 catch(std::string &s){
447 std::cerr << s << std::endl;
451 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.
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")
void getArgVals(int narg, char **arg, 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 &test_boxes, bool &rectilinear, int &mj_premigration_option, int &mj_coordinate_cutoff)
bool getArgumentValue(string &argumentid, double &argumentValue, string argumentline)