/****************************************************************************************** * 起泡排序测试程序 ******************************************************************************************/ void main ( int argc, char* argv[] ) { int n = 0; //array length if ( 1 < argc ) n = atoi ( argv[1] ); if ( n < 0 ) n = 0; //make sure length is non-negative int* A = ( int* ) malloc ( n * sizeof ( int ) ); //allocate an array of size n unsigned int seed = ( unsigned int ) time ( NULL ); //A same seed is used here for comparison between different algorithms printf ( "\n== Bubblesort algorithm #0 ========\n" ); randomArray ( A, n, seed ); //create a randomized array using the same seed printf ( "--> " ); print ( A, n ); bubblesort ( A, n ); //sort the array using algorithm#0 printf ( "==> " ); print ( A, n ); printf ( "\n== Bubblesort algorithm #1A ========\n" ); randomArray ( A, n, seed ); //create a randomized array using the same seed printf ( "==> " ); print ( A, n ); bubblesort1A ( A, n ); //sort the array using algorithm#1A printf ( "==> " ); print ( A, n ); printf ( "\n== Bubblesort algorithm #1B ========\n" ); randomArray ( A, n, seed ); //create a randomized array using the same seed printf ( "==> " ); print ( A, n ); bubblesort1B ( A, n ); //sort the array using algorithm#1B printf ( "==> " ); print ( A, n ); printf ( "\n== Bubblesort algorithm #2 ========\n" ); randomArray ( A, n, seed ); //create a randomized array using the same seed printf ( "==> " ); print ( A, n ); bubblesort2 ( A, n ); //sort the array using algorithm#2 printf ( "==> " ); print ( A, n ); free ( A ); //release the array }
void testSparseGammaGapMergingRandom( uint64_t const nl, uint64_t const kll, uint64_t const klh, uint64_t const nr, uint64_t const krl, uint64_t const krh ) { libmaus::autoarray::AutoArray<uint64_t> Al = randomArray(nl,kll,klh); libmaus::autoarray::AutoArray<uint64_t> Ar = randomArray(nr,krl,krh); testSparseGammaGapMergingSmall(Al.begin(),Al.size(),Ar.begin(),Ar.size()); }
void main(int argc,char **argv) { int n=atoi(argv[1]); int filter=20; int a[n]; randomArray(a,n); double serial_time=serialFilter(a,n,filter); printf("%f\n",serial_time); }
void main(int argc,char **argv) { int n=atoi(argv[1]); int filter=50; int a[n]; randomArray(a,n); double parallel_time=parallelFilter(a,n,filter); printf("%f\n",parallel_time); }
int test_sort() { int* array = randomArray(N); if (array == NULL) return 0; std::cout.width(8); std::cout.setf(std::ios::left); std::cout << "before insertsort" << std::endl; for (int i = 0; i < N; i++) { std::cout << array[i] << " "; if ((i + 1) % 10 == 0) std::cout << std::endl; } Sort::insert_sort(array, N); std::cout << "after insertsort" << std::endl; for (int i = 0; i < N; i++) { std::cout << array[i] << " "; if ((i + 1) % 10 == 0) std::cout << std::endl; } array = randomArray(N); std::cout << "before mergesort" << std::endl; for (int i = 0; i < N; i++) { std::cout << array[i] << " "; if ((i + 1) % 10 == 0) std::cout << std::endl; } Sort::merge_sort(array, 0, N - 1); std::cout << "after mergesort" << std::endl; for (int i = 0; i < N; i++) { std::cout << array[i] << " "; if ((i + 1) % 10 == 0) std::cout << std::endl; } return 0; }
void HttpPoll::resetKey() { #ifdef PROX_DEBUG fprintf(stderr, "HttpPoll: reset key!\n"); #endif QByteArray a = randomArray(64); QString str = QString::fromLatin1(a.data(), a.size()); d->key_n = POLL_KEYS; for(int n = 0; n < POLL_KEYS; ++n) d->key[n] = hpk(n+1, str); }
//Execution Begins Here int main (int argc, char **argv){ QApplication app(argc, argv); int rows = 5; int cols = 6; srand(time(NULL)); char* numbers; Array randomArray(rows, cols); numbers = randomArray.toString(); QLabel *label = new QLabel(numbers); label->show(); return app.exec(); }
int main(int argc, char** argv) { int *t, toread; long long int n, i, j, size; n=atof(argv[1]); int ar[2][n]; int a[n]; randomArray(a,n); double serialStart = omp_get_wtime(); int* aserial = prefixSumSerial(a, n); double serialStop = omp_get_wtime(); //Serial printf("%lf\n", (serialStop-serialStart)); return 0; }
/** @fn void ClientCpp::work() @brief A method of Client's class that runs the main functions of the class and sends the information for the server @param *array an integer array pointer @return */ void ClientCpp::work() { clientArray_ = (int *) malloc (sizeof (int) * cArraySize_); randomArray(clientArray_); while (doWork_) { cltMutex.lock(); if (tryWork_ && isClientReady_) { gettimeofday(&iniTime, NULL); qsort(clientArray_, cArraySize_, sizeof (int), compairC); gettimeofday(&iniConnTime, NULL); send(my_socket_, clientArray_, sizeof (int)*cArraySize_, 0); doWork_ = 0; } cltMutex.unlock(); usleep(1000); } }
// Test glTexImage and glGetTexImage functionality bool TextureSRGBTest::testImageTransfer(void) { const GLubyte *image = randomArray(128 * 128 * 4, 0); GLubyte image2[128 * 128 * 4]; int i, j; for (i = 0; Formats[i].sFormat; i++) { // upload tex image glTexImage2D(GL_TEXTURE_2D, 0, Formats[i].sFormat, 128, 128, 0, Formats[i].baseFormat, GL_UNSIGNED_BYTE, image); // retrieve tex image glGetTexImage(GL_TEXTURE_2D, 0, Formats[i].baseFormat, GL_UNSIGNED_BYTE, image2); // compare original and returned images const int comps = Formats[i].components; for (j = 0; j < 128 * 128 * comps; j++) { if (image[j] != image2[j]) { env->log << '\n' << name << " glGetTexImage failed for internalFormat " << Formats[i].sFormat << "\n"; env->log << "Expected value at [" << j << "] should be " << (int) image[j] << " found " << (int) image2[j] << "\n"; delete [] image; return false; } image2[j] = 0; // reset for next GetTexImage } } delete [] image; return true; }
static QString genId() { return QCA::Hash("sha1").hashToString(randomArray(128)); }
bool TextureSRGBTest::testTextureFormat(GLenum intFormat, GLint components, GLEAN::Environment &env) { const GLubyte *image = randomArray(128 * 128 * 4, intFormat); GLfloat readback[128 * 128 * 4]; int i; GLint redBits, alphaBits; glGetIntegerv(GL_RED_BITS, &redBits); glGetIntegerv(GL_ALPHA_BITS, &alphaBits); const float tolerance = 1.0 / ((1 << (redBits - 1)) - 1); // setup matrices glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glViewport(0, 0, windowSize, windowSize); // setup texture glTexImage2D(GL_TEXTURE_2D, 0, intFormat, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, image); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glEnable(GL_TEXTURE_2D); glDisable(GL_DITHER); glDrawBuffer(GL_FRONT); glReadBuffer(GL_FRONT); // draw test polygon glBegin(GL_POLYGON); glTexCoord2f(0, 0); glVertex2f(-1, -1); glTexCoord2f(1, 0); glVertex2f( 1, -1); glTexCoord2f(1, 1); glVertex2f( 1, 1); glTexCoord2f(0, 1); glVertex2f(-1, 1); glEnd(); glReadPixels(0, 0, windowSize, windowSize, GL_RGBA, GL_FLOAT, readback); // compare rendered results to expected values for (i = 0; i < 128 * 128; i++) { const GLfloat *actual = readback + i * 4; GLfloat expected[4]; expected[0] = nonlinear_to_linear(image[i * 4 + 0]); expected[1] = nonlinear_to_linear(image[i * 4 + 1]); expected[2] = nonlinear_to_linear(image[i * 4 + 2]); expected[3] = image[i * 4 + 3] / 255.0; if (components <= 2) { if (fabs(actual[0] - expected[0]) > tolerance) { env.log << '\n' << name << " failed for internalFormat " << intFormat << "\n"; env.log << "Expected luminance " << expected[0] << " found " << actual[0] << "\n"; delete [] image; return GL_FALSE; } } else { assert(components == 3 || components == 4); if (fabs(actual[0] - expected[0]) > tolerance || fabs(actual[1] - expected[1]) > tolerance || fabs(actual[2] - expected[2]) > tolerance) { env.log << '\n' << name << " failed for internalFormat " << intFormat << "\n"; env.log << "Expected color " << expected[0] << ", " << expected[1] << ", " << expected[2] << " found " << actual[0] << ", " << actual[1] << ", " << actual[2] << "\n"; delete [] image; return GL_FALSE; } } if (alphaBits >= redBits && components == 4 && fabs(actual[3] - expected[3]) > tolerance) { env.log << '\n' << name << " failed for internalFormat " << intFormat << "\n"; env.log << "Expected alpha " << expected[3] << " found " << actual[3] << "\n"; delete [] image; return GL_FALSE; } } delete [] image; return GL_TRUE; }