Ejemplo n.º 1
0
int
main(void)
{
  int i;
  __complex__ double result, array[n];
  int lresult;

  /* '+' reductions.  */
#pragma acc parallel
#pragma acc loop gang worker vector reduction (+:result)
  for (i = 0; i < n; i++)
    result += array[i];

  /* '*' reductions.  */
#pragma acc parallel
#pragma acc loop gang worker vector reduction (*:result)
  for (i = 0; i < n; i++)
    result *= array[i];

  /* '&&' reductions.  */
#pragma acc parallel
#pragma acc loop gang worker vector reduction (&&:lresult)
  for (i = 0; i < n; i++)
    lresult = lresult && (__real__(result) > __real__(array[i]));

  /* '||' reductions.  */
#pragma acc parallel
#pragma acc loop gang worker vector reduction (||:lresult)
  for (i = 0; i < n; i++)
    lresult = lresult || (__real__(result) > __real__(array[i]));

  return 0;
}
Ejemplo n.º 2
0
/*
 * This routine calculates the center of mass of B2, in order to keep 
 * concentrations of magnetic field centered in the domain.
 */
displacement displacementByCenter()
{
    int i;
    displacement ret;
    complex PRECISION dkz;
    complex PRECISION dkx;
    
    complex PRECISION * data = B->vec->y->spectral;
    PRECISION mean = 0;
    PRECISION weightedMeanX = 0;
    PRECISION weightedMeanZ = 0;
    
    //Only one processor has the data to find the z center of mass, as it only
    //uses the mean values of x
    if(my_kx->min == 0)
    {
        mean = __real__(data[0]);
		weightedMeanZ = zmx/2.*mean;
        for(i = 1; i < ndkz; i++)
        {
            dkz = dzFactor(i);
            weightedMeanZ += __real__(data[i] / dkz);
        }
    }
    
    //Everyone shares in doing part of the x center mass
    if(vrank == 0)
	{
		weightedMeanX = xmx/2.*mean;
    	for(i = 1; i < my_kx->width; i++)
    	{
    	    dkx = dxFactor(i);
    	    weightedMeanX += 2*__real__(data[ndkz*i] / dkx);
   		}
	}
	else
	{
    	for(i = 0; i < my_kx->width; i++)
    	{
    	    dkx = dxFactor(i);
    	    weightedMeanX += 2*__real__(data[ndkz*i] / dkx);
   		}
    }
    //Root need all the info for the scattered sum
    if(vrank == 0)
    {
        MPI_Reduce(MPI_IN_PLACE, &weightedMeanX, 1, MPI_PRECISION, MPI_SUM, 0, vcomm);
        ret.dx = (weightedMeanX/mean) - xmx/2.;
        ret.dy = 0;
        ret.dz = (weightedMeanZ/mean) - zmx/2.;
    }   
    else
        MPI_Reduce(&weightedMeanX, 0, 1, MPI_PRECISION, MPI_SUM, 0, vcomm);
        
    MPI_Bcast(&ret, sizeof(displacement), MPI_BYTE, 0, vcomm);
    
    return ret;
}
Ejemplo n.º 3
0
int
main(void)
{
  const int n = 1000;
  int i;
  __complex__ double result, array[n];
  int lresult;

  /* '+' reductions.  */
#pragma acc parallel vector_length (vl)
#pragma acc loop reduction (+:result)
  for (i = 0; i < n; i++)
    result += array[i];

  /* Needs support for complex multiplication.  */

//   /* '*' reductions.  */
// #pragma acc parallel vector_length (vl)
// #pragma acc loop reduction (*:result)
//   for (i = 0; i < n; i++)
//     result *= array[i];
//
//   /* 'max' reductions.  */
// #pragma acc parallel vector_length (vl)
// #pragma acc loop reduction (+:result)
//   for (i = 0; i < n; i++)
//       result = result > array[i] ? result : array[i];
// 
//   /* 'min' reductions.  */
// #pragma acc parallel vector_length (vl)
// #pragma acc loop reduction (+:result)
//   for (i = 0; i < n; i++)
//       result = result < array[i] ? result : array[i];

  /* '&&' reductions.  */
#pragma acc parallel vector_length (vl)
#pragma acc loop reduction (&&:lresult)
  for (i = 0; i < n; i++)
    lresult = lresult && (__real__(result) > __real__(array[i]));

  /* '||' reductions.  */
#pragma acc parallel vector_length (vl)
#pragma acc loop reduction (||:lresult)
  for (i = 0; i < n; i++)
    lresult = lresult || (__real__(result) > __real__(array[i]));

  return 0;
}
Ejemplo n.º 4
0
int main() {
      float start[SIZE];
      int i;
      
      for (i=0; i<SIZE; i++) start[i] = (float)(i+1);
      
      printf("Starting out: ");
      for (i=0; i<SIZE; i++) printf(" %f ", (start[i])); printf("\n");

      _Complex float middle[SIZE/2 + 1];
      
      fftwf_plan plan = fftwf_plan_dft_r2c_1d(SIZE, start, (fftwf_complex*)middle, FFTW_ESTIMATE);
      fftwf_execute(plan);
      fftwf_destroy_plan(plan);

      printf("Done with forward transform: ");
      for (i=0; i< SIZE/2 + 1; i++) printf(" %g+%gi ", __real__ (middle[i]),  __imag__ (middle[i]));
      printf("\n");

      float end[SIZE];

      fftwf_plan plan2 = fftwf_plan_dft_c2r_1d(SIZE, (fftwf_complex*)middle, end, FFTW_ESTIMATE);
      fftwf_execute(plan2);
      fftwf_destroy_plan(plan2);

      printf("Done with reverse transform transform: ");
      for (i=0; i<SIZE; i++) printf(" %fi ", (end[i]));
      printf("\n");
}
Ejemplo n.º 5
0
inline Quad Arg( const Complex<Quad>& alphaPre )
{
    __complex128 alpha;
    __real__(alpha) = alphaPre.real();
    __imag__(alpha) = alphaPre.imag();

    return cargq(alpha);
}
Ejemplo n.º 6
0
static Obj COMPLEX_ROOTS (Obj self, Obj coeffs)
{
  Obj result;
  Int i, numroots, degree = LEN_PLIST(coeffs)-1;
  xcomplex op[degree+1], zero[degree];

  if (degree < 1)
    return Fail;

  for (i = 0; i <= degree; i++) {
    __real__(op)[degree-i] = VAL_FLOAT(ELM_PLIST(ELM_PLIST(coeffs,i+1),1));
    __imag__(op)[degree-i] = VAL_FLOAT(ELM_PLIST(ELM_PLIST(coeffs,i+1),2));
    if (isnan(__real__(op)[degree-i]) || isnan(__imag__(op)[degree-i]))
      return Fail;
  }

#ifdef DEBUG_COMPLEX_ROOTS
  fprintf(stderr,"coeffs");
  for (i = 0; i <= degree; i++)
    fprintf(stderr," %g+I*%g",(double)opr[i],(double)opi[i]);
   /* __asm__ __volatile__ ("int3"); */
  fprintf(stderr,"\n");
#endif

  numroots = cpoly (degree, op, zero);

  if (numroots == -1)
    return Fail;

#ifdef DEBUG_COMPLEX_ROOTS
  fprintf(stderr,"roots");
  for (i = 0; i < numroots; i++)
    fprintf(stderr," %g+I*%g",__real__(zero)[i],__imag__(zero)[i]);
  fprintf(stderr,"\n");
#endif

  result = ALLOC_PLIST(numroots);
  for (i = 1; i <= numroots; i++) {
    Obj t = ALLOC_PLIST(2);
    set_elm_plist(t,1, NEW_FLOAT(__real__(zero)[i-1]));
    set_elm_plist(t,2, NEW_FLOAT(__imag__(zero)[i-1]));
    set_elm_plist(result,i, t);
  }
  return result;
}
Ejemplo n.º 7
0
inline Complex<Quad> Asin( const Complex<Quad>& alphaPre )
{
    __complex128 alpha;
    __real__(alpha) = alphaPre.real();
    __imag__(alpha) = alphaPre.imag();
    
    __complex128 asinAlpha = casinq(alpha);
    return Complex<Quad>(crealq(asinAlpha),cimagq(asinAlpha));
}
Ejemplo n.º 8
0
inline Complex<Quad> Atanh( const Complex<Quad>& alphaPre )
{
    __complex128 alpha;
    __real__(alpha) = alphaPre.real();
    __imag__(alpha) = alphaPre.imag();
    
    __complex128 atanhAlpha = catanhq(alpha);
    return Complex<Quad>(crealq(atanhAlpha),cimagq(atanhAlpha));
}
static void
sse2_test (void)
{
  _Complex128 a = 1.3q + 3.4qi, b = 5.6q + 7.8qi, c;

  c = foo (a, b);
  if (__real__(c) == 0.0q || __imag__ (c) == 0.0q)
    abort ();
}
Ejemplo n.º 10
0
inline Complex<Quad> Cos( const Complex<Quad>& alphaPre )
{
    __complex128 alpha;
    __real__(alpha) = alphaPre.real();
    __imag__(alpha) = alphaPre.imag();
    
    __complex128 cosAlpha = ccosq(alpha);
    return Complex<Quad>(crealq(cosAlpha),cimagq(cosAlpha));
}
Ejemplo n.º 11
0
inline Complex<Quad> Sqrt( const Complex<Quad>& alphaPre )
{ 
    __complex128 alpha;
    __real__(alpha) = alphaPre.real();
    __imag__(alpha) = alphaPre.imag();

    __complex128 sqrtAlpha = csqrtq(alpha);
    return Complex<Quad>(crealq(sqrtAlpha),cimagq(sqrtAlpha));
}
Ejemplo n.º 12
0
inline Complex<Quad> Log( const Complex<Quad>& alphaPre )
{
    __complex128 alpha;
    __real__(alpha) = alphaPre.real();
    __imag__(alpha) = alphaPre.imag();

    __complex128 logAlpha = clogq(alpha);
    return Complex<Quad>(crealq(logAlpha),cimagq(logAlpha));
}
Ejemplo n.º 13
0
Archivo: complex.c Proyecto: aaasz/SHP
void f1(int * p) {
  
  // This branch should be infeasible
  // because __imag__ p is 0.
  if (!p && __imag__ (intptr_t) p)
    *p = 1; // no-warning

  // If p != 0 then this branch is feasible; otherwise it is not.
  if (__real__ (intptr_t) p)
    *p = 1; // no-warning
    
  *p = 2; // expected-warning{{Dereference of null pointer}}
}
Ejemplo n.º 14
0
Archivo: dft.c Proyecto: wicker/dft
// some examples of working with complex.h library
void complex_demo() {

  int i;
  double complex a,b,c;

  printf("---------------------------------------\n");
  printf("some examples of working with complex.h\n");
  printf("---------------------------------------\n");

  // access real and imaginary parts with these operators
  __real__ a = 1.4f;
  __imag__ a = 2.0f;

  // or set entire number in this form
  c = 1.0 + 3.0I;

  // otherwise, they work like regular variables
  b = a;
  double complex x[3] = {a,b,c};

  // access the contents with the same operators
  printf("a = %.2f %.2fi\n",__real__(a), __imag__(a));
  printf("b = %.2f %.2fi\n",__real__(b), __imag__(b));
  printf("c = %.2f %.2fi\n",__real__(c), __imag__(c));

  for (i = 0; i < 3; i++) {
    printf("x[%d] = %.2f %.2fi\n",i,__real__(x[i]),__imag__(x[i]));
  }

  // add complex numbers
  c = a + b;
  printf("a + b = %.2f + %.2fi\n",__real__(c),__imag__(c));
  
  // multiply complex numbers
  c = a * b;
  printf("a * b = %.2f + %.2fi\n",__real__(c),__imag__(c));

  // print out pi
  printf("pi = %.10f\n",M_PI);
  printf("---------------------------------------\n");

}
Ejemplo n.º 15
0
// ?: in constant expressions.
int g17[(3?:1) - 2]; 

