📄 xmdssequence.cc
字号:
else { fprintf(outfile,"_segment0();\n"); } fprintf(outfile,"\n"); } if(simulation()->parameters()->usempi&simulation()->parameters()->stochastic) { fprintf(outfile,"double* _temp_vector;\n"); fprintf(outfile,"unsigned long _length;\n"); fprintf(outfile,"\n"); for(unsigned long i=0;i<simulation()->output()->nMomentGroups();i++) { fprintf(outfile,"_length = _mg%li_size*_mg%li_fullstep_ncomponents;\n",i,i); fprintf(outfile,"_temp_vector = new double[_length];\n"); fprintf(outfile,"\n"); fprintf(outfile,"MPI_Reduce(_mg%li_fullstep,_temp_vector,_length,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD);\n",i); fprintf(outfile,"\n"); fprintf(outfile,"for(unsigned long _i0=0; _i0<_length; _i0++)\n"); fprintf(outfile," _mg%li_fullstep[_i0]=_temp_vector[_i0];\n",i); fprintf(outfile,"\n"); if(simulation()->parameters()->nPaths>1) { fprintf(outfile,"MPI_Reduce(_mg%li_fullstep_sd,_temp_vector,_length,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD);\n",i); fprintf(outfile,"\n"); fprintf(outfile,"for(unsigned long _i0=0; _i0<_length; _i0++)\n"); fprintf(outfile," _mg%li_fullstep_sd[_i0]=_temp_vector[_i0];\n",i); fprintf(outfile,"\n"); } if(simulation()->parameters()->errorCheck) { fprintf(outfile,"MPI_Reduce(_mg%li_halfstep,_temp_vector,_length,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD);\n",i); fprintf(outfile,"\n"); fprintf(outfile,"for(unsigned long _i0=0; _i0<_length; _i0++)\n"); fprintf(outfile," _mg%li_halfstep[_i0]=_temp_vector[_i0];\n",i); fprintf(outfile,"\n"); if(simulation()->parameters()->nPaths>1) { fprintf(outfile,"MPI_Reduce(_mg%li_halfstep_sd,_temp_vector,_length,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD);\n",i); fprintf(outfile,"\n"); fprintf(outfile,"for(unsigned long _i0=0; _i0<_length; _i0++)\n"); fprintf(outfile," _mg%li_halfstep_sd[_i0]=_temp_vector[_i0];\n",i); fprintf(outfile,"\n"); } } fprintf(outfile,"delete[] _temp_vector;\n"); fprintf(outfile,"\n"); } fprintf(outfile,"if(rank==0)\n"); fprintf(outfile," _write_output();\n"); fprintf(outfile,"\n"); } else if(simulation()->parameters()->usempi){ fprintf(outfile,"if(rank==0)\n"); fprintf(outfile," _write_output();\n"); fprintf(outfile,"\n"); } else { fprintf(outfile,"_write_output();\n"); fprintf(outfile,"\n"); } if(simulation()->parameters()->benchmark) { fprintf(outfile,"clock_t endTime = clock();\n"); fprintf(outfile,"int simTime = (endTime - startTime)/CLOCKS_PER_SEC;\n"); fprintf(outfile,"printf(\"Time elapsed for simulation is: %%d seconds\\n\",simTime);\n"); } simulation()->field()->writePlanDeletionCalls(outfile); simulation()->output()->writePlanDeletionCalls(outfile); if(simulation()->parameters()->usempi) { fprintf(outfile,"MPI_Finalize();\n"); fprintf(outfile,"\n"); } if (simulation()->parameters()->bing) { // this should be the last statement in the main() routine fprintf(outfile,"printf(\"\\a\");\n"); } fprintf(outfile,"return 0 ;\n"); fprintf(outfile,"}\n"); fprintf(outfile,"\n"); fprintf(outfile,"// *************************\n"); if(simulation()->parameters()->usempi) { fprintf(outfile,"void _segment0(\n"); fprintf(outfile," const int& size) {\n"); } else fprintf(outfile,"void _segment0() {\n"); fprintf(outfile,"\n"); for(list<const xmdsSegment*>:: const_iterator ppxmdsSegment = mySegmentList.begin(); ppxmdsSegment != mySegmentList.end(); ppxmdsSegment++) { (*ppxmdsSegment)->writeInitialisationCalls(outfile); } if(simulation()->parameters()->stochastic) { if(simulation()->parameters()->errorCheck) { if(simulation()->parameters()->usempi) { fprintf(outfile,"_gen1[0] = %li+rank;\n",simulation()->parameters()->seed[0]); fprintf(outfile,"_gen2[0] = %li+rank;\n",simulation()->parameters()->seed[1]); } else { fprintf(outfile,"_gen1[0] = %li;\n",simulation()->parameters()->seed[0]); fprintf(outfile,"_gen2[0] = %li;\n",simulation()->parameters()->seed[1]); } fprintf(outfile,"_gen1[1] = 0;\n"); fprintf(outfile,"_gen2[1] = 0;\n"); fprintf(outfile,"_gen1[2] = 0;\n"); fprintf(outfile,"_gen2[2] = 0;\n"); fprintf(outfile,"erand48(_gen1);\n"); fprintf(outfile,"erand48(_gen2);\n"); } else { if(simulation()->parameters()->usempi) { fprintf(outfile,"_gen[0] = %li+rank;\n",simulation()->parameters()->seed[0]); } else { fprintf(outfile,"_gen[0] = %li;\n",simulation()->parameters()->seed[0]); } fprintf(outfile,"_gen[1] = 0;\n"); fprintf(outfile,"_gen[2] = 0;\n"); fprintf(outfile,"erand48(_gen);\n"); } } const char* indent; if(simulation()->parameters()->nPaths>1) { if(simulation()->parameters()->usempi) { fprintf(outfile,"for(long _i0=rank;_i0<_n_paths;_i0+=size)"); } else { fprintf(outfile,"for(long _i0=0;_i0<_n_paths;_i0++)"); } indent=" "; fprintf(outfile," {\n"); } else indent=""; fprintf(outfile,"\n"); fprintf(outfile,"%s%s=0;\n",indent,simulation()->parameters()->propDimName.c_str()); fprintf(outfile,"\n"); simulation()->field()->writeInitialisationCalls(outfile,indent); for(unsigned long i=0;i<simulation()->output()->nMomentGroups();i++) { fprintf(outfile,"%s_mg%li_sample_pointer=0;\n",indent,i); if(simulation()->output()->momentGroup(i)->requiresIntegrations()|(simulation()->parameters()->usempi&!simulation()->parameters()->stochastic)) { fprintf(outfile,"%s_mg%li_raw_initialise();\n",indent,i); } } fprintf(outfile,"\n"); simulation()->field()->writeSampleCalls(outfile,indent); if(simulation()->parameters()->nPaths>1) { fprintf(outfile,"%sprintf(\"Starting path %%li\\n\",_i0+1);\n",indent); } for(list<const xmdsSegment*>::const_iterator ppxmdsSegment = mySegmentList.begin(); ppxmdsSegment != mySegmentList.end(); ppxmdsSegment++) { fprintf(outfile,"%s_segment%li(1);\n",indent,(*ppxmdsSegment)->segmentNumber); } fprintf(outfile,"\n"); for(unsigned long i=0;i<simulation()->output()->nMomentGroups();i++) { fprintf(outfile,"%s_mg%li_process();\n",indent,i); } if(simulation()->parameters()->nPaths>1) { fprintf(outfile," }\n"); } fprintf(outfile,"}\n"); fprintf(outfile,"\n"); } else { // I am a sub-sequence if(verbose()) { printf("Writing sequence routine ...\n"); } fprintf(outfile,"// ********************************************************\n"); fprintf(outfile,"// segment %li (sequence) routines\n",segmentNumber); fprintf(outfile,"\n"); fprintf(outfile,"// *************************\n"); fprintf(outfile,"void _segment%li(unsigned long cycle) {\n",segmentNumber); for(list<const xmdsSegment*>:: const_iterator ppxmdsSegment = mySegmentList.begin(); ppxmdsSegment != mySegmentList.end(); ppxmdsSegment++) { (*ppxmdsSegment)->writeInitialisationCalls(outfile); } fprintf(outfile,"for(unsigned long i=0; i<%li; i++) {\n",nCycles); for(list<const xmdsSegment*>::const_iterator ppxmdsSegment = mySegmentList.begin(); ppxmdsSegment != mySegmentList.end(); ppxmdsSegment++) { fprintf(outfile," _segment%li(i+1);\n", (*ppxmdsSegment)->segmentNumber); } fprintf(outfile," }\n"); fprintf(outfile,"}\n"); fprintf(outfile,"\n"); } xmdsElement::writeRoutines(outfile); fprintf(outfile,"\n");};// ******************************************************************************xmdsSegment* xmdsSequence::createxmdsSequence() { if(debugFlag) { printf("xmdsSequence::createxmdsSequence\n"); } xmdsSegment* newxmdsSegment = new xmdsSequence(simulation(),verbose()); addChild((xmdsElement*) newxmdsSegment); mySegmentList.push_back(newxmdsSegment); return newxmdsSegment;}// ******************************************************************************xmdsSegment* xmdsSequence::createxmdsIntegrateRK4EX() { if(debugFlag) { printf("xmdsSequence::createxmdsIntegrateRK4EX\n"); } xmdsSegment* newxmdsSegment = new xmdsIntegrateRK4EX(simulation(),verbose()); addChild((xmdsElement*) newxmdsSegment); mySegmentList.push_back(newxmdsSegment); return newxmdsSegment;}// ******************************************************************************xmdsSegment* xmdsSequence::createxmdsIntegrateRK4IP() { if(debugFlag) { printf("xmdsSequence::createxmdsIntegrateRK4IP\n"); } xmdsSegment* newxmdsSegment = new xmdsIntegrateRK4IP(simulation(),verbose()); addChild((xmdsElement*) newxmdsSegment); mySegmentList.push_back(newxmdsSegment); return newxmdsSegment;}// ******************************************************************************xmdsSegment* xmdsSequence::createxmdsIntegrateSIEX() { if(debugFlag) { printf("xmdsSequence::createxmdsIntegrateSIEX\n"); } xmdsSegment* newxmdsSegment = new xmdsIntegrateSIEX(simulation(),verbose()); addChild((xmdsElement*) newxmdsSegment); mySegmentList.push_back(newxmdsSegment); return newxmdsSegment;}// ******************************************************************************xmdsSegment* xmdsSequence::createxmdsIntegrateSIIP() { if(debugFlag) { printf("xmdsSequence::createxmdsIntegrateSIIP\n"); } xmdsSegment* newxmdsSegment = new xmdsIntegrateSIIP(simulation(),verbose()); addChild((xmdsElement*) newxmdsSegment); mySegmentList.push_back(newxmdsSegment); return newxmdsSegment;}// ******************************************************************************xmdsSegment* xmdsSequence::createxmdsFilter() { if(debugFlag) { printf("xmdsSequence::createxmdsIntegrateFilter\n"); } xmdsSegment* newxmdsSegment = new xmdsFilter(simulation(),verbose()); addChild((xmdsElement*) newxmdsSegment); mySegmentList.push_back(newxmdsSegment); return newxmdsSegment;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -