/***************************************************************************** * SOURCE: This is a translation of a Pthread program from the Lawrence Livermore * Computing Center POSIX Threads Programming Exercise at: * https://computing.llnl.gov/tutorials/pthreads/exercise.html * FILE: bug6fix.cvl * DESCRIPTION: * This solution uses a mutex variable to protect the global sum while each * thread updates it. A much more efficient method would be that used in the * dotprod_mutex.cvl example. * Command line execution: * civl verify -inputNUMTHRDS=8 -inputVECLEN=100000 bug6fix.cvl ******************************************************************************/ #include #include "pthread.cvh" #include #include /* Define global data where everyone can see them */ $input int NUMTHRDS; $input int VECLEN; pthread_mutex_t mutexsum; int *a, *b; long sum=0.0; void *dotprod(void *arg) { /* Each thread works on a different set of data. * The offset is specified by the arg parameter. The size of * the data for each thread is indicated by VECLEN. */ int i, start, end, offset, len; long tid; tid = (long)*arg; // Dereference rather than direct conv offset = tid; len = VECLEN; start = offset*len; end = start + len; /* Perform my section of the dot product */ printf("thread: %d starting. start=%d end=%d\n",tid,start,end-1); // Removed l from %ld, unsupported for (i=start; i