EVAL_EXPR(18, ((int)((void*)10 + 10)) == 20 ? 1 : -1);

struct s {
  int a[(int)-1.0f]; // expected-error {{array size is negative}}
};

EVAL_EXPR(19, ((int)&*(char*)10 == 10 ? 1 : -1));

EVAL_EXPR(20, __builtin_constant_p(*((int*) 10), -1, 1));

EVAL_EXPR(21, (__imag__ 2i) == 2 ? 1 : -1);

EVAL_EXPR(22, (__real__ (2i+3)) == 3 ? 1 : -1);

int g23[(int)(1.0 / 1.0)] = { 1 };
int g24[(int)(1.0 / 1.0)] = { 1 , 2 }; // expected-warning {{excess elements in array initializer}}
int g25[(int)(1.0 + 1.0)], g26 = sizeof(g25);

EVAL_EXPR(26, (_Complex double)0 ? -1 : 1)
EVAL_EXPR(27, (_Complex int)0 ? -1 : 1)
EVAL_EXPR(28, (_Complex double)1 ? 1 : -1)
EVAL_EXPR(29, (_Complex int)1 ? 1 : -1)


// PR4027 + rdar://6808859
struct a { int x, y };
static struct a V2 = (struct a)(struct a){ 1, 2};
static const struct a V1 = (struct a){ 1, 2};
Ejemplo n.º 16
0
static xreal xnorm(xcomplex z) { return __real__(z)*__real(z)+__imag__(z)*__imag__(z);}
Ejemplo n.º 17
0
short bar_short(void) {
  return __real__(foo_short(2 - 3i));
}
Ejemplo n.º 18
0
int bar_int(void) {
  return __real__(foo_int(2 - 3i));
}
Ejemplo n.º 19
0
long long bar_long_long(void) {
  return __real__(foo_long_long(2LL - 3LLi));
}
Ejemplo n.º 20
0
signed char bar_char(void) {
  return __real__(foo_char(2 - 3i));
}
Ejemplo n.º 21
0
static void xscalbln (xcomplex *z, int e) {
  __real__(*z) = scalbln(__real__(*z), e);
  __imag__(*z) = scalbln(__imag__(*z), e);
}
Ejemplo n.º 22
0
int n;

