void main(int argc, char **argv) { /*--- Add rng_type as the argument to the new interface ---*/ int rng_type; int seed, param, block_size, discard_blocks, use_blocks; /****************** Read and check Arguments ********************/ if(argc==8 ) /*--- increase argc by 1 ---*/ { argv++; rng_type = atoi(*argv++); /*--- get rng_type ---*/ seed = atoi(*argv++); param = atoi(*argv++); lattice_size = atoi(*argv++); block_size = atoi(*argv++); discard_blocks = atoi(*argv++); use_blocks = atoi(*argv++); check_arguments(lattice_size, block_size, discard_blocks, use_blocks); #ifdef PARALLEL printf("Wolff Algorithm with Parallel RNG\n"); #else printf("Wolff Algorithm with Serial RNG\n"); #endif printf("lattice_size = %d, block_size = %d, discard_blocks = %d, use_blocks = %d\n", lattice_size, block_size, discard_blocks, use_blocks); } else { printf("USAGE: %s rng_type seed param lattice_size block_size discard_blocks use_blocks\n", argv[0]); exit(-1); } minitialize(rng_type, seed, param, use_blocks); /* initalize data */ /************** 'Thermalize' system so that results are not influenced by the initial onditions *************/ thermalize(block_size, discard_blocks); /********** Perform the actual Wolff algorithm calculations *********/ wolff(block_size, use_blocks); }
void main(int argc, char **argv) { int seed, param, block_size, discard_blocks, use_blocks; /****************** Read and check Arguments ********************/ if(argc==7 ) { argv++; seed = atoi(*argv++); param = atoi(*argv++); lattice_size = atoi(*argv++); block_size = atoi(*argv++); discard_blocks = atoi(*argv++); use_blocks = atoi(*argv++); check_arguments(lattice_size, block_size, discard_blocks, use_blocks); #ifdef PARALLEL printf("Wolff Algorithm with Parallel RNG\n"); #else printf("Wolff Algorithm with Serial RNG\n"); #endif printf("lattice_size = %d, block_size = %d, discard_blocks = %d, use_blocks = %d\n", lattice_size, block_size, discard_blocks, use_blocks); } else { printf("USAGE: %s seed param lattice_size block_size discard_blocks use_blocks\n", argv[0]); exit(-1); } initialize(seed, param, use_blocks); /* initalize data */ /************** 'Thermalize' system so that results are not influenced by the initial onditions *************/ thermalize(block_size, discard_blocks); /********** Perform the actual Wolff algorithm calculations *********/ wolff(block_size, use_blocks); }
double VMCSolver::runMonteCarloIntegration() { nAccepted=0; nRejected=0; rOld = zeros<mat>(nParticles, nDimensions); rNew = zeros<mat>(nParticles, nDimensions); double energySum = 0; double energySquaredSum = 0; double deltaE; // initialise trial positions for(int i = 0; i < nParticles; i++) { for(int j = 0; j < nDimensions; j++) { rOld(i,j)=sqrt(h)*this->gaussianDeviate(&idum); } } initialize(); // loop over Monte Carlo cycles int my_start=0; int my_end=local_nCycles; double r12 = 0; thermalize(); for(int cycle = my_start; cycle < my_end; cycle++) { // if(cycle%(my_end/100)==0) // cout << "Currently in cycle "<< cycle<<endl; if(cycle%nrOfCyclesEachOutput==0 && createOutput && cycle >0){ datalogger.flushData(); } // New position to test for(int i = 0; i < nParticles; i++) { this->currentparticle=i; wf.setCurrentParticle(i); this->cycle(i); } //collect data deltaE = wf.localEnergyCF(rNew); if(createOutput){ datalogger.addData(deltaE); } energySum += deltaE; energySquaredSum += deltaE*deltaE; } if(createOutput){ datalogger.flushFinalData(); } double energy = energySum/(local_nCycles); double energySquared = energySquaredSum/(local_nCycles); double totalenergy=0; double totalenergySquared=0; int totalaccepted=0, totalrejected=0; //1 processor receives all information //MPI_Reduce(&energy, &totalenergy, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); //all processors receive all information MPI_Allreduce(&energy, &totalenergy, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); totalenergy/=numprocs; MPI_Allreduce(&nAccepted, &totalaccepted, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); MPI_Allreduce(&nRejected, &totalrejected, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); MPI_Allreduce(&energySquared, &totalenergySquared, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); totalenergySquared/=numprocs; acceptRatio=double(totalaccepted)/(totalrejected+totalaccepted); double variance = totalenergySquared-pow(totalenergy,2); cout << "Energy: " << totalenergy << " Energy (squared sum): " << totalenergySquared << endl; cout << "Variance: "<< variance<<endl; cout << "Total acceptratio: " <<acceptRatio << endl; return totalenergy; }