/* * posix_threads.cpp * * Created on: 10.01.2011 * Author: mk */ #include // POSIX-threads #include // time operations (to calculate the runtime) #include // standard IO operations (to print to console) #include // general purpose standard library (to generate random numbers) #define NUM_ELEMENTS 1000000 // number of array-elements to add pthread_t* threads; // stores the posix-thread-objects int* threadNums; // stores the thread-numbers time_t beginCalc,endCalc; // used to calculate the runtime of the program unsigned long a[NUM_ELEMENTS],b[NUM_ELEMENTS],c[NUM_ELEMENTS]; // arrays to add (c=a+b) int numThreads; // number of threads to create /* * fills the arrays with random numbers between 0 and 9 */ void fillArrays() { for(unsigned i=0;i1) { threads = (pthread_t*)malloc(numThreads*sizeof(pthread_t)); // reserve memory for the threads threadNums = (int*)malloc(numThreads*sizeof(int)); // reserve memory for the thread-numbers for (unsigned i=0;i