📄 main.cc
字号:
cout << "-----------------------------\n"; cout << "The simulation header follows:\n"; for (unsigned int i=0; i<simHeaderText.size(); i++) { cout << simHeaderText[i] << "\n"; } cout << "-----------------------------\n"; } if (debugFlag) { // have a look at the body if it exists cout << "-----------------------------\n"; cout << "The simulation body follows:\n"; for (unsigned int i=0; i<simBodyText.size(); i++) { cout << simBodyText[i] << "\n"; } cout << "-----------------------------\n"; } if (!foundSimEndTag) { printf("Failed to find the string \"</simulation>\" within the simulation text\n"); printf("Exiting\n"); // I'm sure we should do something more intelligent here... return 1; } if (debugFlag) { // have a look at the footer if it exits cout << "-----------------------------\n"; cout << "The simulation footer follows:\n"; for (unsigned int i=0; i<simFooterText.size(); i++) { cout << simFooterText[i] << "\n"; } cout << "-----------------------------\n"; } } catch(XMLParserException XMLRoutinesErr) { printf("Could not load Document\n"); printf("due to the following XMLParserException:\n"); printf("%s",XMLRoutinesErr.getError()); printf("Exiting.\n"); return 1; } if(*theDocument->documentElement()->nodeName() != "simulation") { printf("Error: Expecting root element in '%s' to be <simulation>\n",infilename); printf("Exiting.\n"); return 1; } unsigned long xmdsBytePoint = myXMLParser.xmdsBytePoint(); // create the xmdsSimulation xmdsSimulation myxmdsSimulation(infilename,verbose,strcmp(MPICC,"")); if(verbose) { printf("Processing simulation ...\n"); } // print out some info about xmds printf("This is xmds, version %s-%s\n", myxmdsSimulation.parameters()->version.c_str(), myxmdsSimulation.parameters()->release.c_str()); printf("Copyright 2000-2004 Greg Collecutt, Joseph Hope, Paul Cochrane and others\n"); printf("xmds is available from http://www.xmds.org\n\n"); try { myxmdsSimulation.processElement(theDocument->documentElement()); } catch (xmdsException xmdsExceptionErr) { printf("Error: simulation element could not be processed\n"); printf("due to the following xmdsException:\n"); printf("%s",xmdsExceptionErr.getError()); printf("Exiting.\n"); return 1; } if(verbose) { printf("Writing output code ...\n"); } try { myxmdsSimulation.makeCode(xmdsBytePoint); } catch (xmdsException xmdsExceptionErr) { printf("Error: simulation failed to write output code\n"); printf("due to the following xmdsException:\n"); printf("%s",xmdsExceptionErr.getError()); printf("Exiting.\n"); return 1; } string cc = XMDS_CC; string cflags = XMDS_CFLAGS; string mpicc = MPICC; string mpicflags = MPICCFLAGS; string cincludes = XMDS_INCLUDES; string clibs = XMDS_LIBS; string fftwlibs = FFTW_LIBS; string fftw_mpi_libs = FFTW_MPI_LIBS; string cthreadlibs = THREADLIBS; // this is just some code to show what the defaults are if (verbose) { cout << "Defaults: (from when xmds was built)\n" << " cc = " << cc << "\n" << " cflags = " << cflags << "\n" << " mpicc = " << mpicc << "\n" << " mpicflags = " << mpicflags << "\n" << " cincludes = " << cincludes << "\n" << " clibs = " << clibs << "\n" << " fftwlibs = " << fftwlibs << "\n" << " fftw_mpi_libs = " << fftw_mpi_libs << "\n" << " cthreadlibs = " << cthreadlibs << "\n"; } // if the usePrefs flag is true then try to find the prefs file // and then try to parse it, falling back to the above values if // we fail if (myxmdsSimulation.parameters()->usePrefs) { if (verbose) { printf("Using user-defined preferences\n"); } // now try and open the file // first look in ~/.xmds/xmds.prefs // work out what the home directory is ifstream fIn, fPrefs; string findHomeString, homeStuff, homeDir, rmString; homeStuff = "home.stuff"; findHomeString = "echo $HOME > " + homeStuff; system(findHomeString.c_str()); fIn.open(homeStuff.c_str()); if (fIn.fail()) { // do something } fIn >> homeDir; fIn.close(); rmString = "rm " + homeStuff; system(rmString.c_str()); // ~/.xmds/xmds.prefs string prefsFname; prefsFname = homeDir + "/.xmds/xmds.prefs"; fPrefs.open(prefsFname.c_str()); if (!fPrefs.fail()) { if (verbose) { printf("Prefs file found: %s\n", prefsFname.c_str()); } // ok, now try and parse the sucker... parsePrefs(fPrefs, cc, cflags, clibs, cincludes, cthreadlibs, mpicc, mpicflags, fftwlibs, fftw_mpi_libs, verbose, debugFlag); fPrefs.close(); } // if that didn't work, try the local directory else if (fPrefs.fail()) { string localDir; if (verbose) { printf("Prefs file not found at %s\n", prefsFname.c_str()); printf("Trying in the local directory\n"); // work out what the local directory is, and report it system("echo $PWD > localDir.test"); fIn.open("localDir.test"); if (fIn.fail()) { // do something } fIn >> localDir; fIn.close(); system("rm localDir.test"); printf("The local directory is %s\n", localDir.c_str()); } prefsFname = "xmds.prefs"; ifstream fPrefs; // need to define fPrefs again (local to this block) fPrefs.open(prefsFname.c_str()); if (!fPrefs.fail()) { if (verbose) { printf("Prefs file found in local directory: %s\n", localDir.c_str()); } // ok, now try and parse the sucker... parsePrefs(fPrefs, cc, cflags, clibs, cincludes, cthreadlibs, mpicc, mpicflags, fftwlibs, fftw_mpi_libs, verbose, debugFlag); fPrefs.close(); } // if we get to here, and things have still failed, print a warning // and just use the defaults else if (fPrefs.fail() && verbose) { printf("Warning: no preferences file found. Using default values instead\n"); } } } if (!myxmdsSimulation.parameters()->usePrefs && verbose) { printf("Warning: User-defined preferences NOT being used. Using defaults instead\n"); } // this is just some code to show what the compilation values are after the prefs have been added if (verbose) { cout << "User defined preferences: (some will be the default values)\n" << "These are used by xmds to build the simulation\n" << " cc = " << cc << "\n" << " cflags = " << cflags << "\n" << " mpicc = " << mpicc << "\n" << " mpicflags = " << mpicflags << "\n" << " cincludes = " << cincludes << "\n" << " clibs = " << clibs << "\n" << " fftwlibs = " << fftwlibs << "\n" << " fftw_mpi_libs = " << fftw_mpi_libs << "\n" << " cthreadlibs = " << cthreadlibs << "\n"; } // now set up the system command to compile the simulation char command[1024]; if (compileFlag) { if(myxmdsSimulation.parameters()->usempi) { if(myxmdsSimulation.parameters()->nThreads>1) { printf("compiling for MPI parallel execution with threads...\n"); sprintf(command,"%s -D_REENTRANT %s -o %s %s.cc %s %s %s",mpicc.c_str(),mpicflags.c_str(), myxmdsSimulation.parameters()->simulationName.c_str(), myxmdsSimulation.parameters()->simulationName.c_str(), cincludes.c_str(),cthreadlibs.c_str(),fftw_mpi_libs.c_str()); printf(" %s\n",command); if(system(command)) { printf("compilation failed.\n"); return 1; } } else if(!(myxmdsSimulation.parameters()->stochastic)){ printf("compiling for MPI parallel execution for a nondeterministic simulation...\n"); sprintf(command,"%s %s -o %s %s.cc %s %s",mpicc.c_str(),mpicflags.c_str(), myxmdsSimulation.parameters()->simulationName.c_str(), myxmdsSimulation.parameters()->simulationName.c_str() ,cincludes.c_str(),fftw_mpi_libs.c_str()); printf(" %s\n",command); if(system(command)) { printf("compilation failed.\n"); return 1; } } else { printf("compiling for MPI parallel execution ...\n"); sprintf(command,"%s %s -o %s %s.cc %s %s",mpicc.c_str(),mpicflags.c_str(), myxmdsSimulation.parameters()->simulationName.c_str(), myxmdsSimulation.parameters()->simulationName.c_str(), cincludes.c_str(),fftw_mpi_libs.c_str()); printf(" %s\n",command); if(system(command)) { printf("compilation failed.\n"); return 1; } } } else { if(myxmdsSimulation.parameters()->nThreads>1) { printf("compiling for threaded parallel execution...\n"); sprintf(command,"%s -D_REENTRANT %s -o %s %s.cc %s %s %s",cc.c_str(),cflags.c_str(), myxmdsSimulation.parameters()->simulationName.c_str(), myxmdsSimulation.parameters()->simulationName.c_str(), cincludes.c_str(),cthreadlibs.c_str(),fftwlibs.c_str()); printf(" %s\n",command); if(system(command)) { printf("compilation failed.\n"); return 1; } } else { printf("compiling ...\n"); sprintf(command,"%s %s -o %s %s.cc %s %s %s",cc.c_str(),cflags.c_str(), myxmdsSimulation.parameters()->simulationName.c_str(), myxmdsSimulation.parameters()->simulationName.c_str(), cincludes.c_str(),clibs.c_str(),fftwlibs.c_str()); printf(" %s\n",command); if(system(command)) { printf("compilation failed.\n"); return 1; } } } printf("\n%s ready to execute\n",myxmdsSimulation.parameters()->simulationName.c_str()); } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -