int main(int v, char **c) { //srand(( unsigned )time(NULL)); inputCorretto(v, c); char ch; double *a; int len = atoi(c[2]); fprintf(stdout, "Vuoi generare l'array a random (y/n)? "); fscanf(stdin, "%c", &ch); if( ch == 'y') { a = generateArray(RANDOM, DOUBLE, len, 100); for( int i = 0; i<len; i++) a[i] = a[i]/100; } else a = generateArray(NOTRANDOM, DOUBLE, len); printArray(a, len, "double"); bucketSort( a, len ); return 0; }
void dpVectorAdd::init(){ dataParameters.push_back(Asize); dataNames.push_back("nElements"); // Allocate and initialize host arrays srcA = (float *)malloc(sizeof(cl_float) * Asize); srcB = (float *)malloc(sizeof(cl_float) * Asize); dst = (float *)malloc(sizeof(cl_float) * Asize); generateArray(srcA, Asize); generateArray(srcB, Asize); }
// returns the pointer to the list; NULL if list not created PCB_p createPCB(char* name, int newPid, int newPriority, int theInterruptSimulator, int thePcValue, State theState) { if (newPriority > 15 || newPriority < 0) { printf("Error 1212123: Priority must be 0 - 15. PCD not Created."); } //struct control_block_type testing; PCB_p pcb = malloc(sizeof(struct PCB)); // if allocation was successful if (pcb != NULL) { strcpy(pcb->name, name); pcb->pid = newPid; pcb->priority = newPriority; pcb->interrupt_simulator = theInterruptSimulator; pcb->pc = thePcValue; pcb->currentState = theState; //New stuff //pcb->max_pc = ? jowy added (do we need a new parameter?) pcb->creation = getTheCurrentTime(); pcb->terminate = (rand() % 11) +1; pcb->term_count = 0; generateArray(pcb->IO_1_traps, pcb->IO_2_traps); } return pcb; }
// ---------------------------------------------------------------------------- int main(int argc, char** argv) { DBG("[Lesson 1]: Sortings: Standard sort 1"); int A[SIZE], B[SIZE], C[SIZE]; generateArray(A, SIZE); copy(A, B, SIZE); copy(A, C, SIZE); sort::insertion(A, SIZE); sort::mergesort(B, SIZE); sort::quicksort(C, SIZE); if (!equal(A, B, SIZE)) { ERR("Insertion vs Mergesort NOT equal result!"); } else { INF("OK"); } if (!equal(A, C, SIZE)) { ERR("Insertion vs Quicksort NOT equal result!"); } else { INF("OK"); } if (!equal(B, C, SIZE)) { ERR("Mergesort vs Quicksort NOT equal result!"); } else { INF("OK"); } DBG("[Lesson 1]: Sortings: Standard sort 1 [END]"); return 0; }
int main(int argc, char *argv[]) { int i; int n; // loop {number of iterations} [number of threads] if(argc<2) { printf("Usage: sumcomp {array size} [number of threads]\n"); exit(1); } n = atoll(argv[1]); printf("Debug: array size = %d \n",n); if(argc==3) { p = atoi(argv[2]); assert(p>=1); printf("Debug: number of requested threads = %d\n",p); } omp_set_num_threads(p); #pragma omp parallel { assert(p==omp_get_num_threads()); //printf("Debug: number of threads set = %d\n",omp_get_num_threads()); int rank = omp_get_thread_num(); printf("Rank=%d: my world has %d threads\n",rank,p); } // end of my omp parallel region double time = omp_get_wtime(); // 1. generate the array // // int *a=NULL; a = generateArray(n); //dispArray(a,n); // 2. compute sum using reduce computeSum(a,n); time = omp_get_wtime() - time; printf("Total time = %f seconds \n ", time); return 0; }
int main() { srand(time(NULL)); int *array= NULL, size = 20; array=(int*)malloc(size*sizeof(int)); generateArray(array, size, 0, 99); outputArray(array, size); sortBuble(array, size,less); outputArray(array,size); free(array); array=NULL; return 0; }
//main function definition int main() { SeedRand(); //seeds the rand() with system time int size=6; struct input* ip = NULL; struct data** dt = NULL; ip=generateArray(size); //input structure is generated and initialized dt=generateDataArray(size); //generates and initializes data structure findMax(dt,size,ip); //calls findMax function printData(dt,size); //printData function called //frees the allocated space from the heap freeallpointers(dt,size,ip); return 0; //successful termination of program }
// ----------------------------------------------------------- // FUNCTION Heap Sort : (heap) // Sorts m random integers using the heap sort // PARAMETER USAGE : // m : The number of integers to sort using heap sort // FUNCTION CALLED : // generateArray: It creates a random array of size m, of ints // printArray: Prints the array given to it. For both sorted and unsorted array // sortArray: Sorts the array given to it //----------------------------------------------------------- int heap( long int *m ) { char buffer[256]; int heapArray[*m], i; sprintf( buffer, " Heap Sort Process Started\n" ); write( 1, buffer, strlen( buffer ) ); generateArray( heapArray, *m ); printArray( heapArray, *m, 0 ); sortArray( heapArray, *m ); printArray( heapArray, *m, 1 ); sprintf( buffer, " Heap Sort Process Exits\n" ); write( 1, buffer, strlen( buffer ) ); }
int main(int argc, char *argv[]){ int i, j; int N; char name[128]; N = 50000000; float *Aout, *Ain; Aout = (float*) malloc(N*sizeof(float)); if (!Aout){ fprintf(stderr,"error in Aout malloc"); } Ain = (float*) malloc(N*sizeof(float)); if (!Ain){ fprintf(stderr,"error in Ain malloc"); } printf("total Data: %0.3f Megabytes\n", (float) N*sizeof(float)/1048576); generateArray(Ain, N); //starting up opencl cl_device_id devices[MAXDEVICES]; cl_platform_id platforms[MAXPLATFORMS]; unsigned int num_devices, num_platforms; clGetPlatformIDs(MAXPLATFORMS, platforms, &num_platforms); printf("number of platforms found: %d\n", num_platforms); for (i = 0; i < num_platforms; i++){ clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, sizeof(name), name, NULL); clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, MAXDEVICES, devices, &num_devices); //list devices available on platform printf("platform %s with %d devices\n", name, num_devices); for (j = 0; j < num_devices; j++){ clGetDeviceInfo(devices[j], CL_DEVICE_NAME, sizeof(name), name, NULL); printf("\tdevice %d %s\n", j, name); memTest(platforms[i], devices[j], Ain, Aout, N); } } return 0; }
int main (int argc, char *argv[]){ int proc_id,procs_num; int iloop; int A[totalSize]; int a[chunkSize]; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &proc_id); MPI_Comm_size(MPI_COMM_WORLD, &procs_num); if (proc_id == 0) { generateArray("A",A,totalSize); printArray("A",A,totalSize,0); } MPI_Scatter(A, chunkSize, MPI_INT, a, chunkSize, MPI_INT, 0, MPI_COMM_WORLD); printArray("a",a,chunkSize,proc_id); MPI_Finalize(); }
int main() { static int array[100]; int initilized = 0; int sorted = 0; int loop = 1; while(loop == 1) { int choice; printf("Välj opperation:\n"); printf(" 1. Generera en ny Talföljd.\n"); printf(" 2. Sortera arrayen.\n"); printf(" 3. Min/Max/median.\n"); printf(" 4. Sök.\n"); printf(" 8. Print array.\n"); printf(" 9. Exit.\n"); scanf("%d", &choice); switch(choice) { case 1: array = generateArray(array); initilized = 1; sorted = 0; printArray(array); break; case 2: if(initilized == 1) { array = sortArray(array); sorted = 1; printArray(array); } else { printf("Ej giltig Talföljd.\nGenerera en ny först.\n"); } break; case 3: if(sorted == 1) { valueOperations(array); } else { printf("Ej giltig Talföljd.\nGenerera en ny Sortera först.\n"); } break; case 4: if(sorted == 1) { int value; printf("Vilket värde vill ni söka efter?\n"); scanf("%d", &value); searchArray(array, value); } else { printf("Ej giltig Talföljd.\nSortera först.\n"); } case 8: printArray(array); break; case 9: loop = 0; break; default: printf("Ej giltigt kommando.\n"); break; } } return 1; }
// ---------------------------------------------------------------------------- int main(int argc, char** argv) { DBG("[Lesson 1]: Sortings: Standard sort 2"); bool flag = true; while (flag) { size_t size = std::rand() % 65536 + 1; int* A = new int[size]; int* B = new int[size]; int* C = new int[size]; int* D = new int[size]; generateArray(A, size); copy(A, B, size); copy(A, C, size); copy(A, D, size); sort::insertion(A, size); sort::mergesort(B, size); sort::quicksort(C, size); std::sort(D, D + size); bool accumulate_1 = equal(A, B, size); bool accumulate_2 = equal(A, C, size); bool accumulate_3 = equal(B, C, size); bool accumulate_4 = equal(D, C, size); if (!accumulate_1) { ERR("Insertion vs Mergesort NOT equal result!"); print(A, size); printf("\n"); print(B, size); flag = false; } if (!accumulate_2) { ERR("Insertion vs Quicksort NOT equal result!"); print(A, size); printf("\n"); print(C, size); flag = false; } if (!accumulate_3) { ERR("Mergesort vs Quicksort NOT equal result!"); print(B, size); printf("\n"); print(C, size); flag = false; } if (!accumulate_4) { ERR("Standard sort vs Quicksort NOT equal result!"); print(D, size); printf("\n"); print(C, size); flag = false; } if (flag) { INF("OK: %zu", size); } delete [] A; delete [] B; delete [] C; delete [] D; } DBG("[Lesson 1]: Sortings: Standard sort 2 [END]"); return 0; }