void
f (void)
{
  int i = 0;
  int a[n]; /* { dg-error "ISO C90 forbids variable length array" } */
  enum e1 {
    /* Integer constant expressions may not contain statement
       expressions (not a permitted operand).  */
    E1 = (1 ? 0 : ({ 0; })), /* { dg-error "constant expression" } */
    /* { dg-error "ISO C forbids braced-groups" "ISO" { target *-*-* } 16 } */
    /* Real and imaginary parts act like other arithmetic
       operators.  */
    E2 = __real__ (1 ? 0 : i++), /* { dg-error "constant expression" } */
    E3 = __real__ 0,
    E4 = __imag__ (1 ? 0 : i++), /* { dg-error "constant" } */
    E5 = __imag__ 0,
    /* __alignof__ always constant.  */
    E6 = __alignof__ (int[n]), /* { dg-error "ISO C90 forbids variable length array" } */
    E7 = __alignof__ (a), /* { dg-error "__alignof__ \\(expression\\)" } */
    /* __extension__ ignored for constant expression purposes.  */
    E8 = __extension__ (1 ? 0 : i++), /* { dg-error "constant expression" } */
    E9 = __extension__ 0,
    /* Conditional expressions with omitted arguments act like the
       standard type.  */ 
    E10 = (1 ? : i++), /* { dg-error "constant expression" } */
    /* { dg-error "ISO C forbids omitting" "ISO" { target *-*-* } 32 } */
    E11 = (1 ? : 0) /* { dg-error "ISO C forbids omitting" } */
  };