int main(int argc, char *argv[]) { long i; graph G; double runtime; inputCheck(argc, argv); if(N == 1){ generateTestGraph(&G); } else { generateGraph(N, randInit, &G, 0); } tick(); dijkstra(&G, 0, 0); runtime = tack(); // char *b; b = malloc(G.N * 5); if(b == NULL) {perror("malloc"); exit(EXIT_FAILURE); } sprintf(b,"\nLowest distances!\nD=["); for(i = 0; i<G.N; i++){ sprintf(&b[strlen(b)], "%d,", G.D[i]); } printf("%s]\n", b); printf("Was working for [%f] sec.\n",runtime); return EXIT_SUCCESS; }
// Constructor - creates the Epetra objects (maps and vectors) ConvDiff_PDE::ConvDiff_PDE( Epetra_Comm& Comm_ , double peclet_ , double radiation_ , double kappa_ , double bcWeight_ , double xmin_ , double xmax_ , double Tleft_ , double Tright_ , int NumGlobalUnknowns_ , std::string name_ ) : GenericEpetraProblem(Comm_, NumGlobalUnknowns_, name_), xmin ( xmin_ ) , xmax ( xmax_ ) , Tleft ( Tleft_ ) , Tright ( Tright_ ) , peclet ( peclet_ ) , radiation ( radiation_ ) , kappa ( kappa_ ) , bcWeight ( bcWeight_ ) , expandJacobian ( true ) , depProbPtr ( NULL ) { // Create mesh and solution vectors // We first initialize the mesh and then the solution since the latter can depend on the mesh. xptr = Teuchos::rcp( new Epetra_Vector(*StandardMap) ); dx = (xmax - xmin) / ( (double) NumGlobalNodes - 1 ); for( int i = 0; i < NumMyNodes; ++i ) (*xptr)[i]=xmin + dx*((double) StandardMap->MinMyGID()+i); // Create extra vector needed for transient problem interface oldSolution = Teuchos::rcp( new Epetra_Vector(*StandardMap) ); // Create and initialize (using default provided) the solution vector initialSolution = Teuchos::rcp(new Epetra_Vector(*StandardMap)); initializeSolution(); // Allocate the memory for a matrix dynamically (i.e. the graph is dynamic). AA = Teuchos::rcp( new Epetra_CrsGraph(Copy, *StandardMap, 0) ); generateGraph(); #ifdef DEBUG AA->Print(cout); #endif // Create a matrix using the graph just created - this creates a // static graph so we can refill the new matirx after FillComplete() // is called. A = Teuchos::rcp(new Epetra_CrsMatrix (Copy, *AA)); A->FillComplete(); // Create the Importer needed for FD coloring ColumnToOverlapImporter = Teuchos::rcp( new Epetra_Import(A->ColMap(),*OverlapMap) ); }
// Constructor - creates the Epetra objects (maps and vectors) HMX_PDE::HMX_PDE(Epetra_Comm& comm, double diffCoef_, double Const_R_, double Steric_C_, double PreExp_A_, double ActEnergy_, map<string, double> SrcTermExponent_, map<string, double> SrcTermWeight_, int numGlobalNodes, std::string name_) : GenericEpetraProblem(comm, numGlobalNodes, name_), xmin(0.0), xmax(1.0), dt(2.0e-1), diffCoef(diffCoef_), Const_R(Const_R_), StericCoef(Steric_C_), PreExp_A(PreExp_A_), ActEnergy(ActEnergy_), SrcTermExponent(SrcTermExponent_), SrcTermWeight(SrcTermWeight_) { // Create mesh and solution vectors // We first initialize the mesh and then the solution since the latter // can depend on the mesh. xptr = Teuchos::rcp( new Epetra_Vector(*StandardMap) ); double Length= xmax - xmin; dx=Length/((double) NumGlobalNodes-1); for (int i=0; i < NumMyNodes; i++) { (*xptr)[i]=xmin + dx*((double) StandardMap->MinMyGID()+i); } // Create extra vector needed for this transient problem oldSolution = new Epetra_Vector(*StandardMap); // Next we create and initialize (using default provided) the solution vector initialSolution = Teuchos::rcp(new Epetra_Vector(*StandardMap)); initializeSolution(); // Allocate the memory for a matrix dynamically (i.e. the graph is dynamic). AA = Teuchos::rcp( new Epetra_CrsGraph(Copy, *StandardMap, 0) ); generateGraph(); #ifdef DEBUG AA->Print(cout); #endif // Create a matrix using the graph just created - this creates a // static graph so we can refill the new matirx after FillComplete() // is called. A = Teuchos::rcp(new Epetra_CrsMatrix (Copy, *AA)); A->FillComplete(); // Create the Importer needed for FD coloring ColumnToOverlapImporter = new Epetra_Import(A->ColMap(),*OverlapMap); }
int main(int argc, char *argv[]) { if (argc != 4) { std::cout << argv[0] << "input.m patchnum sampling\n"; exit(-1); } int patchnum = atoi(argv[2]); double threshold = atof(argv[3]); srand (static_cast <unsigned> (time(0))); //load seeds; std::vector<Patch*> patches; //loadSeeds("seed_sim.m", patches); //loadSeeds("seed2.m", patches); Mesh *mesh = new Mesh; mesh->readMFile(argv[1]); generateSeeds(mesh, patches, patchnum); for (int i = 0; i <= 500; ++i) { /*if (i % 100 == 0) { sprintf_s(buf, "center_%d.cm", i+1); saveCenters(buf, patches); }*/ clustering(mesh, patches); checkPatches(patches); update(patches); /*if (i % 100 == 0) { sprintf_s(buf, "out_%d.m", i+1); mesh->writeMFile(buf); }*/ } mesh->writeMFile("end.m"); std::cout << "end!\n"; traceBoundary(patches); DualGraph *dualGraph = generateGraph(patches); sampling(patches, avg_length); delete dualGraph; delete mesh; return 0; }
int ladderLength(string beginWord, string endWord, unordered_set<string>& wordList) { if(beginWord == endWord) return 1; vector<string> myStrVec; myStrVec.push_back(beginWord); for(unordered_set<string>::iterator it=wordList.begin(); it!=wordList.end(); it++) { if((*it) != beginWord && (*it) != endWord) myStrVec.push_back(*it); } myStrVec.push_back(endWord); vector<vector<neighbor>> myAdjList = generateGraph(myStrVec); vector<int> prevNode; vector<double> minDist; dijkstraPathFinder(0, myStrVec.size()-1, myAdjList, prevNode, minDist); list<int> myPath = dijkstraPathTo(myStrVec.size()-1, prevNode); return myPath.size()<=1 ? 0 : myPath.size(); }
// Constructor - creates the Epetra objects (maps and vectors) Pitchfork_FiniteElementProblem::Pitchfork_FiniteElementProblem( int numGlobalElements, Epetra_Comm& comm) : flag(F_ONLY), StandardMap(NULL), OverlapMap(NULL), Importer(NULL), initialSolution(NULL), rhs(NULL), AA(NULL), A(NULL), Comm(&comm), MyPID(0), NumProc(0), NumMyElements(0), NumGlobalElements(numGlobalElements), lambda(0.0), alpha(0.0), beta(0.0) { // Commonly used variables int i; MyPID = Comm->MyPID(); // Process ID NumProc = Comm->NumProc(); // Total number of processes // Construct a Source Map that puts approximately the same // Number of equations on each processor in uniform global ordering StandardMap = new Epetra_Map(NumGlobalElements, 0, *Comm); // Get the number of elements owned by this processor NumMyElements = StandardMap->NumMyElements(); // Construct an overlaped map for the finite element fill ************* // For single processor jobs, the overlap and standard map are the same if (NumProc == 1) { OverlapMap = new Epetra_Map(*StandardMap); } else { int OverlapNumMyElements; int OverlapMinMyGID; OverlapNumMyElements = NumMyElements + 2; if ((MyPID == 0) || (MyPID == NumProc - 1)) OverlapNumMyElements --; if (MyPID==0) OverlapMinMyGID = StandardMap->MinMyGID(); else OverlapMinMyGID = StandardMap->MinMyGID() - 1; int* OverlapMyGlobalElements = new int[OverlapNumMyElements]; for (i = 0; i < OverlapNumMyElements; i ++) OverlapMyGlobalElements[i] = OverlapMinMyGID + i; OverlapMap = new Epetra_Map(-1, OverlapNumMyElements, OverlapMyGlobalElements, 0, *Comm); delete [] OverlapMyGlobalElements; } // End Overlap map construction ************************************* // Construct Linear Objects Importer = new Epetra_Import(*OverlapMap, *StandardMap); initialSolution = new Epetra_Vector(*StandardMap); AA = new Epetra_CrsGraph(Copy, *StandardMap, 5); // Allocate the memory for a matrix dynamically (i.e. the graph is dynamic). generateGraph(*AA); // Create a second matrix using graph of first matrix - this creates a // static graph so we can refill the new matirx after FillComplete() // is called. A = new Epetra_CrsMatrix (Copy, *AA); A->FillComplete(); // Set default bifurcation values lambda = -2.25; alpha = 1.0; beta = 0.0; }
int main(int argc, char **argv) { long i; graph G; char debugFlag = 0; debugFlag=0; MPI_Init(&argc, &argv); MPI_Comm_rank (MPI_COMM_WORLD, &mpi_id); /* get current process id */ MPI_Comm_size (MPI_COMM_WORLD, &mpi_size); /* get number of processes */ inputCheck(argc, argv); if(mpi_id == 0) { if(N == 1){ generateTestGraph(&G); } else { generateGraph(N, randInit, &G, debugFlag); } } else { if(N == 1) N = 6; generateEmptyGraph(N, &G); } N = G.N; if(debugFlag){ enableDebug(N); } if((debugFlag == 1) && (mpi_id == 0) ){ printf("Using graph\n"); printGraph(&G); } if(mpi_id == 0) printf("\nTesting with max 2 Threads\n"); testScheduler(2,&G, debugFlag); if(mpi_id == 0) printf("\nTesting with max 4 Threads\n"); testScheduler(4,&G, debugFlag); if(mpi_id == 0) printf("\nTesting with max 8 Threads\n"); testScheduler(8,&G, debugFlag); // omp_set_num_threads(4); // omp_set_schedule(omp_sched_static, 2); // dijkstra(&G, 0, 0); // char *b; // b = malloc(G.N * 5); // if(b == NULL) {perror("malloc"); exit(EXIT_FAILURE); } // sprintf(b,"\nLowest distances!\nD=["); // for(i = 0; i<G.N; i++){ // sprintf(&b[strlen(b)], "%d,", G.D[i]); // } // printf("%s]\n", b); MPI_Finalize(); return EXIT_SUCCESS; }
int main(int argc, char** argv) { global.debug = 0; global.verbose = 0; uint i,j; const long seed = time(0); srand(seed); if (global.verbose) printf("seed = %li\n",seed); FILE* output; uint n,v,nb; long timeS; if (argc < 7) { printf("Argument error !\n"); printf("syntax : %s filename n V\nn = number of items, V = bag volume\n",argv[0]); return 0; } uint nMin,nMax,vMin,vMax; graph* g = 0; path* p = 0; nb = atoi(argv[2]); nMin = atoi(argv[3]); nMax = atoi(argv[4]); vMin = atoi(argv[5]); vMax = atoi(argv[6]); if (!(output = fopen(argv[1],"a"))) { perror("File error."); exit(EXIT_FAILURE); } for (i = 0 ; i < nb ; i++) { n = rand() % (nMax - nMin) + nMin; g = generateGraph(n,vMin,vMax); timeS = time(0); p = tsp(g); timeS = time(0)-timeS; printf("[TEST] %i : n = %i (%li seconds)\n",i,n,timeS); fprintf(output,"%u %li\n",n,timeS,v); freeGraph(g); freePath(p); g = 0; p = 0; } fclose(output); /* // ex prog dyn g = createGraph(5); for (i = 0 ; i < 5 ; i++) setEdge(g,i,i,50); setEdge(g,0,1,1); setEdge(g,0,2,2); setEdge(g,0,3,1); setEdge(g,0,4,0); setEdge(g,1,2,3); setEdge(g,1,3,5); setEdge(g,1,4,0); setEdge(g,2,3,2); setEdge(g,2,4,1); setEdge(g,3,4,4); printGraph(g); p = tsp(g); printPath(p); freePath(p); freeGraph(g); */ return EXIT_SUCCESS; }
void GraphParser::extractGraph(){ parseFile(); generateGraph(); }
// Constructor - creates the Epetra objects (maps and vectors) Brusselator::Brusselator(int numGlobalNodes, Epetra_Comm& comm) : xmin(0.0), xmax(1.0), Comm(&comm), NumGlobalNodes(numGlobalNodes), ColumnToOverlapImporter(0), AA(0), A(0), alpha(0.25), beta(1.5), D1(1.0/40.0), D2(1.0/40.0) { // Commonly used variables int i; MyPID = Comm->MyPID(); // Process ID NumProc = Comm->NumProc(); // Total number of processes // Here we assume a 2-species Brusselator model, ie 2 dofs per node // Note that this needs to be echoed in thew anonymous enum for NUMSPECIES. NumSpecies = 2; NumGlobalUnknowns = NumSpecies * NumGlobalNodes; // Construct a Source Map that puts approximately the same // number of equations on each processor // Begin by distributing nodes fairly equally StandardNodeMap = new Epetra_Map(NumGlobalNodes, 0, *Comm); // Get the number of nodes owned by this processor NumMyNodes = StandardNodeMap->NumMyElements(); // Construct an overlap node map for the finite element fill // For single processor jobs, the overlap and standard maps are the same if (NumProc == 1) OverlapNodeMap = new Epetra_Map(*StandardNodeMap); else { int OverlapNumMyNodes; int OverlapMinMyNodeGID; OverlapNumMyNodes = NumMyNodes + 2; if ((MyPID == 0) || (MyPID == NumProc - 1)) OverlapNumMyNodes --; if (MyPID==0) OverlapMinMyNodeGID = StandardNodeMap->MinMyGID(); else OverlapMinMyNodeGID = StandardNodeMap->MinMyGID() - 1; int* OverlapMyGlobalNodes = new int[OverlapNumMyNodes]; for (i = 0; i < OverlapNumMyNodes; i ++) OverlapMyGlobalNodes[i] = OverlapMinMyNodeGID + i; OverlapNodeMap = new Epetra_Map(-1, OverlapNumMyNodes, OverlapMyGlobalNodes, 0, *Comm); delete [] OverlapMyGlobalNodes; } // End Overlap node map construction ******************************** // Now create the unknowns maps from the node maps NumMyUnknowns = NumSpecies * NumMyNodes; int* StandardMyGlobalUnknowns = new int[NumMyUnknowns]; for (int k=0; k<NumSpecies; k++) for (i=0; i<NumMyNodes; i++) { // For now, we employ an interleave of unknowns StandardMyGlobalUnknowns[ NumSpecies * i + k ] = NumSpecies * StandardNodeMap->GID(i) + k; } StandardMap = new Epetra_Map(-1, NumMyUnknowns, StandardMyGlobalUnknowns, 0, *Comm); delete [] StandardMyGlobalUnknowns; assert(StandardMap->NumGlobalElements() == NumGlobalUnknowns); if (NumProc == 1) { OverlapMap = new Epetra_Map(*StandardMap); } else { int OverlapNumMyNodes = OverlapNodeMap->NumMyElements(); int OverlapNumMyUnknowns = NumSpecies * OverlapNumMyNodes; int* OverlapMyGlobalUnknowns = new int[OverlapNumMyUnknowns]; for (int k=0; k<NumSpecies; k++) for (i=0; i<OverlapNumMyNodes; i++) OverlapMyGlobalUnknowns[ NumSpecies * i + k ] = NumSpecies * OverlapNodeMap->GID(i) + k; OverlapMap = new Epetra_Map(-1, OverlapNumMyUnknowns, OverlapMyGlobalUnknowns, 0, *Comm); delete [] OverlapMyGlobalUnknowns; } // End Overlap unknowns map construction *************************** // Construct Linear Objects Importer = new Epetra_Import(*OverlapMap, *StandardMap); nodeImporter = new Epetra_Import(*OverlapNodeMap, *StandardNodeMap); initialSolution = new Epetra_Vector(*StandardMap); AA = new Epetra_CrsGraph(Copy, *StandardMap, 0); // Allocate the memory for a matrix dynamically (i.e. the graph is dynamic). generateGraph(*AA); // Create the matrix A = new Epetra_CrsMatrix (Copy, *AA); A->FillComplete(); // Create the nodal coordinates xptr = new Epetra_Vector(*StandardNodeMap); double Length= xmax - xmin; dx=Length/((double) NumGlobalNodes-1); for (i=0; i < NumMyNodes; i++) { (*xptr)[i]=xmin + dx*((double) StandardNodeMap->MinMyGID()+i); } initializeSoln(); }