Пример #1
0
void longExecution(long th_id)
{
    Extrae_user_function (1);
    printf ("Thread %08lx: Waiting 5 seconds\n", th_id);
    sleep(5);
    Extrae_user_function (0);
}
Пример #2
0
long long int Cutter3 (char *input, char *output, long long int from, long long int to)
{
  FILE *fd = NULL;
  char *cutter_args[6];
  char   from_str[128];  
  char     to_str[128];  
  long long int cut_size_in_bytes = 0;

#ifdef TRACE_MODE
  Extrae_user_function (1);
#endif 

  snprintf(from_str, sizeof(from_str), "%lld", from);
  snprintf(to_str,   sizeof(to_str),   "%lld", to);

  cutter_args[0] = "cutter";
  cutter_args[1] = input;
  cutter_args[2] = output;
  cutter_args[3] = "-t";
  cutter_args[4] = from_str;
  cutter_args[5] = to_str;

  cutter_main (6, cutter_args);

  fd = fopen(output, "r");
  fseek(fd, 0L, SEEK_END);
  cut_size_in_bytes = ftell( fd );
  fclose(fd);

#ifdef TRACE_MODE 
  Extrae_user_function (0);
#endif

  return cut_size_in_bytes;
}
Пример #3
0
int main (int argc, char *argv[])
{
	Extrae_user_function(1);
	fA();
	fB();
	Extrae_user_function(0);
	return 0;
}
Пример #4
0
void Sampler_wavelet (signal_t *signal, spectral_value_t **waveletSignal, int number_of_points, char *dbg_file)
{
#ifdef TRACE_MODE
  Extrae_user_function (1);
#endif
  fprintf (stdout, "Executing Sampler Wavelet...");
  long long int period, last_signal_time;
  spectral_value_t last_value;
  int calculated_periods = 0, i;
  spectral_value_t * wavelet_values = NULL;
#ifdef DEBUG_MODE
  FILE *fp;
  if ((fp = fopen (dbg_file, "w")) == NULL)
    {
      fprintf (stderr, "\nDebug: Can't open file '%s'!\n\n");
      perror("fopen: ");
      exit (-1);
    }
#endif
  wavelet_values = (spectral_value_t *)malloc(sizeof(spectral_value_t) * number_of_points);

  /* Obtaning de last time of the wavelet */
  last_signal_time = SIGNAL_LAST_TIME(signal);

  /* Period = Total time / number of samples */
  period = last_signal_time / number_of_points;

  /* Calculating points */

  last_value = SIGNAL_FIRST_VALUE(signal);
  i = 1;

  while (calculated_periods < number_of_points)
    {
      while (i < SIGNAL_SIZE(signal) && calculated_periods * period > SIGNAL_TIME(signal, i))
	{
	  last_value = SIGNAL_VALUE(signal, i);
	  i++;
	}
      wavelet_values[calculated_periods] = last_value;
      calculated_periods++;
#ifdef DEBUG_MODE
      fprintf (fp, "%lf\n", last_value);
#endif
    }

#ifdef DEBUG_MODE
  fclose (fp);

#endif
  printf ("Done!\n");
  fflush (stdout);

  *waveletSignal = wavelet_values;
#ifdef TRACE_MODE
  Extrae_user_function (0);
#endif
}
Пример #5
0
double pi_kernel (int n, double h)
{
	double tmp = 0;
	double x;
	int i;

	Extrae_user_function (1);

	for (i = 1; i <= n; i++)
	{
		x = h * ((double)i - 0.5);
		tmp += (4.0 / (1.0 + x*x));
	}

	Extrae_user_function (0);

	return tmp;
}
Пример #6
0
signal_t * Sampler (signal_t *signal, spectral_value_t freq, char *dbg_file)
{
  int i=0, j=0;
  int num_samples = 0;
  signal_t *sampledSignal = NULL;
  spectral_time_t total_time = 0;

#ifdef TRACE_MODE
  Extrae_user_function (1);
#endif

  total_time    = Spectral_GetSignalTime( signal );
  num_samples   = (total_time / freq) + 1;
  sampledSignal = Spectral_AllocateSignal( num_samples );

  while (i < num_samples)
  {
    while ( (i * freq > SIGNAL_TIME(signal, j) + SIGNAL_DELTA(signal, j)) && (j < SIGNAL_SIZE(signal)) )
    {
      j ++;
    }
    SIGNAL_ADD_POINT_3( sampledSignal, 
      signal->data[j].time, 
      signal->data[j].delta, 
      signal->data[j].value 
    );
    i ++;
  }

#ifdef DEBUG_MODE
  Spectral_DumpSignal( sampledSignal, dbg_file );
#endif

#ifdef TRACE_MODE
  Extrae_user_function (0);
#endif

  return sampledSignal;
}
Пример #7
0
void fB(void)
{
	Extrae_user_function(1);
	printf ("fB\n");
	Extrae_user_function(0);
}
Пример #8
0
/*================================================================================
 * recursively generate the AMR hierarchy
 *================================================================================*/
