inline void insertionSort(std::vector<int>& nums) { if (nums.empty()) return; for (size_t j = 1; j != nums.size(); ++j) { size_t i = j; int v = nums[i]; for (; i && nums[i - 1] > v; --i) { nums[i] = nums[i - 1]; } nums[i] = v; outputVec(nums); } }
int main(int argc, char *argv[]) { int err = 0; int i, j; double *vecA, *matB, *vecC; double s_time,e_time; // Get cmndln args exit if error occurs if((err = getArgs(argc, argv))) errExit("Exiting app"); //Args.m = 3; // Args.n = 3; // Args.verbose = 1; // Allocate memory for the matrix and vectors if(! (vecA = (double*) malloc(Args.m * sizeof(double)))) errExit("Error: Failed to allocate memory for vecA\n"); if(! (matB = (double*) malloc(Args.m * Args.n * sizeof(double)))) errExit("Error: Failed to allocate memory for matB\n"); if(! (vecC = (double*) malloc(Args.n * sizeof(double)))) errExit("Error: Failed to allocate memory for vecC\n"); // Seed the random number generator (This provides a repeatable random series) srand(1); // Init matB as an array with random values between 1 and 10 for(i=0; i < Args.m; i++) { for(j=0; j < Args.n; j++) matB[i * Args.n + j] = RNDRANGE(10.0); } // Init vecC as our vector which multiples matB*2 for(i=0; i < Args.n; i++) vecC[i] = RNDRANGE(10.0); // Perform the matrix-vector multiply s_time=omp_get_wtime(); matvectMultiply(vecA, matB, vecC); e_time=omp_get_wtime(); // If verbose then display the matrices if(Args.verbose) { outputMat("Matrix B:", matB); outputVec("Vector C:", vecC); outputVec("Resultant Vector A:", vecA); } printf("%d %f\n",omp_get_max_threads(),e_time-s_time); // Free memory if(vecA) free(vecA); if(matB) free(matB); if(vecC) free(vecC); //system("pause"); return err; }