/* * Copyright ©2021 Chris Thachuk. All rights reserved. Permission is * hereby granted to students registered for University of Washington * CSE 333 for use solely during Autumn Quarter 2021 for purposes of * the course. No other use, copying, distribution, or modification * is permitted without prior written consent. Copyrights for * third-party components of this work must be honored. Instructors * interested in reusing these course materials should contact the * author. */ #include #include #include #include #include "dnautil.h" using std::cerr; using std::endl; using std::cout; using stopwatch = std::chrono::high_resolution_clock; // Prints usage information about this program and exits with EXIT_FAILURE. void Usage(char *progname); // Calculate and print timing information for determining the minimum // pairwise Hamming distance in the oligo pool using the min_distance // function. void SummarizeMinDistance(const char* label, const dnautil::OligoPool&, int(*min_distance)(const dnautil::OligoPool&)); int main(int argc, char **argv) { if (argc != 2) { Usage(argv[0]); } // The number of oligos the user requested in the pool. int poolsize = atoi(argv[1]); // Generate a random pool of oligos of size `poolsize`. auto pool = dnautil::RandomOligoPool(poolsize); // Calculate the minimum Hamming distance between any pair of oligos in the set. // N.B. This program can cause an Illegal Instruction fault if the CPU executing // the program does not support the relevant instruction (e.g., AVX2 or AVX512 instructions). // Investigate how you can perform a syscall at runtime to determine if the necessary AVX2 // or AVX512 instructions are supported before calling those functions. A general strategy // is to call this once, at runtime, during a setup phase and then use the 'fastest' // implementation supported by the architecture executing the code. // Using scalar code. SummarizeMinDistance("scalar", pool, dnautil::MinPairwiseDistance); // Using AVX2 vector instructions. SummarizeMinDistance("avx2", pool, dnautil::MinPairwiseDistance); // Using AVX512 vector instructions. SummarizeMinDistance("avx512", pool, dnautil::MinPairwiseDistance); return EXIT_SUCCESS; } void Usage(char *progname) { cerr << "usage: " << progname << " num_strands" << endl; exit(EXIT_FAILURE); } void SummarizeMinDistance(const char* label, const dnautil::OligoPool& pool, int(*min_distance)(const dnautil::OligoPool&)) { auto start = stopwatch::now(); int distance = min_distance(pool); auto stop = stopwatch::now(); auto duration = std::chrono::duration_cast(stop - start); cout << "Using " << label << " instructions" << endl; cout << "Minimum distance : " << distance << endl; cout << "Time to calc (ms): " << duration.count() << endl << endl; }