boolean gen_AMRhierarchy(gridls **grid_list, int *no_grids)
{
  gridls *cur_grid;                   /* current grid pointer                  */
  gridls *fin_grid;                   /* fine grid pointer                     */
  gridls *for_grid;                   /* sometimes needed for debugging...     */
  int     fingrid_no, curgrid_no;     /* index of finest and current grid      */
  int     grid_no;
  
  boolean runAHF;  /* only run AHF when the finest grid level has been reached */
  boolean refined; /* refinement flag                                          */
  
#ifdef EXTRAE_API_USAGE
  Extrae_user_function(1);
#endif

  /* up to now we plan to run AHF */
  runAHF = TRUE;
  
  
  /*=========================================================================
   * try to refine finest grid:
   *
   * 1. get (number!) density field on currently finest grid right
   * 2. try to refine grid using 'number of particles per node' criterion
   *=========================================================================*/
  
  /* currently the finest grid... */
  fin_grid = *grid_list + *no_grids - 1;
  
  if(!(((global.fst_cycle == FALSE) && (fin_grid->l1dim == global.fin_l1dim)) || 
       ((fin_grid->l1dim) == simu.NGRID_MAX)))
   {
    timing.genrefgrids  -= time(NULL);
    
    /* get number density: "npart/node" */
    fin_grid->time.grid -= time(NULL);
    zero_dens   (fin_grid);
    assign_npart(fin_grid);
    fin_grid->time.grid += time(NULL);
    
    /* try to refine grid under "npart/node" criterion */
    refined = gen_refgrid(grid_list, no_grids);
    
    timing.genrefgrids  += time(NULL);
   }
  else
   {
    refined = FALSE;
   } 
  
  /*--------------------------------------------------
   * when refined we make a recursive call to step()
   *--------------------------------------------------*/
  if(refined == TRUE) 
   {
    /* recursive call to gen_AMRhierarchy() */
    runAHF = gen_AMRhierarchy(grid_list, no_grids);
    
    curgrid_no      = *no_grids - 1;
    fingrid_no      = *no_grids - 1;
    global.dom_grid = *grid_list + global.domgrid_no;
    cur_grid        = *grid_list + curgrid_no;
   }
  
  /*---------------------------------------------
   * otherwise stay with the actual finest grid
   *---------------------------------------------*/
  else /* refined == FALSE */
   {
    /* no new refinement => stay with current finest grid */
    curgrid_no      = *no_grids - 1;
    fingrid_no      = *no_grids - 1;
    global.dom_grid = *grid_list + global.domgrid_no;
    cur_grid        = *grid_list + curgrid_no;
    
    /* store force resolution in header info */
    io.header.cur_reflevel = (float)(curgrid_no-global.domgrid_no);
    io.header.cur_frcres   = (float)(simu.boxsize/(double)cur_grid->l1dim);
    io.header.cur_frcres  *= 3000.;
    
    
    energy.time -= time(NULL);
    energy.time += time(NULL);
    
    if(global.fst_cycle == TRUE)
     {
      global.fin_l1dim = cur_grid->l1dim;
      global.fst_cycle = FALSE;
     }
   } /* if(refined) */
  
  
  
  /*=========================================================================
   *
   *         WE NOW HAVE ACCESS TO THE FULL BLOWN GRID HIERACHY
   *
   *=========================================================================*/
  
  
  /*=========================================================================
   *          here are those parts dealing with AHFpotcentre,
   *              the actual AHF is happening in main.c
   *=========================================================================*/
  ahf.time -= time(NULL);
  /* we only run AHF when having reached the end of the grid hierarchy */
  if(runAHF)
   {
    
    /* get the density absolutely right on all amr levels */
    /*====================================================*/
    timing.densrecovery -= time(NULL);
#ifdef AHFdensrecovery
    /* re-assign density right on all grids */
    for(for_grid = cur_grid; for_grid >= global.dom_grid; for_grid--)
      restore_dens(for_grid);      
    if(curgrid_no != fingrid_no) 
      refill_dens(cur_grid);
    if(cur_grid != global.dom_grid)
      stack_dens(cur_grid, global.dom_grid+1);
#endif
    timing.densrecovery += time(NULL);
    
    
    /* obtain gravitational potential */
    /*================================*/
    timing.potcentre -= time(NULL);
#ifdef AHFpotcentre    
    /* solve for potential on domain grids */
    fprintf(stderr,"AHFpotcentres:   solving on domain grid %d ... ",global.dom_grid->l1dim);
    solve_dom_gravity(*grid_list);
    fprintf(stderr,"done\n");
    
    /* solve for potential on refinement grids */
    fprintf(stderr,"                 solving on refinement grids ... ");
    if(curgrid_no > global.domgrid_no)
      for(grid_no = global.domgrid_no+1; grid_no <= curgrid_no; grid_no++)
       {
        fprintf(stderr," %d  ",(global.dom_grid+grid_no)->l1dim);
        solve_ref_gravity(*grid_list, grid_no);
       }
    fprintf(stderr,"done\n");    
#endif /* AHFpotcentre */
    timing.potcentre += time(NULL);
    
   }
  ahf.time += time(NULL);

#ifdef EXTRAE_API_USAGE
  Extrae_user_function(0);
#endif

  /* return FALSE indicating that AHF has been run */
  return(FALSE);
} 
Пример #9
0
/*===============================================================================
 * gen_domgrids: generate the domain grids
 *===============================================================================*/
