int
main (void)
{
  int array[ARRAYSIZE];
  struct ThreadData data[NUMTHREADS];
  int i;
  /* this has the effect of rounding up the number of tasks
   * per thread, which is useful in case ARRAYSIZE does not
   * divide evenly by NUMTHREADS. */
  int tasksPerThread = (ARRAYSIZE + NUMTHREADS - 1) / NUMTHREADS;

  /* Divide work for threads, prepare parameters */
  for (i = 0; i < NUMTHREADS; i++) {
    data[i].start = i * tasksPerThread;
    data[i].stop = (i + 1) * tasksPerThread;
    data[i].array = array;
  }
  /* the last calculation must not go past the end of the array */
  data[NUMTHREADS - 1].stop = ARRAYSIZE;

  /* Do each part */
  for (i = 0; i < NUMTHREADS; i++) {
    squarer (&data[i]);
  }

  /* Display Result */
  for (i = 0; i < ARRAYSIZE; i++) {
    printf ("%d ", array[i]);
  }
  printf ("\n");

  return 0;
}
Ejemplo n.º 2
0
/**
	 * @brief Calcualtes the correlation between two input data strings
	 * @param in/out- pointers to floating point variables representing 2 input data strings
	 * @param length- integer number representing the length of the input data string
   * @retval floating point variable representing the calculated correlation between 2 input data strings
   */
float correlation(float* in, float* out, int length){
    
	float mean_in = mean(in, length);
	float mean_out = mean(out, length);

	float flt_temp1 = 0;
	float flt_temp2 = 0;
	float flt_temp3 = 0;
	int i;
	for(i = 0; i < length; i++){
		flt_temp1 = flt_temp1 + ((in[i] - mean_in) * (out[i] - mean_out));
		flt_temp2 = flt_temp2 + squarer(in[i] - mean_in);
		flt_temp3 = flt_temp3 + squarer(out[i] - mean_out);
	}

	return(flt_temp1 / root(flt_temp2 * flt_temp3));
}
Ejemplo n.º 3
0
/**
	 * @brief Calcualtes the standard deviation of an input data string
	 * @param diff- pointer to a floating point variable representing the input data string
	 * @param result- pointer to a floating point variable representing the output data string
	 * @param length- integer number representing the length of the input data string
   * @retval void
   */
void misc(float* result, float* diff, int length){
    
	float flt_temp1 = 0;
	int i;
	result[0] = mean(diff, length);
	for(i = 0; i < length; i++){
		flt_temp1 = flt_temp1 + squarer(diff[i] - result[0]);
	}

	result[1] = root(flt_temp1 / length - 1);
}