void displayMat(int rows, int cols, const double *vPtr) { if(dlayout == RowMaj) { int i; printf("[\n"); for (i = 0; i < rows; i++) { displayVec(cols, &vPtr[i*rows]); printf("\n"); } printf("]\n"); } else { int i,j; printf("[\n"); for (i = 0; i < rows; i++) { printf("["); for (j = 0; j < cols; j++) { printf("%e", (vPtr + cols * j)[i]); if (j < cols - 1) printf(","); else printf("]"); } printf("\n"); } printf("]\n"); } }
int main() { std::cout << "****** ang2vec ******" << std::endl; double theta = PI / 2; double phi = PI / 2; double vec[3]; ang2vec(theta, phi, vec); displayVec(vec); std::cout << "****** npix2nisde ******" << std::endl; long npix = 786432; std::cout << npix2nside(npix) << std::endl; std::cout << "****** nside2npix ******" << std::endl; long nside = 256; std::cout << nside2npix(nside) << std::endl; std::cout << "****** pix2ang ******" << std::endl; long ipring = 10000; // ipring -> Index_Pixel_Ring pix2ang_ring(nside, ipring, &theta, &phi); std::cout << "theta = " << theta << std::endl; std::cout << "phi = " << phi << std::endl; std::cout << "****** pix2vec ******" << std::endl; pix2vec_ring(nside, ipring, vec); displayVec(vec); std::cout << "****** ang2pix ******" << std::endl; ang2pix_ring(nside, theta, phi, &ipring); std::cout << "ipring = " << ipring << std::endl; std::cout << "****** vec2pix ******" << std::endl; vec2pix_ring(nside, vec, &ipring); std::cout << "ipring = " << ipring << std::endl; std::cout << "****** ring2nest ******" << std::endl; long ipnest; ring2nest(nside, ipring, &ipnest); std::cout << "ipnest = " << ipnest << std::endl; std::cout << "****** nest2ring ******" << std::endl; nest2ring(nside, ipnest, &ipring); std::cout << "ipring = " << ipring << std::endl; }
int main(int argc, char *argv[]) { BuilderAbstract * builder = new Builder(std::cin); builder->Initialize(); OptPondSolver * optPondSolver = builder->release(); Gecode::DFS<OptPondSolver> dfsOptPondSolver( optPondSolver ); while( OptPondSolver * ops = dfsOptPondSolver.next() ) { displayVec(ops->lireSolution()); } return 0; }
void PDA::display() { cout << "PDA = (K,Sigma,Tau,Delta,q0,Z0,F)\n"; cout << "K = "; displayVec(K); cout << endl; cout << "Sigma = "; displayVec(Sigma); cout << endl; cout << "Tau = "; displayVec(Tau); cout << endl; cout << "q0 = " << q0 << endl; cout << "Z0 = " << Z0 << endl; cout << "F = "; displayVec(F); cout << endl; cout << "Delta:\n"; for(size_t i = 0; i < Delta.size(); ++i) { for(size_t j = 0; j < Delta[i].size(); ++j) { for(size_t k = 0; k < Delta[i][j].size(); ++k) { cout << "Delta(" << K[i] << ","; if(j == Sigma.size()) { cout << "e"; } else { cout << Sigma[j]; } cout << "," << Tau[k] << ") = {"; for(size_t l = 0; l < Delta[i][j][k].size(); ++l) { cout << "(" << Delta[i][j][k][l].nextState << ","; if(!Delta[i][j][k][l].strToPush.empty()) { for_each(Delta[i][j][k][l].strToPush.begin(), Delta[i][j][k][l].strToPush.end(), [](const string& str) { cout << str; }); } else { cout << "e"; } cout << ")"; if(l != Delta[i][j][k].size() - 1) { cout << ","; } } cout << "}" << endl; } } } }
int main(int argc, const char *argv[]) { // Seed the random number generator using time srand48((unsigned int) time(NULL)); // Dimension of the operation with defaul value int N = PROBSIZE; // Specify operation: 0 MatMult; 1 MatVecMult int opr = 0; // Whether to verify the result or not int verif = 0; // Whether to display the result or not int disp = 0; // Whether to call the naive implementation int execNaive = 1; // Whether to call the optimized implementation int execOPT = 1; // Parse command line { int arg_index = 1; int print_usage = 0; while (arg_index < argc) { if ( strcmp(argv[arg_index], "-N") == 0 ) { arg_index++; N = atoi(argv[arg_index++]); } else if ( strcmp(argv[arg_index], "-operation") == 0 ) { arg_index++; opr = atoi(argv[arg_index++]); } else if ( strcmp(argv[arg_index], "-help") == 0 ) { print_usage = 1; break; } else if( strcmp(argv[arg_index], "-verif") == 0 ) { arg_index++; verif = 1; if(execNaive==0 || execOPT==0) { printf("***Must call both naive and optimized when running verification\n"); print_usage = 1; break; } } else if( strcmp(argv[arg_index], "-disp") == 0 ) { arg_index++; disp = 1; } else if( strcmp(argv[arg_index], "-naive") == 0 ) { arg_index++; execNaive = 1; execOPT = 0; if(verif==1) { printf("***Must call both naive and optimized when running verification\n"); print_usage = 1; break; } } else if( strcmp(argv[arg_index], "-OPT") == 0 ) { arg_index++; execOPT = 1; execNaive = 0; if(verif==1) { printf("***Must call both naive and optimized when running verification\n"); print_usage = 1; break; } } else { printf("***Invalid argument: %s\n", argv[arg_index]); print_usage = 1; break; } } if (print_usage) { printf("\n"); printf("Usage: %s [<options>]\n", argv[0]); printf("\n"); printf(" -N <N> : problem size (default: %d)\n", PROBSIZE); printf(" -operation <ID> : Operation ID = 0 for MatMult or ID = 1 for MatVecMult\n"); printf(" -verif : Activate verification\n"); printf(" -disp : Display result (use only for small N!)\n"); printf(" -naive : Run only naive implementation\n"); printf(" -OPT : Run only optimized implementation\n"); printf(" -help : Display this message\n"); printf("\n"); } if (print_usage) return 0; } // Perform operation switch(opr) { case 0: /* Matrix-matrix multiply */ { printf("Performing matrix-matrix multiply operation\n"); double *matA, *matB, *matC1, *matC2; // Allocate memory matA = (double *) malloc(N*N * sizeof(double)); matB = (double *) malloc(N*N * sizeof(double)); if(execNaive) matC1 = (double *) malloc(N*N * sizeof(double)); if(execOPT) matC2 = (double *) malloc(N*N * sizeof(double)); // Initialize matrix values randInitialize(N*N,matA); randInitialize(N*N,matB); clock_t tic, toc; double tm; if(execNaive) { // Perform naive matA x matB = matC1 tic = clock(); matMult(N,matA,matB,matC1); toc = clock(); tm = (double)(toc - tic) / CLOCKS_PER_SEC; printf("Elapsed time for naive mat-mat mult.: %f seconds\n",tm); } if(execOPT) { // Perform optimized matA x matB = matC2 tic = clock(); //matMult_opt(N,matA,matB,matC2); toc = clock(); tm = (double)(toc - tic) / CLOCKS_PER_SEC; printf("Elapsed time for optimized mat-mat mult.: %f seconds\n",tm); } // Verify results (compare the two matrices) if(verif) compareVecs(N*N,matC2,matC1); // Display results (don't use for large matrices) if(disp) { displayMat(N,N,matA); printf("\n"); displayMat(N,N,matB); printf("\n"); displayMat(N,N,matC1); printf("\n"); displayMat(N,N,matC2); } // Free memory free(matA); free(matB); if(execNaive) free(matC1); if(execOPT) free(matC2); } break; case 1: /* Matrix-vector multiply */ { printf("Performing matrix-vector multiply operation\n"); double *matA, *vecB, *vecC1,*vecC2; // Allocate memory matA = (double *) malloc(N*N * sizeof(double)); vecB = (double *) malloc(N*N * sizeof(double)); if(execNaive) vecC1 = (double *) malloc(N*N * sizeof(double)); if(execOPT) vecC2 = (double *) malloc(N*N * sizeof(double)); // Initialize values randInitialize(N*N,matA); randInitialize(N,vecB); clock_t tic, toc; double tm; if(execNaive) { // Perform naive matA x vecB = vecC1 tic = clock(); matVecMult(N,matA,vecB,vecC1); toc = clock(); tm = (double)(toc - tic) / CLOCKS_PER_SEC; printf("Elapsed time for naive mat-vec mult.: %f seconds\n",tm); } if(execOPT) { // Perform optimized matA x vecB = vecC2 tic = clock(); matVecMult_opt(N,matA,vecB,vecC2); toc = clock(); tm = (double)(toc - tic) / CLOCKS_PER_SEC; printf("Elapsed time for optimized mat-vec mult.: %f seconds\n",tm); } // Verify results if(verif) compareVecs(N,vecC2,vecC1); // Display results (don't use for large matrices) if(disp) { displayMat(N,N,matA); printf("\n"); displayVec(N,vecB); printf("\n"); displayVec(N,vecC1); printf("\n"); } // Free memory free(matA); free(vecB); if(execNaive) free(vecC1); if(execOPT) free(vecC2); } break; default: printf(" Invalid operation ID\n"); return 0; } return 0; }