gridls *gen_domgrids(int *no_grids)
{
  gridls *grid_list;       /* pointer to array of grid entries          */
  gridls *cur_grid;        /* pointer to current grid                   */
  double  mass2dens;        /* conversion factor to get mass density     */
  double  mass2partdens;    /* conversion factor to get particle density */
  double  frac, dl1dim, dno_part;
  int     exp;
  int     l1dim;

#ifdef EXTRAE_API_USAGE
  Extrae_user_function(1);
#endif

  /* calculate the total number of domain grids */
  frac        = (double) simu.NGRID_DOM / (double) simu.NGRID_MIN;
  exp         = (float) (log(frac)/log(2.));
  *no_grids   = exp + 1;
  
#ifdef VERBOSE
  fprintf(stderr,"\n\ngen_domgrids: total number of domain grids = %d (%g, %d)\n\n",*no_grids,frac,exp);
#endif
  
  /*======================================
   * there are '*no_grids' to be created:
   *        a) simu.NGRID_MIN^3 grid
   *            ...
   *        x) simu.NGRID_DOM^3 grid
   *=======================================*/
  
  /* allocate memory for all grids */
  grid_list = (gridls *) calloc(*no_grids, sizeof(gridls));
  
  /*
   * 'grid_list' is the pointer to the first gridls-structure
   * out of '*no_grids' of such structures
   */
  
  /* generate the all grids and initialize the structure with the corresponding data */
  for(cur_grid = grid_list, l1dim = simu.NGRID_MIN; l1dim <= simu.NGRID_DOM; l1dim *= 2, cur_grid++)
    {     
      /* mass2dens <=> 1/rho_bar [code units] */
      dl1dim        = (double)l1dim;
      dno_part      = (double)simu.no_part;
      mass2dens     = pow3(dl1dim)/simu.no_vpart;
      mass2partdens = pow3(dl1dim)/dno_part;
      
      /*===========================
       * fill in grid_list details
       *===========================*/
      cur_grid->timecounter    = global.super_t;
      cur_grid->l1dim          = l1dim;
      cur_grid->spacing        = (double)1.0 / (double) cur_grid->l1dim;
      cur_grid->spacing2       = pow2(cur_grid->spacing);

      cur_grid->masstodens     = mass2dens;
      cur_grid->masstopartdens = mass2partdens;
#ifdef MULTIMASS
      cur_grid->critdens       = simu.Nth_dom * mass2partdens;
#else
      cur_grid->critdens       = simu.Nth_dom * mass2dens;
#endif
      cur_grid->old_resid      = 0.0;
      cur_grid->cur_resid      = 0.0;
      cur_grid->no_sweeps      = 0;
      
      cur_grid->time.potential = 0;
      cur_grid->time.density   = 0;
      cur_grid->time.DK        = 0;
      cur_grid->time.grid      = 0;
      cur_grid->time.hydro     = 0;
      
      cur_grid->multistep             = 0;
      cur_grid->next                  = FALSE;
      
      /*========================================================
       * generate the actual pquad, cquad, and nquad structures
       *========================================================*/
      alloc_quads(cur_grid, l1dim);
    }
    
  /*===========================
   * keep track of domain grid
   *===========================*/
  global.dom_grid   = grid_list + (*no_grids - 1);
  global.domgrid_no = (*no_grids - 1);

#ifdef EXTRAE_API_USAGE
  Extrae_user_function(0);
#endif

  return(grid_list);
}
Пример #10
0
signal_t * Cutter_signal (signal_t *signal, long long int t0, long long int t1, signal_data_t *maximum_point, char *dbg_file)
{
  int i = 0;
  signal_t *cut = NULL;
  spectral_time_t  max_time   = 0;
  spectral_time_t  max_delta  = 0;
  spectral_value_t max_value  = 0;

#ifdef TRACE_MODE
  Extrae_user_function (1);
#endif
  cut = Spectral_AllocateSignal( SIGNAL_SIZE(signal) );

  /* Skip times until t0 */
  i = 0;
  while ((i < SIGNAL_SIZE(signal)) && ((SIGNAL_TIME(signal, i) + SIGNAL_DELTA(signal, i)) < t0))
  {
    i++;
  }

  /* Reached t0, add the first point */
  if ((i < SIGNAL_SIZE(signal)) && ((SIGNAL_TIME(signal, i) + SIGNAL_DELTA(signal, i)) >= t0))
  {
    SIGNAL_ADD_POINT_3( cut,
      0,
      SIGNAL_TIME (signal, i) + SIGNAL_DELTA(signal, i) - t0,
      SIGNAL_VALUE(signal, i)
    );
    if (SIGNAL_LAST_VALUE(cut) > max_value)
    {
      max_time  = SIGNAL_LAST_TIME (cut);
      max_delta = SIGNAL_LAST_DELTA(cut);
      max_value = SIGNAL_LAST_VALUE(cut);
    }
    i++;
  }

  /* Between t0 and t1 */
  while ((i < SIGNAL_SIZE(signal)) && ((SIGNAL_TIME(signal, i) + SIGNAL_DELTA(signal, i)) <= t1))
  {
    SIGNAL_ADD_POINT_3( cut,
      SIGNAL_TIME(signal, i) - t0,
      SIGNAL_DELTA(signal, i),
      SIGNAL_VALUE(signal, i)
    );
    if (SIGNAL_LAST_VALUE(cut) > max_value)
    {
      max_time  = SIGNAL_LAST_TIME (cut);
      max_delta = SIGNAL_LAST_DELTA(cut);
      max_value = SIGNAL_LAST_VALUE(cut);
    }
    i++;
  }

  /* Reached t1, add a last point */
  if ((i < SIGNAL_SIZE(signal)) && ((SIGNAL_TIME(signal, i) + SIGNAL_DELTA(signal, i)) > t1))
  {
    SIGNAL_ADD_POINT_3( cut,
      SIGNAL_TIME(signal, i) - t0,
      t1 - SIGNAL_TIME(signal, i),
      SIGNAL_VALUE(signal, i)
    );
    if (SIGNAL_LAST_VALUE(cut) > max_value)
    {
      max_time  = SIGNAL_LAST_TIME (cut);
      max_delta = SIGNAL_LAST_DELTA(cut);
      max_value = SIGNAL_LAST_VALUE(cut);
    }
    i++;
  }

  if (maximum_point != NULL)
  {
    maximum_point->time  = max_time;
    maximum_point->delta = max_delta;
    maximum_point->value = max_value;
  }

  Spectral_ReallocateSignal( cut, SIGNAL_SIZE(cut) );

#ifdef DEBUG_MODE
  Spectral_DumpSignal( cut, dbg_file );
#endif

#ifdef TRACE_MODE
  Extrae_user_function (0);
#endif

  return cut;
}
Пример #11
0
void
GetTime (results_fft_t *input, long long int *T2,
	 int *correctOut, double *goodness, double *goodness2,
	 double *goodness3, int *zigazagaOut, int *nzeros)
{
#ifdef TRACE_MODE
  Extrae_user_function (1);
#endif

  double p, f, p1, p2, f1, f2, maxp, maxf=0, maxp2, maxf2=0, minp, pant, fant,
    *max_, *max2;
  long long int t, i, j;
  int correct, zigazaga;
  int N = input->N;

  maxp = 0;
  maxp2 = 0;
  minp = 10000000000.0;
  correct = 1;
  max_ = (double *) malloc (sizeof (double) * N);

  //i=0;
  //---> Freqx2.txt ---> fprintf(gp, "%lf %lf\n", 1.0*i*freq, conj[i]);

  f2 = 0;
  p2 = input->conj[0];

  i = 1;
  while ((input->conj[i] == p2) && (i < N / 2 + 3))
    {
      i++;
    }

  fant = input->freq[i];
  pant = input->conj[i];

  p1 = pant;
  f1 = fant;

  /* Provar d'inicialitzar les variables? */

  max2 = max_;

  for (j = i + 1; j < N / 2 + 3; j++)
    {
      f = input->freq[j];
      p = input->conj[j];

      if (p1 != p)
	{
	  if (p2 < p1 && p1 > p)
	    {
	      *max_ = f1;
	      max_++;
	      if (p1 > maxp)
		{
		  maxp = p1;
		  maxf = f1;
		}
	      else if (p1 > maxp2 && p1 < maxp)
		{
		  maxp2 = p1;
		  maxf2 = f1;
		}
	      if (p1 < minp)
		{
		  minp = p1;
		}
	    }

	  p2 = p1;
	  f2 = f1;
	  p1 = p;
	  f1 = f;
	}

    }

  *max_ = -1.0;
  max_ = max2;

  //printf("Period=%lf ms\n", maxf/1000000);

  if ((maxp2 / maxp < 0.9) || (MIN (maxf2, maxf) / MAX (maxf2, maxf) < 0.9)
      || (minp / maxp > 0.99))
    {
      //printf("Warning!!!! -----> Two similar periods\n");
      correct = 0;
    }

  j = 2;
  zigazaga = 1;
  t = maxf;
  i = 0;

#ifdef DEBUG_MODE
  FILE *fDB1;
  fDB1 = fopen ("gettime_output.txt", "a+");
  if (fDB1 == NULL)
    {
      printf ("\nDebug: Can't open file output.txt !!!\n\n");
      exit (-1);
    }
#endif

  while ((i < N) && (j < 5) && (zigazaga == 1))
    {
      f = input->freq[i];
      p = input->conj[i];
#ifdef DEBUG_MODE
      fprintf (fDB1, "%lf %lf\n", 1.0 * j * t, f);
#endif
      if ( /*0.95*f < j*t & j*t < 1.05*f */ f == j * t)
	{
#ifdef DEBUG_MODE
	  fprintf (fDB1, "%lf\n", *max_);
#endif
	  while ((*max_ < f) && (*max_ != -1))
	    {
	      max_++;
	    }

	  if ((0.95 * f < *max_) && (*max_ < 1.05 * f))
	    {
#ifdef DEBUG_MODE
	      fprintf (fDB1, "%lf %lf %lf %lf\n", maxp, maxf, p, f);
#endif

	      j++;
	    }
	  else
	    {
	      zigazaga = 0;
	    }
	}
      i++;
    }

  if (j < 5)
    {
      zigazaga = 0;
    }


  if ((maxf2 / maxf <= 2.05 && maxf2 / maxf >= 1.95)
      || (maxf2 / maxf <= 3.05 && maxf2 / maxf >= 2.95))
    {
      zigazaga = 1;
    }

  //Tcorrect 
  *T2 = t;
  *correctOut = correct;
  *goodness = maxp2 / maxp;
  *goodness2 = maxf2 / maxf;
  *goodness3 = minp / maxp;
  *zigazagaOut = zigazaga;
  *nzeros = j;

#ifdef DEBUG_MODE
  fclose (fDB1);

  fDB1 = fopen ("gettime_Tcorrect", "w");
  if (fDB1 == NULL)
    {
      printf ("\nDebug: Can't open file Tcorrect !!!\n\n");
      exit (-1);
    }
  fprintf (fDB1, "%lld %d %lf %lf %lf %d %lld\n", t, correct, maxp2 / maxp,
	   maxf2 / maxf, minp / maxp, zigazaga, j);
  fclose (fDB1);
#endif

  //free(max_);

#ifdef TRACE_MODE
  Extrae_user_function (0);
#endif

}
Пример #12
0
void Generate_Running_Signals (char *input_trace, char *filtered_trace, long long int min_time, signal_t **signal_in_running_out, char *dbg_file_in_running, signal_t **signal_dur_running_out, char *dbg_file_dur_running)
{
  int i    = 0;
  semantic_t *bursts_in_running  = NULL;
  semantic_t *bursts_dur_running = NULL;
  int num_bursts        = 0;
  int build_in_running  = (signal_in_running_out  != NULL);
  int build_dur_running = (signal_dur_running_out != NULL);

#ifdef TRACE_MODE
  Extrae_user_function (1);
#endif

  fprintf(stdout, "Generating Running signals... \n");


  Trace_Filter_States(input_trace, filtered_trace, min_time);

  /* Load the trace and parse bursts */
  num_bursts = ParseRunningBurstsFromTrace( ( min_time >= 0 ? filtered_trace : input_trace ), &bursts_in_running, &bursts_dur_running);

  /* Generating signals */
  signal_t *signal_in_running  = NULL;
  signal_t *signal_dur_running = NULL;

  /* In running signal */
  if (build_in_running)
  {
    signal_in_running  = Spectral_AllocateSignal( num_bursts );

    if (bursts_in_running[1].time - bursts_in_running[0].time > 0)
    {
      SIGNAL_ADD_POINT_3( signal_in_running,
        bursts_in_running[0].time,
        bursts_in_running[1].time - bursts_in_running[0].time,
        bursts_in_running[0].value);
    }

    for (i = 1; i < num_bursts - 2; i++)
    {
      bursts_in_running[i].value = bursts_in_running[i].value + bursts_in_running[i - 1].value;
      if (bursts_in_running[i + 1].time - bursts_in_running[i].time > 0)
      {
        SIGNAL_ADD_POINT_3( signal_in_running,
          bursts_in_running[i].time,
          bursts_in_running[i + 1].time - bursts_in_running[i].time,
          bursts_in_running[i].value);
      }
    }
  }

  /* Duration of running bursts signal */
  if (build_dur_running)
  {
    signal_dur_running = Spectral_AllocateSignal( num_bursts );

    if (bursts_dur_running[1].time - bursts_dur_running[0].time > 0)
    {
      SIGNAL_ADD_POINT_3( signal_dur_running,
        bursts_dur_running[0].time,
        bursts_dur_running[1].time - bursts_dur_running[0].time,
        (1.0 * bursts_dur_running[0].value) / 1000000.0
      );
    }

    for (i = 1; i < num_bursts - 2; i++)
    {
      bursts_dur_running[i].value = bursts_dur_running[i].value + bursts_dur_running[i - 1].value;
      if (bursts_dur_running[i + 1].time - bursts_dur_running[i].time > 0)
      {
        SIGNAL_ADD_POINT_3( signal_dur_running,
          bursts_dur_running[i].time,
          bursts_dur_running[i + 1].time - bursts_dur_running[i].time,
          (1.0 * bursts_dur_running[i].value) / 1000000.0
        );
      }
    }
  }

  free (bursts_in_running);
  free (bursts_dur_running);

#if defined(DEBUG_MODE)
  if (build_in_running)  Spectral_DumpSignal(signal_in_running,  dbg_file_in_running);
  if (build_dur_running) Spectral_DumpSignal(signal_dur_running, dbg_file_dur_running);
#endif

#ifdef TRACE_MODE
  Extrae_user_function (0);
#endif

  *signal_in_running_out  = signal_in_running;
  *signal_dur_running_out = signal_dur_running;
}
Пример #13
0
void Crosscorrelation(signal_t *signal1, signal_t *signal2, char *dbg_file, int *x, double *y)
{
#ifdef TRACE_MODE
  Extrae_user_function (1);
#endif

  fftw_complex *in=NULL, *out=NULL, *in2=NULL, *out2=NULL, *product=NULL;
  fftw_plan p, p2, p3;
  int N=0, i=0, j=0, N1=0, N2=0;
  double *conj1=NULL, *conj2=NULL, max=0;

#ifdef DEBUG_MODE
  FILE *fd;
  fd = fopen (dbg_file, "w");
  if (fd == NULL)
  {
    fprintf (stderr, "\nDebug: Can't open file %s!\n", dbg_file);
    perror("fopen: ");
    exit (-1);
  }
#endif

  N1 = SIGNAL_SIZE(signal1);
  N2 = SIGNAL_SIZE(signal2);

  N = MAX(N1, N2);

  in=fftw_malloc(sizeof(fftw_complex)*N);
  out=fftw_malloc(sizeof(fftw_complex)*N);
  in2=fftw_malloc(sizeof(fftw_complex)*N);
  out2=fftw_malloc(sizeof(fftw_complex)*N);
  product=fftw_malloc(sizeof(fftw_complex)*N);
  conj1=(double *)malloc(sizeof(double)*N);
  conj2=(double *)malloc(sizeof(double)*N);

  bzero(in, sizeof(fftw_complex)*N);
  bzero(out, sizeof(fftw_complex)*N);
  bzero(in2, sizeof(fftw_complex)*N);
  bzero(out2, sizeof(fftw_complex)*N);
  bzero(conj1, sizeof(double)*N);
  bzero(conj2, sizeof(double)*N);

  p=fftw_plan_dft_1d(N, in, out, -1, FFTW_ESTIMATE);
  p2=fftw_plan_dft_1d(N, in2, out2, -1, FFTW_ESTIMATE);

  for(i=0; i<N1; i++) {
    in[i] = signal1->data[i].value;
  }

  for(i=0; i<N2; i++) {
    in2[i] = signal2->data[i].value;
  }

  fftw_execute(p); fftw_execute(p2);


  for(i=0; i<N; i++)  {
          product[i]=out[i]*conj(out2[i]);
//          product2[i]=out2[i]*conj(out[i]);
   }

  p3=fftw_plan_dft_1d(N, product, out, 1, FFTW_ESTIMATE);
  fftw_execute(p3);
//  p4=fftw_plan_dft_1d(N, product2, out2, 1, FFTW_ESTIMATE);
//  fftw_execute(p4);

/*
 *   for(i=0; i<N; i++)  {
 *        fprintf(stderr, "product_out1[%d]=%lf product_out2[%d]=%lf (equal? %d)\n",
 *                i, cabs(out[i]), i, cabs(out2[i]), ( cabs(out[i]) == cabs(out2[i]) ));
 *                  }
 *                  */
  max = 0; j = 0;

  //ULL!! N/p on p nombre d'iteracions, en aquest cas 2

  for(i=0; i<N; i++) {
        conj1[i]=(double)(pow(cabs(out[i]),2)/pow(N,3));

        if(conj1[i]>max) {
                 max=conj1[i];
                 j=i;
        }
  }

#ifdef DEBUG_MODE
  fprintf (fd, "%d %lf\n", j, max);

  for (i = 0; i < N; i++)
    {
      fprintf (fd, "%d %lf\n", i, conj1[i]);
    }
#endif

 
  fftw_destroy_plan (p);
  fftw_destroy_plan (p2);
  fftw_destroy_plan (p3);

  free(in); free(out); free(in2); free(out2); free(product); free(conj1); free(conj2);

#ifdef DEBUG_MODE
  fclose (fd);
#endif

  *x = j;
  *y = max;

#ifdef TRACE_MODE
  Extrae_user_function (0);
#endif

}