DBResult* DatabaseMySQL::storeQuery(const std::string &query) { if(!m_connected && !sqlConnect(true)) return NULL; int32_t error = 0; #ifdef __SQL_QUERY_DEBUG__ std::clog << "MYSQL DEBUG, storeQuery: " << query.c_str() << std::endl; #endif if(mysql_real_query(&m_handle, query.c_str(), query.length())) { error = mysql_errno(&m_handle); if(error == CR_SERVER_LOST || error == CR_SERVER_GONE_ERROR) m_connected = false; std::clog << "mysql_real_query(): " << query << " - MYSQL ERROR: " << mysql_error(&m_handle) << " (" << error << ")" << std::endl; return NULL; } if(MYSQL_RES* presult = mysql_store_result(&m_handle)) { DBResult* result = (DBResult*)new MySQLResult(presult); return verifyResult(result); } error = mysql_errno(&m_handle); if(error == CR_UNKNOWN_ERROR || error == CR_SERVER_LOST) return NULL; std::clog << "mysql_store_result(): " << query << " - MYSQL ERROR: " << mysql_error(&m_handle) << " (" << error << ")" << std::endl; return NULL; }
DBResult* DatabaseODBC::storeQuery(const std::string &query) { if(!m_connected) return NULL; #ifdef __DEBUG_SQL__ std::cout << "ODBC QUERY: " << query << std::endl; #endif std::string buf = _parse(query); SQLHSTMT stmt; SQLRETURN ret = SQLAllocHandle(SQL_HANDLE_STMT, m_handle, &stmt); if(!RETURN_SUCCESS(ret)){ std::cout << "Failed to allocate ODBC SQLHSTMT statement." << std::endl; return NULL; } ret = SQLExecDirect(stmt, (SQLCHAR*)buf.c_str(), buf.length() ); if(!RETURN_SUCCESS(ret)){ std::cout << "SQLExecDirect(): " << query << ": ODBC ERROR." << std::endl; return NULL; } DBResult* results = new ODBCResult(stmt); return verifyResult(results); }
DBResult_ptr Database::storeQuery(const std::string& query) { // executes the query database_lock.lock(); retry: while (mysql_real_query(m_handle, query.c_str(), query.length()) != 0) { std::cout << "[Error - mysql_real_query] Query: " << query << std::endl << "Message: " << mysql_error(m_handle) << std::endl; auto error = mysql_errno(m_handle); if (error != CR_SERVER_LOST && error != CR_SERVER_GONE_ERROR && error != CR_CONN_HOST_ERROR && error != 1053/*ER_SERVER_SHUTDOWN*/ && error != CR_CONNECTION_ERROR) { break; } std::this_thread::sleep_for(std::chrono::seconds(1)); } // we should call that every time as someone would call executeQuery('SELECT...') // as it is described in MySQL manual: "it doesn't hurt" :P MYSQL_RES* m_res = mysql_store_result(m_handle); // error occured if (!m_res) { std::cout << "[Error - mysql_store_result] Query: " << query << std::endl << "Message: " << mysql_error(m_handle) << std::endl; int error = mysql_errno(m_handle); if (error != CR_SERVER_LOST && error != CR_SERVER_GONE_ERROR && error != CR_CONN_HOST_ERROR && error != 1053/*ER_SERVER_SHUTDOWN*/ && error != CR_CONNECTION_ERROR) { database_lock.unlock(); return nullptr; } goto retry; } database_lock.unlock(); // retriving results of query return verifyResult(DBResult_ptr(new DBResult(m_res))); }
DBResult_ptr DatabaseODBC::internalSelectQuery(const std::string &query) { if(!m_connected) return DBResult_ptr(); #ifdef __DEBUG_SQL__ std::cout << "ODBC QUERY: " << query << std::endl; #endif std::string buf = _parse(query); SQLHSTMT stmt; SQLRETURN ret = SQLAllocHandle(SQL_HANDLE_STMT, m_handle, &stmt); if(!RETURN_SUCCESS(ret)){ std::cout << "Failed to allocate ODBC SQLHSTMT statement." << std::endl; return DBResult_ptr(); } ret = SQLExecDirect(stmt, (SQLCHAR*)buf.c_str(), buf.length() ); if(!RETURN_SUCCESS(ret)){ std::cout << "SQLExecDirect(): " << query << ": ODBC ERROR." << std::endl; return DBResult_ptr(); } DBResult_ptr results(new ODBCResult(stmt), boost::bind(&DatabaseDriver::freeResult, this, _1)); return verifyResult(results); }
main () { int h,i,j,k; int n_var=7; int t_var=5; int nSize[7] = {16, 64, 256, 1024, 4096, 16384, 65536}; int threads[5] = {1, 2, 4, 8, 16}; int repeat = 1000; printf("Lab Work 2 - Performance Test - Merge By Ranking\n"); printf("\t\tseq\t"); for(h=0;h<t_var;h++) printf("t=%i\t", threads[h]); printf("\n"); for(i=0; i<n_var; i++) { //set up inputs int *A, *B, *AB; int n = nSize[i]*2/3; int m = nSize[i]/3; setup(&A, &B, &AB, n, m); //printDataset("Input A: ", A, n); //printDataset("Input B: ", B, m); printf("size=%.5i\t", nSize[i]); timeFunc(mergeSeq, A, B, AB, n, m, 1, repeat); int seqResult[n+m]; for(j=0;j<n+m;j++) seqResult[j] = AB[j]; for(k=0;k<t_var;k++) { //set up threads number. int threads_num = threads[k]; omp_set_dynamic(0); omp_set_num_threads(threads_num); timeFunc(merge, A, B, AB, n, m, threads_num, repeat); } int parResult[n+m]; for(j=0;j<n+m;j++) parResult[j] = AB[j]; verifyResult(seqResult, parResult, n); printf("\n"); //printDataset("Output AB: ", AB, n+m); //printf("\n"); } }
int should_crack_roaming_policy(char *file) { char imeibuf[92] = {0}; char readbuf[92] = {0}; char* const delim = "#"; char *token, *cur = readbuf; int sequence = 0 , ret = 0, readSize = 0, i = 0; int len = property_get("persist.sys.oppo.device.imei", imeibuf, ""); if(len != 15 || strlen(imeibuf)!=15) return -1; printf("should_crack_roaming_policy Enter\n"); FILE *fp = fopen(file, "rb"); if (!fp) { printf("should_crack_roaming_policy=fp=NULL\n"); return -1; } readSize = fread(readbuf, sizeof(char), 32, fp); for(i = 0; i < readSize; i++) { readbuf[i] ^= 14; readbuf[i] = ~readbuf[i]; } readbuf[i]='\0'; fclose(fp); remove(file); while (token = strsep(&cur, delim)) { if(verifyResult(token,sequence,sequence==2?imeibuf:NULL) == 0) { ret++; } sequence++; } printf("=====ret===%d\n",ret); if(ret >= 3) { return 0; } else { return -1; } }
DBResult_ptr DatabaseMySQL::internalSelectQuery(const std::string &query) { if(!m_connected) return DBResult_ptr(); #ifdef __DEBUG_SQL__ std::cout << "MYSQL QUERY: " << query << std::endl; #endif // executes the query if(mysql_real_query(&m_handle, query.c_str(), query.length()) != 0){ std::cout << "mysql_real_query(): " << query << ": MYSQL ERROR: " << mysql_error(&m_handle) << std::endl; int error = mysql_errno(&m_handle); if(error == CR_SERVER_LOST || error == CR_SERVER_GONE_ERROR){ m_connected = false; } } // we should call that every time as someone would call executeQuery('SELECT...') // as it is described in MySQL manual: "it doesn't hurt" :P MYSQL_RES* m_res = mysql_store_result(&m_handle); // error occured if(!m_res){ std::cout << "mysql_store_result(): " << query.substr(0, 256) << ": MYSQL ERROR: " << mysql_error(&m_handle) << std::endl; int error = mysql_errno(&m_handle); if(error == CR_SERVER_LOST || error == CR_SERVER_GONE_ERROR){ m_connected = false; } return DBResult_ptr(); } // retriving results of query DBResult_ptr res(new MySQLResult(m_res), boost::bind(&DatabaseDriver::freeResult, this, _1)); return verifyResult(res); }
DBResult_ptr DatabaseSQLite::internalSelectQuery(const std::string &query) { boost::recursive_mutex::scoped_lock lockClass(sqliteLock); if(!m_connected) return DBResult_ptr(); #ifdef __DEBUG_SQL__ std::cout << "SQLITE QUERY: " << query << std::endl; #endif std::string buf = _parse(query); sqlite3_stmt* stmt; // prepares statement if( OTS_SQLITE3_PREPARE(m_handle, buf.c_str(), buf.length(), &stmt, NULL) != SQLITE_OK){ sqlite3_finalize(stmt); std::cout << "OTS_SQLITE3_PREPARE(): SQLITE ERROR: " << sqlite3_errmsg(m_handle) << " (" << buf << ")" << std::endl; return DBResult_ptr(); } DBResult_ptr results(new SQLiteResult(stmt), boost::bind(&DatabaseDriver::freeResult, this, _1)); return verifyResult(results); }
DBResult* DatabasePgSQL::storeQuery(const std::string& query) { if(!m_connected) return NULL; #ifdef __SQL_QUERY_DEBUG__ std::cout << "PGSQL QUERY: " << query << std::endl; #endif // executes query PGresult* res = PQexec(m_handle, _parse(query).c_str()); ExecStatusType stat = PQresultStatus(res); if(stat != PGRES_COMMAND_OK && stat != PGRES_TUPLES_OK) { std::cout << "PQexec(): " << query << ": " << PQresultErrorMessage(res) << std::endl; PQclear(res); return false; } // everything went fine DBResult* results = new PgSQLResult(res); return verifyResult(results); }
DBResult* DatabaseSQLite::storeQuery(const std::string &query) { OTSYS_THREAD_LOCK_CLASS lockClass(sqliteLock); if(!m_connected) return NULL; #ifdef __SQL_QUERY_DEBUG__ std::cout << "SQLITE QUERY: " << query << std::endl; #endif std::string buf = _parse(query); sqlite3_stmt* stmt; // prepares statement if(OTSYS_SQLITE3_PREPARE(m_handle, buf.c_str(), buf.length(), &stmt, NULL) != SQLITE_OK) { sqlite3_finalize(stmt); std::cout << "OTSYS_SQLITE3_PREPARE(): SQLITE ERROR: " << sqlite3_errmsg(m_handle) << " (" << buf << ")" << std::endl; return NULL; } DBResult* result = new SQLiteResult(stmt); return verifyResult(result); }
DBResult* Database::storeQuery(const std::string& query) { if (!m_connected) { return nullptr; } // executes the query database_lock.lock(); if (mysql_real_query(m_handle, query.c_str(), query.length()) != 0) { std::cout << "[Error - mysql_real_query] Query: " << query << std::endl << "Message: " << mysql_error(m_handle) << std::endl; int error = mysql_errno(m_handle); if (error == CR_SERVER_LOST || error == CR_SERVER_GONE_ERROR) { m_connected = false; } } // we should call that every time as someone would call executeQuery('SELECT...') // as it is described in MySQL manual: "it doesn't hurt" :P MYSQL_RES* m_res = mysql_store_result(m_handle); // error occured if (!m_res) { std::cout << "[Error - mysql_store_result] Query: " << query << std::endl << "Message: " << mysql_error(m_handle) << std::endl; int error = mysql_errno(m_handle); database_lock.unlock(); if (error == CR_SERVER_LOST || error == CR_SERVER_GONE_ERROR) { m_connected = false; } return nullptr; } database_lock.unlock(); // retriving results of query return verifyResult(new DBResult(m_res)); }
double test_1(){ double start_time = omp_get_wtime(); int read=0, write = 1; // s is the number of non-pointy bit 2D slices of diamond tiling // that is available for the current tile size. int s = (tau/3) - 2; // subset_s is an input parameter indicating how many of those // slices we want to use in the repeated tiling pattern. // subset_s should be less than s and greater than or equal to 2. if (subset_s > s || subset_s<2) { fprintf(stderr, "Error: need 2<=subset_s<=s\n"); exit(-1); } // Set lower and upper bounds for spatial dimensions. // When did code gen have a non-inclusive upper bound. // Ian's upper bound is inclusive. int Li=1, Lj=1, Ui=upperBound+1, Uj=upperBound+1; // Loop over the tiling pattern. for (int toffset=0; toffset<T; toffset+=subset_s){ // Loop over phases of tiles within repeated tile pattern. // This is like iterating over the A and B trapezoid tile types. for (int c0 = -2; c0 <= 0; c0 += 1){ // Two loops over tiles within one phase. // All of the tiles within one phase can be done in parallel. // updates by Dave W, to the c1 and c2 loops, for OpenMP (from here to the end of the #if BOUNDING_BOX_FOR_PARALLEL_LOOPS // hoist out min_c1 and max_c1, then use that to hoist a bounding box for c2 // initial version is just aiming for correct and parallel, without worrying about a loose boundingbox int c1_lb = max( max( floord(Lj + (tau/3) * c0 + (tau/3), tau), c0 + floord(-2 * T + Lj - 1, tau) + 1), floord(Lj + 1, tau) ); // end init block c1 int c1_ub = min( min( floord(Uj + (tau/3) * c0 - ((tau/3)+2), tau) + 1, floord(T + Uj - 1, tau)), c0 + floord(Uj - 5, tau) + 2 ); // end cond block c1 // The two expressions below are the same as in the previous version, except that // in the c2_lb_min_expr, I have replaced c1 with: // c1_min_value where it appears with a positive coefficient, and // c1_max_value where it appears with a negative coefficient. // and in the c2_ub_max_expr, the opposite (i.e., c1 becomes c1_max_value where positive) // I will be embarrassed if I have done this wrong. /// Note that I assume tau > 0 #define c2_lb_min_expr(c1_min_value, c1_max_value) \ max( \ max( \ max( \ max( \ max( \ max( \ c0 - 2 * c1_max_value + floord(-Ui + Lj + 1,tau), \ -c1_max_value + floord(-2 * Ui - Uj + tau * c0 + tau * c1_min_value - tau-3, tau*2)+1), \ c1_min_value + floord(-Ui - 2 * Uj + 3, tau)), \ floord(-Ui - Uj + 3, tau)), \ c0 - c1_max_value + floord(-Ui - (tau/3) * c0 + ((tau/3)+1), tau)), \ c0 - c1_max_value + floord(-T - Ui, tau) + 1), \ -c1_max_value + floord(-Ui + 4, tau) - 1 \ ) /* end init block c2 */ #define c2_ub_max_expr(c1_min_value, c1_max_value) \ min( \ min( \ min( \ min( \ min( \ min( \ c0 - 2 * c1_min_value + floord(-Li + Uj - 2, tau) + 1, \ c0 - c1_min_value + floord(-Li - 2, tau) + 1), \ c0 - c1_min_value + floord(-Li - (tau/3) * c0 - ((tau/3)+1), tau) + 1), \ floord(T - Li - Lj, tau)), \ -c1_min_value + floord(2 * T - Li, tau)), \ c1_max_value + floord(-Li - 2 * Lj - 1, tau) + 1), \ -c1_min_value + floord(-2 * Li - Lj + tau * c0 + tau * c1_max_value + (tau-1), tau*2) \ ) /* end cond block c2 */ #define c2_lb_expr(c1_value) c2_lb_min_expr(c1_value, c1_value) #define c2_ub_expr(c1_value) c2_ub_max_expr(c1_value, c1_value) #if BOUNDING_BOX_FOR_PARALLEL_LOOPS int c2_box_lb = c2_lb_min_expr(c1_lb, c1_ub); int c2_box_ub = c2_ub_max_expr(c1_lb, c1_ub); #if PARALLEL // don't need to mention c1...c5 below, since they're scoped inside the for loops #pragma omp parallel for shared(start_time, s, Li, Lj, Ui, Uj, toffset, c0, c1_lb, c1_ub, c2_box_lb, c2_box_ub, ) private(read, write) collapse(2) #endif for (int c1 = c1_lb; c1 <= c1_ub; c1 += 1) { for (int c2 = c2_box_lb; c2 <= c2_box_ub; c2 += 1) if (c2 >= c2_lb_expr(c1) && c2 <= c2_ub_expr(c1)) { #else for (int c1 = c1_lb; c1 <= c1_ub; c1 += 1) { for (int c2 = c2_lb_expr(c1); c2 <= c2_ub_expr(c1); c2 += 1) { #endif //fprintf(stdout, "(%d,%d,%d)\n", c0,c1,c2); // Loop over subset_s time steps within tiling pattern // and within tile c0,c1,c2. // Every time the pattern is repeated, toffset will be // subset_s bigger. // The real t value is c3+toffset. We are just using the // tiling pattern from t=1 to t<=subset_s. for (int c3 = 1; c3 <= min(T-toffset,subset_s); c3 += 1){ int t = c3+toffset; // if t % 2 is 1, then read=0 and write=1 write = t & 1; read = 1-write; // x spatial dimension. for (int c4 = max( max( max( -tau * c1 - tau * c2 + 2 * c3 - (2*tau-2), -Uj - tau * c2 + c3 - (tau-2)), tau * c0 - tau * c1 - tau * c2 - c3), Li ); // end init block c4 c4 <= min( min( min( tau * c0 - tau * c1 - tau * c2 - c3 + (tau-1), -tau * c1 - tau * c2 + 2 * c3), -Lj - tau * c2 + c3), Ui - 1 ); // end cond block c4 c4 += 1){ // y spatial dimension. for (int c5 = max( max( tau * c1 - c3, Lj), -tau * c2 + c3 - c4 - (tau-1) ); // end init block c5 c5 <= min( min( Uj - 1, -tau * c2 + c3 - c4), tau * c1 - c3 + (tau-1) ); // end cond block c5 c5 += 1){ //fprintf(stdout, "(%d,%d,%d,%d,%d,%d)\n", c0,c1,c2,c3,c4,c5); stencil( read, write, c4, c5); } // for c5 } // for c4 } // for c3 } // for c2 } // for c1 } // for c0 } // for toffset double end_time = omp_get_wtime(); return (end_time - start_time); } int main( int argc, char* argv[] ){ setbuf(stdout, NULL); // set buffer to null, so prints ALWAYS print (for debug purposes mainly) bool verify = false; bool printtime = true; // Command line parsing char c; while ((c = getopt (argc, argv, "nc:s:p:T:t:hv")) != -1){ switch( c ) { case 'n': printtime=false; break; case 'c': // problem size cores = parseInt( optarg ); if( cores <= 0 ){ fprintf(stderr, "cores must be greater than 0: %d\n", cores); exit(BAD_RUN_TIME_PARAMETERS); } break; case 's': // subset //globalSeed = parseInt( optarg ); subset_s = parseInt( optarg ); break; case 'p': // problem size problemSize = parseInt( optarg ); if( problemSize <= 0 ){ fprintf(stderr, "problemSize must be greater than 0: %d\n", problemSize); exit(BAD_RUN_TIME_PARAMETERS); } break; case 'T': // T (time steps) T = parseInt( optarg ); if( T <= 0 ){ fprintf(stderr, "T must be greater than 0: %d\n", T); exit(BAD_RUN_TIME_PARAMETERS); } break; case 't': // tau #if defined tau fprintf(stderr, "don't use -t to set tau when you compiled with -Dtau=%d.\n", tau); if (parseInt(optarg) != tau) exit(BAD_COMPILE_TIME_PARAMETERS); #else tau = parseInt( optarg ); #endif break; case 'h': // help printf("usage: %s\n-n \t dont print time \n-p <problem size> \t problem size in elements \n-T <time steps>\t number of time steps\n-c <cores>\tnumber of threads\n-s <subset_s>\t tile parameter\n-t <tau>\t tile parameter\n-h\tthis dialogue\n-v\tverify output\n", argv[0]); exit(0); case 'v': // verify; verify = true; break; case '?': if (optopt == 'p') fprintf (stderr, "Option -%c requires positive int argument: problem size.\n", optopt); else if (optopt == 'T') fprintf (stderr, "Option -%c requires positive int argument: T.\n", optopt); else if (optopt == 's') fprintf (stderr, "Option -%c requires int argument: subset_s.\n", optopt); else if (optopt == 'c') fprintf (stderr, "Option -%c requires int argument: number of cores.\n", optopt); else if (isprint (optopt)) fprintf (stderr, "Unknown option `-%c'.\n", optopt); else fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); exit(0); default: exit(0); } } if( !( tau % 3 == 0 && tau >= 15 ) ){ #if defined tau fprintf(stderr, "tau must be a multiple of 3, and >= 15, but the program was compiled with -Dtau=%d, and thus can't run :-(\n", tau); exit(BAD_COMPILE_TIME_PARAMETERS); #else fprintf(stderr, "tau must be a multiple of 3, and >= 15, but it's %d; re-run with a different -t value\n", tau); exit(BAD_RUN_TIME_PARAMETERS); #endif } init(); initSpace(); double time = test_1(); if( printtime ) { printf( "Time: %f\n", time ); } if( verify ){ verifyResult( true ); } }
int main(int argc, char** argv) { const unsigned int width = 1200; const unsigned int height = 800; const int maxIterations = 256; int numThreads = 2; float x0 = -2; float x1 = 1; float y0 = -1; float y1 = 1; // parse commandline options //////////////////////////////////////////// int opt; static struct option long_options[] = { {"threads", 1, 0, 't'}, {"view", 1, 0, 'v'}, {"help", 0, 0, '?'}, {0 ,0, 0, 0} }; while ((opt = getopt_long(argc, argv, "t:v:?", long_options, NULL)) != EOF) { switch (opt) { case 't': { numThreads = atoi(optarg); break; } case 'v': { int viewIndex = atoi(optarg); // change view settings if (viewIndex == 2) { float scaleValue = .015f; float shiftX = -.986f; float shiftY = .30f; scaleAndShift(x0, x1, y0, y1, scaleValue, shiftX, shiftY); } else if (viewIndex > 1) { fprintf(stderr, "Invalid view index\n"); return 1; } break; } case '?': default: usage(argv[0]); return 1; } } // end parsing of commandline options int* output_serial = new int[width*height]; int* output_thread = new int[width*height]; // // Run the serial implementation. Run the code three times and // take the minimum to get a good estimate. // memset(output_serial, 0, width * height * sizeof(int)); double minSerial = 1e30; for (int i = 0; i < 3; ++i) { double startTime = CycleTimer::currentSeconds(); mandelbrotSerial(x0, y0, x1, y1, width, height, 0, height, maxIterations, output_serial); double endTime = CycleTimer::currentSeconds(); minSerial = std::min(minSerial, endTime - startTime); } printf("[mandelbrot serial]:\t\t[%.3f] ms\n", minSerial * 1000); writePPMImage(output_serial, width, height, "mandelbrot-serial.ppm", maxIterations); // // Run the threaded version // memset(output_thread, 0, width * height * sizeof(int)); double minThread = 1e30; for (int i = 0; i < 3; ++i) { double startTime = CycleTimer::currentSeconds(); mandelbrotThread(numThreads, x0, y0, x1, y1, width, height, maxIterations, output_thread); double endTime = CycleTimer::currentSeconds(); minThread = std::min(minThread, endTime - startTime); } printf("[mandelbrot thread]:\t\t[%.3f] ms\n", minThread * 1000); writePPMImage(output_thread, width, height, "mandelbrot-thread.ppm", maxIterations); if (! verifyResult (output_serial, output_thread, width, height)) { printf ("Error : Output from threads does not match serial output\n"); delete[] output_serial; delete[] output_thread; return 1; } // compute speedup printf("\t\t\t\t(%.2fx speedup from %d threads)\n", minSerial/minThread, numThreads); delete[] output_serial; delete[] output_thread; return 0; }
int main(int argc, char** argv){ srand(time(NULL)); if(argc != 2) { printf("Usage: search [elements]\nExample: scan 10000\n"); return -1; } unsigned long long start_time = time_ms(); int event_amount=2; int elems = atoi(argv[1]); cl_int err; cl_event* events=allocateMemoryForEvent(event_amount); cl_ulong total_downsweep=0,total_hillissteele=0; size_t localWorkGroupSize_downSweep[1]={LOCALSIZE}; //must be power of two size_t globalWorkGroupSize_downSweep[1]={getPowerOfTwo(roundUp(LOCALSIZE,roundUp(LOCALSIZE, elems)/2))}; //calculating size_t localWorkGroupSize_hillissteele[1]={LOCALSIZE}; //must be power of two size_t globalWorkGroupSize_hillissteele[1]={roundUp(LOCALSIZE,elems)}; //calculating worksize int howManyWorkGroups=globalWorkGroupSize_downSweep[0]/LOCALSIZE; //quotient is power of two, since dividend and divisor are power of two int sumBuffer_length_downSweep=howManyWorkGroups; int sumBuffer_length_hillis=getPowerOfTwo(roundUp(LOCALSIZE,elems)/LOCALSIZE); VALUE *data = (VALUE*)malloc(elems*sizeof(VALUE)); VALUE *result_seq=(VALUE*)malloc(elems*sizeof(VALUE)); VALUE *result=(VALUE*)malloc(elems*sizeof(VALUE)); VALUE *result_hillissteele=(VALUE*)malloc(elems*sizeof(VALUE)); VALUE *sum=(VALUE*)malloc(sumBuffer_length_downSweep*sizeof(VALUE)); VALUE *sum_hillis=(VALUE*)malloc(sumBuffer_length_hillis*sizeof(VALUE)); memset(sum_hillis,0,sumBuffer_length_hillis*sizeof(VALUE)); memset(result_seq,0,elems*sizeof(VALUE)); // initialize data set (fill randomly) for(int j=0; j<elems; ++j) { data[j] =rand()%121; } // printResult(data, elems, 4, "INPUT"); /*Sequential Scan*/ for(int i=1; i<elems; i++){ result_seq[i]=result_seq[i-1]+data[i-1]; } // printResult(result_seq, elems, 4, "Sequential Algorithm OUTPUT"); //ocl initialization size_t deviceInfo; cl_context context; cl_command_queue command_queue; cl_device_id device_id = cluInitDevice(CL_DEVICE, &context, &command_queue); clGetDeviceInfo(device_id, CL_DEVICE_MAX_WORK_GROUP_SIZE,sizeof(size_t), &deviceInfo,NULL ); // create memory buffer cl_mem mem_data=clCreateBuffer(context, CL_MEM_READ_ONLY| CL_MEM_USE_HOST_PTR,elems*sizeof(VALUE), data, &err); cl_mem mem_data_hillis=clCreateBuffer(context, CL_MEM_READ_ONLY| CL_MEM_USE_HOST_PTR,elems*sizeof(VALUE), data, &err); cl_mem mem_result=clCreateBuffer(context, CL_MEM_READ_WRITE, elems*sizeof(VALUE), NULL,&err); cl_mem mem_result_tmp=clCreateBuffer(context, CL_MEM_READ_WRITE, elems*sizeof(VALUE), NULL,&err); cl_mem mem_sum=clCreateBuffer(context, CL_MEM_READ_WRITE, sumBuffer_length_downSweep*sizeof(VALUE), NULL, &err); cl_mem mem_sum_hillis=clCreateBuffer(context, CL_MEM_READ_WRITE, sumBuffer_length_hillis*sizeof(VALUE), NULL, &err); CLU_ERRCHECK(err, "Failed to create Buffer"); err=clEnqueueWriteBuffer(command_queue, mem_sum_hillis, CL_TRUE, 0, sumBuffer_length_hillis*sizeof(VALUE), sum_hillis, 0, NULL, NULL); CLU_ERRCHECK(err, "Failed to write values into mem_sum"); // create kernel from source char tmp[1024]; sprintf(tmp,"-DVALUE=%s", EXPAND_AND_QUOTE(VALUE)); cl_program program = cluBuildProgramFromFile(context, device_id, KERNEL_FILE_NAME, tmp); cl_kernel kernel_downSweep = clCreateKernel(program, "prefix_scan_downSweep", &err); cl_kernel kernel_hillissteele=clCreateKernel(program, "prefix_scan_hillissteele", &err); cl_kernel kernel_last_stage= clCreateKernel(program, "prefix_scan_last_stage", &err); CLU_ERRCHECK(err,"Could not load source program"); /*-------------------------------------DOWNSWEEP-----------------------------------------------*/ // set arguments int border=elems/2; int flag=1; cluSetKernelArguments(kernel_downSweep, 6, sizeof(cl_mem), (void *)&mem_data, sizeof(cl_mem), (void*)&mem_result, sizeof(cl_mem), (void*)&mem_sum,sizeof(VALUE)*LOCALSIZE*2, NULL, sizeof(int), (void*)&border, sizeof(int), (void*)&flag); //execute kernel CLU_ERRCHECK(clEnqueueNDRangeKernel(command_queue, kernel_downSweep, 1, NULL, globalWorkGroupSize_downSweep, localWorkGroupSize_downSweep, 0, NULL, &(events[1])), "DownSweep_Failed to enqueue 2D kernel"); clFinish(command_queue); total_downsweep+=getProfileTotalTime(events,1); //read values back from device CLU_ERRCHECK(clEnqueueReadBuffer(command_queue, mem_result, CL_TRUE, 0, elems*sizeof(VALUE), result, 0, NULL, NULL),"DownSweep_Failed to read Result Values"); /* CLU_ERRCHECK(clEnqueueReadBuffer(command_queue, mem_sum, CL_TRUE, 0, sumBuffer_length_downSweep*sizeof(VALUE), sum, 0, NULL, NULL),"Failed to read Sum Values"); clFinish(command_queue); printSumBuffer(sum, sumBuffer_length_downSweep,"DOWNSWEEP SUM"); */ err=clEnqueueCopyBuffer(command_queue, mem_result, mem_result_tmp, 0, 0, elems*sizeof(VALUE),0,NULL,NULL); CLU_ERRCHECK(err,"DownSweep_Failed during copying buffer"); /*+++++++++++++++++++++++++++++++++DOWNSWEEP-ON-SUM-BUFFER+++++++++++++++++++++++++++++++++++++++*/ flag=0; border=sumBuffer_length_downSweep/2; //since sumbuffer_length is power of two no further adaption is needed cluSetKernelArguments(kernel_downSweep, 6, sizeof(cl_mem), (void *)&mem_sum, sizeof(cl_mem), (void*)&mem_sum, sizeof(cl_mem), (void*)&mem_sum,sizeof(VALUE)*sumBuffer_length_downSweep, NULL, sizeof(int), (void*)&border, sizeof(int), (void*)&flag); howManyWorkGroups>1 ? globalWorkGroupSize_downSweep[0]=howManyWorkGroups/2:howManyWorkGroups; //if 1 workgroup make adaption howManyWorkGroups>1 ? localWorkGroupSize_downSweep[0]=howManyWorkGroups/2:howManyWorkGroups; //if 1 workgroup make adaption //execute kernel CLU_ERRCHECK(clEnqueueNDRangeKernel(command_queue, kernel_downSweep, 1, NULL, globalWorkGroupSize_downSweep, localWorkGroupSize_downSweep, 0, NULL,&(events[1])), "DownSweep_Failed to enqueue 2D kernel"); clFinish(command_queue); total_downsweep+=getProfileTotalTime(events,1); /* CLU_ERRCHECK(clEnqueueReadBuffer(command_queue, mem_sum, CL_TRUE, 0, sumBuffer_length_downSweep*sizeof(VALUE), sum, 0, NULL, NULL),"Failed to read Sum Values"); printSumBuffer(sum, sumBuffer_length_downSweep,"DOWNSWEEP SUM PREFIX"); */ /*+++++++++++++++++++++++++++++++++DOWNSWEEP-LAST-STAGE(Add Sums)++++++++++++++++++++++++++++++++++++++++*/ border=sumBuffer_length_downSweep; flag=1; cluSetKernelArguments(kernel_last_stage, 4, sizeof(cl_mem), (void *)&mem_result_tmp, sizeof(cl_mem), (void*)&mem_sum, sizeof(int), (void*)&border, sizeof(int), (void*)&flag); globalWorkGroupSize_downSweep[0]=getPowerOfTwo(roundUp(LOCALSIZE,roundUp(LOCALSIZE, elems)/2)); localWorkGroupSize_downSweep[0]=LOCALSIZE; //printf("GLOBALSIZE: %d\tLOCALSIZE %d\n",globalWorkGroupSize[0],localWorkGroupSize[0]); //execute kernel CLU_ERRCHECK(clEnqueueNDRangeKernel(command_queue, kernel_last_stage, 1, NULL, globalWorkGroupSize_downSweep, localWorkGroupSize_downSweep, 0, NULL, &(events[1])), "DownSweep_Failed to enqueue 2D kernel"); clFinish(command_queue); total_downsweep+=getProfileTotalTime(events,1); //read values back from device CLU_ERRCHECK(clEnqueueReadBuffer(command_queue, mem_result_tmp, CL_TRUE, 0, elems*sizeof(VALUE), result, 0, NULL, NULL),"DownSweep_Failed to read Result Values"); /*---------------------------------------HILLISSTEELE----------------------------------------------------------*/ flag=1; border=elems; cluSetKernelArguments(kernel_hillissteele, 6, sizeof(cl_mem), (void *)&mem_data_hillis, sizeof(cl_mem), (void*)&mem_result, sizeof(cl_mem), (void*)&mem_sum_hillis,sizeof(VALUE)*LOCALSIZE*2, NULL, sizeof(int), (void*)&border, sizeof(int), (void*)&flag); //execute kernel //printf("GlobalSize: %d\tLocalWorkGroupSize: %d\n",globalWorkGroupSize[0], localWorkGroupSize[0]); //printf("Amount of WorkGroups: %d\n", globalWorkGroupSize[0]/localWorkGroupSize[0]); CLU_ERRCHECK(clEnqueueNDRangeKernel(command_queue, kernel_hillissteele, 1, NULL, globalWorkGroupSize_hillissteele, localWorkGroupSize_hillissteele, 0, NULL, &(events[0])), "Hillissteele_Failed to enqueue 2D kernel_Inputbuffer"); clFinish(command_queue); total_hillissteele+=getProfileTotalTime(events,0); //read values back from device /* CLU_ERRCHECK(clEnqueueReadBuffer(command_queue, mem_result, CL_TRUE, 0, elems*sizeof(VALUE), result_hillissteele, 0, NULL, NULL),"Failed to read Result Values"); CLU_ERRCHECK(clEnqueueReadBuffer(command_queue, mem_sum_hillis, CL_TRUE, 0, sumBuffer_length_hillis*sizeof(VALUE), sum_hillis, 0, NULL, NULL),"Failed to read Sum_1 Values"); printSumBuffer(sum_hillis, sumBuffer_length_hillis, "HILLISSTEELE SUM"); printResult(result_hillissteele,elems, 4, "HILLISSTEELE Temporary OUTPUT"); */ /*++++++++++++++++++++++++++++++++++++++HILLISSTEELE-ON-SUM-BUFFER+++++++++++++++++++++++++++++++++++++*/ flag=0; border=sumBuffer_length_hillis; cluSetKernelArguments(kernel_hillissteele, 6, sizeof(cl_mem), (void *)&mem_sum_hillis, sizeof(cl_mem), (void*)&mem_sum_hillis, sizeof(cl_mem), (void*)&mem_sum_hillis,sizeof(VALUE)*howManyWorkGroups*2, NULL, sizeof(int), (void*)&border, sizeof(int), (void*)&flag); //execute kernel globalWorkGroupSize_hillissteele[0]=sumBuffer_length_hillis; localWorkGroupSize_hillissteele[0]=sumBuffer_length_hillis; CLU_ERRCHECK(clEnqueueNDRangeKernel(command_queue, kernel_hillissteele, 1, NULL, globalWorkGroupSize_hillissteele, localWorkGroupSize_hillissteele, 0, NULL, &(events[0])), "Hillissteele_Failed to enqueue 2D kernel_Sumbuffer"); clFinish(command_queue); total_hillissteele+=getProfileTotalTime(events,0); //read values back from device /* CLU_ERRCHECK(clEnqueueReadBuffer(command_queue, mem_sum_hillis, CL_TRUE, 0, sumBuffer_length_hillis*sizeof(VALUE), sum_hillis, 0, NULL, NULL),"Failed to read Sum2 Values"); printSumBuffer(sum_hillis, sumBuffer_length_hillis, "HILLISSTEELE SUM PREFIX"); */ /*+++++++++++++++++++++++++++++++++++++HILLISSTEELE-LAST-STAGE(Add Sums)++++++++++++++++++++++++++++++++++++++++*/ flag=0; border=sumBuffer_length_hillis; cluSetKernelArguments(kernel_last_stage, 4, sizeof(cl_mem), (void *)&mem_result, sizeof(cl_mem), (void*)&mem_sum_hillis, sizeof(int), (void*)&border, sizeof(int), (void*)&flag); globalWorkGroupSize_hillissteele[0]=roundUp(LOCALSIZE,elems); localWorkGroupSize_hillissteele[0]=LOCALSIZE; //printf("GLOBALSIZE: %d\tLOCALSIZE %d\n",globalWorkGroupSize[0],localWorkGroupSize[0]); //execute kernel CLU_ERRCHECK(clEnqueueNDRangeKernel(command_queue, kernel_last_stage, 1, NULL, globalWorkGroupSize_hillissteele, localWorkGroupSize_hillissteele, 0, NULL, &(events[0])), "Hillissteele_Failed to enqueue kernel_Last_stage"); clFinish(command_queue); total_hillissteele+=getProfileTotalTime(events,0); //read values back from device CLU_ERRCHECK(clEnqueueReadBuffer(command_queue, mem_result, CL_TRUE, 0, elems*sizeof(VALUE), result_hillissteele, 0, NULL, NULL),"Hillissteele_Failed to read Result Values"); /*-------------------------FINISHED---------------------------------------------*/ //printResult(result_hillissteele, elems, 4, "HILLISSTEELE OUTPUT"); //printResult(result, elems, 4, "IMPROVED IMPLEMENTATION OUTPUT"); //verify results verifyResult(result_seq,result,elems, "Verifying result of DownSweep for bigger array size"); verifyResult(result_seq,result_hillissteele,elems, "Verifying result of HILLISSTEELE for bigger array size"); printProfileInfo(total_downsweep,"Improved Algorithm Time:"); printProfileInfo(total_hillissteele,"Hillis & Steele Time:"); printf("\nDEVICE INFO MAX_WORK_GROUP_SIZE: %d\n", (int) deviceInfo); printf("OCL Device: %s\n", cluGetDeviceDescription(device_id, CL_DEVICE)); printf("Done, took %16llu ms\n", time_ms()-start_time); // finalization for(int i=0; i<event_amount; i++){ clReleaseEvent(events[i]); } err = clFinish(command_queue); err |= clReleaseKernel(kernel_downSweep); err |= clReleaseKernel(kernel_last_stage); err |= clReleaseKernel(kernel_hillissteele); err |= clReleaseProgram(program); err |= clReleaseMemObject(mem_data); err |= clReleaseMemObject(mem_data_hillis); err |= clReleaseMemObject(mem_result); err |= clReleaseMemObject(mem_result_tmp); err |= clReleaseMemObject(mem_sum); err |= clReleaseMemObject(mem_sum_hillis); err |= clReleaseCommandQueue(command_queue); err |= clReleaseContext(context); CLU_ERRCHECK(err, "Failed during ocl cleanup"); free(events); free(result); free(result_hillissteele); free(result_seq); free(sum); free(sum_hillis); return EXIT_SUCCESS; }
int main( int argc, char* argv[] ){ setbuf(stdout, NULL); // set buffer to null, so prints ALWAYS print (for debug purposes mainly) bool verify = false; bool printtime = true; // Command line parsing char c; while ((c = getopt (argc, argv, "nc:s:p:T:t:w:hv")) != -1){ switch( c ) { case 'n': // print time printtime = false; break; case 'c': // cores cores = parseInt( optarg ); if( cores <= 0 ){ fprintf(stderr, "cores must be greater than 0: %d\n", cores); exit( 0 ); } break; case 'p': // problem size problemSize = parseInt( optarg ); if( problemSize <= 0 ){ fprintf(stderr, "problemSize must be greater than 0: %d\n", problemSize); exit( 0 ); } break; case 'T': // T (time steps) T = parseInt( optarg ); if( T <= 0 ){ fprintf(stderr, "T must be greater than 0: %d\n", T); exit( 0 ); } break; case 't': // timeBand timeBand = parseInt( optarg ); if( timeBand <= 0 ){ fprintf(stderr, "t must be greater than 0: %d\n", T); exit( 0 ); } break; case 'w': // width width_max = parseInt( optarg ); if( width_max <= 0 ){ fprintf(stderr, "w must be greater than 0: %d\n", T); exit( 0 ); } break; case 'h': // help printf("usage: %s\n-n \t dont print time \n-p <problem size> \t problem size in elements \n-T <time steps>\t number of time steps\n-c <cores>\tnumber of threads\n-w <tile width>\t the width of the tile\n-t <tile height>\t the number of timesteps in a tile\n-h\tthis dialogue\n-v\tverify output\n", argv[0]); exit(0); case 'v': // verify; verify = true; break; case '?': if (optopt == 'p') fprintf (stderr, "Option -%c requires positive int argument: problem size.\n", optopt); else if (optopt == 'T') fprintf (stderr, "Option -%c requires positive int argument: T.\n", optopt); else if (optopt == 's') fprintf (stderr, "Option -%c requires int argument: subset_s.\n", optopt); else if (optopt == 'c') fprintf (stderr, "Option -%c requires int argument: number of cores.\n", optopt); else if (isprint (optopt)) fprintf (stderr, "Unknown option `-%c'.\n", optopt); else fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); exit(0); default: exit(0); } } initJacobi(); initTrapezoid(); initSpace(); double time = test_1(); if( printtime ){ printf( "Time: %f\n", time ); } if( verify ){ verifyResult( true ); } }
static void TestSelector() { TestText text; USet* excluded_sets[3] = { NULL }; int32_t i, testCaseIdx; if (!getAvailableNames()) { return; } if (!text_open(&text)) { releaseAvailableNames();; } excluded_sets[0] = uset_openEmpty(); for(i = 1 ; i < 3 ; i++) { excluded_sets[i] = uset_open(i*30, i*30+500); } for(testCaseIdx = 0; testCaseIdx < UPRV_LENGTHOF(getEncodingsFns); testCaseIdx++) { int32_t excluded_set_id; int32_t num_encodings; const char **encodings = getEncodingsFns[testCaseIdx](&num_encodings); if (getTestOption(QUICK_OPTION) && num_encodings > 25) { uprv_free((void *)encodings); continue; } /* * for(excluded_set_id = 0 ; excluded_set_id < 3 ; excluded_set_id++) * * This loop was replaced by the following statement because * the loop made the test run longer without adding to the code coverage. * The handling of the exclusion set is independent of the * set of encodings, so there is no need to test every combination. */ excluded_set_id = testCaseIdx % UPRV_LENGTHOF(excluded_sets); { UConverterSelector *sel_rt, *sel_fb; char *buffer_fb = NULL; UErrorCode status = U_ZERO_ERROR; sel_rt = ucnvsel_open(encodings, num_encodings, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_SET, &status); if (num_encodings == gCountAvailable) { /* test the special "all converters" parameter values */ sel_fb = ucnvsel_open(NULL, 0, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_AND_FALLBACK_SET, &status); } else if (uset_isEmpty(excluded_sets[excluded_set_id])) { /* test that a NULL set gives the same results as an empty set */ sel_fb = ucnvsel_open(encodings, num_encodings, NULL, UCNV_ROUNDTRIP_AND_FALLBACK_SET, &status); } else { sel_fb = ucnvsel_open(encodings, num_encodings, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_AND_FALLBACK_SET, &status); } if (U_FAILURE(status)) { log_err("ucnv_sel_open(encodings %ld) failed - %s\n", testCaseIdx, u_errorName(status)); ucnvsel_close(sel_rt); uprv_free((void *)encodings); continue; } text_reset(&text); for (;;) { UBool *manual_rt, *manual_fb; static UChar utf16[10000]; char *s; int32_t length8, length16; s = text_nextString(&text, &length8); if (s == NULL || (getTestOption(QUICK_OPTION) && text.number > 3)) { break; } manual_rt = getResultsManually(encodings, num_encodings, s, length8, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_SET); manual_fb = getResultsManually(encodings, num_encodings, s, length8, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_AND_FALLBACK_SET); /* UTF-8 with length */ status = U_ZERO_ERROR; verifyResult(ucnvsel_selectForUTF8(sel_rt, s, length8, &status), manual_rt); verifyResult(ucnvsel_selectForUTF8(sel_fb, s, length8, &status), manual_fb); /* UTF-8 NUL-terminated */ verifyResult(ucnvsel_selectForUTF8(sel_rt, s, -1, &status), manual_rt); verifyResult(ucnvsel_selectForUTF8(sel_fb, s, -1, &status), manual_fb); u_strFromUTF8(utf16, UPRV_LENGTHOF(utf16), &length16, s, length8, &status); if (U_FAILURE(status)) { log_err("error converting the test text (string %ld) to UTF-16 - %s\n", (long)text.number, u_errorName(status)); } else { if (text.number == 0) { sel_fb = serializeAndUnserialize(sel_fb, &buffer_fb, &status); } if (U_SUCCESS(status)) { /* UTF-16 with length */ verifyResult(ucnvsel_selectForString(sel_rt, utf16, length16, &status), manual_rt); verifyResult(ucnvsel_selectForString(sel_fb, utf16, length16, &status), manual_fb); /* UTF-16 NUL-terminated */ verifyResult(ucnvsel_selectForString(sel_rt, utf16, -1, &status), manual_rt); verifyResult(ucnvsel_selectForString(sel_fb, utf16, -1, &status), manual_fb); } } uprv_free(manual_rt); uprv_free(manual_fb); } ucnvsel_close(sel_rt); ucnvsel_close(sel_fb); uprv_free(buffer_fb); } uprv_free((void *)encodings); } releaseAvailableNames(); text_close(&text); for(i = 0 ; i < 3 ; i++) { uset_close(excluded_sets[i]); } }
int main (int argc, char *argv[]) { struct timeval startt, endt, result; int i, j, k, nt, t, n, c; void *status; pthread_attr_t attr; tThreadArg x[NUM_THREADS]; result.tv_sec = 0; result.tv_usec= 0; /* Initialize and set thread detached attribute */ pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); printf("|NSize|Iterations|Seq|Th01|Th02|Th04|Th08|Par16|\n"); // for each input size for(c=0; c<NSIZE; c++){ int n=Ns[c]*2/3; int m=Ns[c]/3; // Seed Input int *A, *B, *AB; setup(&A, &B, &AB, n, m); printf("| %d | %d |",(n+m),TIMES); /* Run sequential algorithm */ result.tv_usec=0; gettimeofday (&startt, NULL); for (t=0; t<TIMES; t++) { mergeSeq(A, B, AB, n, m); } gettimeofday (&endt, NULL); result.tv_usec = (endt.tv_sec*1000000+endt.tv_usec) - (startt.tv_sec*1000000+startt.tv_usec); printf("%ld | ", result.tv_usec/TIMES); int seqResult[n+m]; for(j=0;j<n+m;j++) seqResult[j] = AB[j]; /* Run threaded algorithm(s) */ for(nt=1; nt<NUM_THREADS; nt=nt<<1){ if(pthread_barrier_init(&barr, NULL, nt+1)) { printf("Could not create a barrier\n"); return -1; } if(pthread_barrier_init(&internal_barr, NULL, nt)) { printf("Could not create a barrier\n"); return -1; } result.tv_sec=0; result.tv_usec=0; for (j=1; j<=/*NUMTHRDS*/nt; j++) { x[j].id = j; x[j].nrT=nt; // number of threads in this round x[j].n=n; //input size x[j].m=m; //input size x[j].A = A; x[j].B = B; x[j].AB = AB; pthread_create(&callThd[j-1], &attr, par_function, (void *)&x[j]); } gettimeofday (&startt, NULL); pthread_barrier_wait(&barr); gettimeofday (&endt, NULL); //printDataset("\nA: ", A, n); //printDataset("B: ", B, m); //printDataset("AB: ", AB, n+m); /* Wait on the other threads */ for(j=0; j</*NUMTHRDS*/nt; j++) { pthread_join(callThd[j], &status); } if (pthread_barrier_destroy(&barr)) { printf("Could not destroy the barrier\n"); return -1; } if (pthread_barrier_destroy(&internal_barr)) { printf("Could not destroy the barrier\n"); return -1; } result.tv_usec += (endt.tv_sec*1000000+endt.tv_usec) - (startt.tv_sec*1000000+startt.tv_usec); printf("%ld | ", result.tv_usec/TIMES); } int parResult[n+m]; for(j=0;j<n+m;j++) parResult[j] = AB[j]; verifyResult(seqResult, parResult, n); printf("\n"); //printDataset("\nseqResult: ", seqResult, n+m); //printDataset("\nparResult: ", parResult, n+m); } pthread_exit(NULL); }
main () { int h,i,j,k; int n_var=7; int t_var=5; int nSize[7] = {16, 64, 256, 1024, 4096, 16384, 65536}; //int nSize[7] = {17,17,17,17,17,17,17}; int threads[5] = {1, 2, 4, 8, 16}; int repeat = 1000; printf("Lab Work 3 - Performance Test - List Ranking\n"); printf("\t\tseq\t"); for(h=0;h<t_var;h++) printf("t=%i\t", threads[h]); printf("\n"); for(i=0; i<n_var; i++) { //set up inputs int *S, *R; int n = nSize[i]; setup(&S, &R, n); // int x[17] = {0, 14, 13, 5, 16, 11, 10, 9, 12, 0, 8, 7, 15, 4, 3, 2, 1}; // // S=x; //printf("Input n: 0 1 2 3 4\n"); //printDataset("Input S: ", S, n); printf("size=%.5i\t", nSize[i]); timeFunc(listRankSeq, S, R, n, repeat); int seqResult[n]; for(j=0;j<n;j++) seqResult[j] = R[j]; for(k=0;k<t_var;k++) { //set up threads number. int threads_num = threads[k]; omp_set_dynamic(0); omp_set_num_threads(threads_num); timeFunc(listRank, S, R, n, repeat); } int parResult[n]; for(j=0;j<n;j++) parResult[j] = R[j]; verifyResult(seqResult, parResult, n); printf("\n"); //printDataset("Output R: ", R, n); //printf("\n"); } }