예제 #1
0
void PLA_clu( int *m, int *n, PLA_COMPLEX *a, int *lda, int *pivot )
{
  int
    j, index, m_min_j_p_1, m_min_j, n_min_j, i_one = 1, i_four = 4;
  PLA_COMPLEX
    ajj_inv, minus_one = {-1.0, 0.0};

  for ( j=1; j<=min( *n, *m ); j++ ){ 
    m_min_j_p_1 = *m-j+1;
    m_min_j = *m-j;
    n_min_j = *n-j;

    index = PLA_icamax( &m_min_j_p_1, &A(j,j,*lda), &i_one );

    Piv(j) = index-1;

    PLA_cswap( n, &A(j,1,*lda), lda, &A(j+index-1,1,*lda), lda ); 

    ajj_inv = complex_inverse( A(j,j,*lda) );

    PLA_cscal( &m_min_j, &ajj_inv, &A(j+1,j,*lda), &i_one );
    
    PLA_cger( &m_min_j, &n_min_j, &minus_one, &A(j+1,j,*lda), &i_one,
	       &A(j,j+1,*lda), lda, &A(j+1,j+1,*lda ), lda );
  }
}
예제 #2
0
/* poly: pointer to coefficients array of size degree + 1.
 * results: pointer to results output array of size degree.
 */
int solve_poly(int degree, const complex_t* poly, complex_t* results) {
    complex_t normalized_poly[MAX_DEGREE + 1];
    int i;
    const complex_t a = poly[degree];
    if (complex_eq(a, complex_from_real(0.0)))
        return solve_poly(degree - 1, poly, results);
    if (degree > MAX_DEGREE)
        return -1;
    if (degree > 2 && stableness_score(poly[degree], poly[degree - 1]) > stableness_score(poly[0], poly[1])) {
        complex_t rev_poly[MAX_DEGREE + 1];
        int num_results;
        for (i = 0; i <= degree; ++i)
            rev_poly[i] = poly[degree - i];
        num_results = solve_poly(degree, rev_poly, results);
        for (i = 0; i < num_results; ++i)
            results[i] = complex_inverse(results[i]);
        return num_results;
    }
    for (i = 0; i < degree; ++i)
        normalized_poly[i] = complex_div(poly[i], a);
    normalized_poly[degree] = complex_from_real(1.0);
    return solve_normalized_poly(degree, normalized_poly, results);
}
예제 #3
0
static complex_t complex_div(complex_t a, complex_t b) {
    return complex_mult(a, complex_inverse(b));
}
예제 #4
0
int main()
{
	srand (time(NULL));
	int i,j;
	double sigma;


	unsigned int *X = random_X (NUM_BLOCKS*NUM_CARRIERS);

	complex_table *IP_SIG = (complex_table *) malloc (sizeof(complex_table));
	complex_table_init (IP_SIG,NUM_CARRIERS,NUM_BLOCKS,"IP_SIG");
	
    create_IP_BLOCKS (IP_SIG,X,ALPHA,PI);
	
	

	complex_table *CARRIERS = (complex_table *) malloc (sizeof(complex_table));
	complex_table_init (CARRIERS,NUM_BLOCKS,NUM_CARRIERS,"CARRIERS");

	create_CARRIERS (CARRIERS);
	print_table (CARRIERS);
	


	complex_table *CARRIERST = (complex_table *) malloc (sizeof(complex_table));
	complex_table_init (CARRIERST,NUM_CARRIERS,NUM_BLOCKS,"CARRIERST");

	TRANSPOSE (CARRIERS,CARRIERST);
	//print_table (CARRIERST);
	
	
	//printf("\nrows : %d\tcolumns : %d",CARRIERST->rows,CARRIERST->columns);
	
	
	complex_table *CORRELATION = (complex_table *) malloc (sizeof(complex_table));
	complex_table_init (CORRELATION,CARRIERST->columns,CARRIERST->columns,"CORRELATION");

	CORRELATET (CARRIERST,CORRELATION);
	//print_table (CORRELATION);
	

	complex_table *MODI = (complex_table *) malloc (sizeof(complex_table));
	complex_table_init (MODI,NUM_BLOCKS,NUM_BLOCKS,"MODI");

	modulate (MODI,CARRIERS,IP_SIG);
	sigma = complex_sigma (MODI); 

	complex_table *AWGN = (complex_table *) malloc (sizeof(complex_table));
	complex_table_init (AWGN,NUM_BLOCKS*OVERSAMPLING,NUM_BLOCKS,"AWGN");
	create_noise (AWGN,Eb,sigma,OVERSAMPLING);
	
	complex_table *NOISY = (complex_table *) malloc (sizeof(complex_table));
	complex_table_init (NOISY,NUM_BLOCKS,NUM_BLOCKS*OVERSAMPLING,"NOISY");

	//	printf("\nhere\n");
	//	create_noisy (NOISY,AWGN,MODI);

	complex_addition (NOISY,AWGN,MODI);


	complex_table *INVERSE = (complex_table *) malloc (sizeof(complex_table));
	complex_table_init (INVERSE,CORRELATION->rows,CORRELATION->columns,"INVERSE");

	complex_idenity_init (INVERSE);
	
	
	complex_inverse (CORRELATION,INVERSE);
	
	//print_table (CORRELATION);

	

	
	
	/*for (i=0;i<NUM_BLOCKS;i++) {
		o = column_from_table (IP_SIG,i);
		complex_Ax (CARRIERS,SYMBOL,IP_BLOCK);
		list_to_table (MODI,SYMBOL,i);	
	}*/
	

	//inverse (CORRELATION,INVERSE);
		
	
	// send result to table :end of loop calculate sigma
	
	
	/*complex_list *IP_BLOCK = (complex_list *) malloc (sizeof(complex_list));
	complex_list_init (IP_BLOCK);*/
		
	
	//	printf("\t%d\t%d\t:\t%.5lf\t%.5lf\t\n",mynode->col,mynode->row,mynode->real,mynode->imag);

	//complex_table *SYMBOL_MODI = create_SYMBOL_MODI (CARRIERS,IP_BLOCK);

	//complex_list *SEFDM_SYMBOL = (complex_list *) malloc (sizeof(complex_list));
	//A_complex_x (CARRIERS,SEFDM_SYMBOL,IP_BLOCK);

	//double SEFDM_SQUARED = complex


	
	printf("\n\n");
	printf("NUM_CARRIERS :\t\t%d \n",NUM_CARRIERS);
	printf("MODULATION_LEVEL :\t%d \n",MODULATION_LEVEL);
	printf("NUM_BLOCKS :\t\t%d \n",NUM_BLOCKS);
	printf("ALPHA :\t\t\t%d \n",ALPHA);
	printf("OVERSAMPLING :\t\t%d \n",OVERSAMPLING);
	printf("Eb :\t\t\t%d \n",Eb);
	
	//print_table (CARRIERS);
	//print_table (CORRELATION);
	
	/*
	print_table (IP_SIG);
	print_table (CARRIERS);
	print_table (CORRELATION);
	print_table (MODI);
	print_table (AWGN);
	print_table (NOISY);
	print_table (INVERSE);
	*/
	
	return 0;
}
int PLA_Local_inv_scal(PLA_Obj alpha, PLA_Obj x)
{
   int value = PLA_SUCCESS;
   int original_error = 0;
   int error_value, i;
   int local_length_x, local_width_x, ld_x;
   int ld_x_buf, stride_x, orientation_x;
   MPI_Datatype datatype_x;
   void *x_buffer, *x_buffer_cur, *alpha_buffer;

   /* Perform parameter checking */

   if ( PLA_ERROR_CHECKING )    /* Perform parameter and error checking */
     value = PLA_Local_inv_scal_enter( alpha, x );

   PLA_Obj_local_length(x, &local_length_x);
   PLA_Obj_local_width (x, &local_width_x);

   PLA_Obj_datatype(x, &datatype_x);

   PLA_Obj_local_ldim(x, &ld_x);
   PLA_Obj_local_stride(x, &stride_x);

   PLA_Obj_project_onto(x, &orientation_x);

   PLA_Obj_local_buffer(x, &x_buffer);
   x_buffer_cur = x_buffer;

   PLA_Obj_local_buffer(alpha, &alpha_buffer);

   if(local_length_x * local_width_x > 0)
   {
      if( PLA_PROJ_ONTO_ROW == orientation_x )
      {
	if (MPI_DOUBLE == datatype_x){
	  double alpha_inv;

	  alpha_inv = 1.0/(*((double *) alpha_buffer));
	  for(i = 0; i < local_length_x; i++)
            {
	      PLA_dscal(&local_width_x, &alpha_inv, (double*)x_buffer_cur, &ld_x);
	      x_buffer_cur = (void*)(((double*)x_buffer_cur)+stride_x);
            }
	}
	else if(MPI_FLOAT == datatype_x){
	  float alpha_inv;

	  alpha_inv = 1.0/(*((float *) alpha_buffer));
	  for(i = 0; i < local_length_x; i++)
            {
	      PLA_sscal(&local_width_x, &alpha_inv, (float*)x_buffer_cur, &ld_x);
	      x_buffer_cur = (void*)(((float*)x_buffer_cur)+stride_x);
            }
	}
	else if(MPI_COMPLEX == datatype_x){
	  PLA_COMPLEX alpha_inverse;

	  alpha_inverse = complex_inverse( *( PLA_COMPLEX * ) alpha_buffer );

	  for(i = 0; i < local_length_x; i++)
            {
	      PLA_cscal(&local_width_x, &alpha_inverse,
			(PLA_COMPLEX*)x_buffer_cur, &ld_x);
	      x_buffer_cur = (void*)(((PLA_COMPLEX*)x_buffer_cur)+stride_x);
            }
	}
	else if(MPI_DOUBLE_COMPLEX == datatype_x){
	  PLA_DOUBLE_COMPLEX alpha_inverse;

	  alpha_inverse = double_complex_inverse( 
			   *( PLA_DOUBLE_COMPLEX * ) alpha_buffer );

	  for(i = 0; i < local_length_x; i++)
            {
	      PLA_zscal(&local_width_x, &alpha_inverse, 
			(PLA_DOUBLE_COMPLEX*)x_buffer_cur, &ld_x);
	      x_buffer_cur = (void*)(((PLA_DOUBLE_COMPLEX*)x_buffer_cur)+stride_x);
            }
	}
      }
      else
      {
	if (MPI_DOUBLE == datatype_x){
	  double alpha_inv;

	  alpha_inv = 1.0/(*((double *) alpha_buffer));
	  for(i = 0; i < local_width_x; i++)
            {
	      PLA_dscal(&local_length_x, &alpha_inv,
			(double*)x_buffer_cur, &stride_x);
	      x_buffer_cur = (void*)(((double*)x_buffer_cur)+ld_x);
            }
	}
	else if(MPI_FLOAT == datatype_x){
	  float alpha_inv;

	  alpha_inv = 1.0/(*((float *) alpha_buffer));
	  for(i = 0; i < local_width_x; i++)
            {
	      PLA_sscal(&local_length_x, &alpha_inv,
			(float*)x_buffer_cur, &stride_x);
	      x_buffer_cur = (void*)(((float*)x_buffer_cur)+ld_x);
            }
	}
	else if(MPI_COMPLEX == datatype_x){
	  PLA_COMPLEX alpha_inverse;

	  alpha_inverse = complex_inverse( 
			   *( PLA_COMPLEX * ) alpha_buffer );

	  for(i = 0; i < local_width_x; i++)
            {
	      PLA_cscal(&local_length_x, &alpha_inverse,
			(PLA_COMPLEX*)x_buffer_cur, &stride_x);
	      x_buffer_cur = (void*)(((PLA_COMPLEX*)x_buffer_cur)+ld_x); /*complex == 2 floats */
            }
	}
	else if(MPI_DOUBLE_COMPLEX == datatype_x){
	  PLA_DOUBLE_COMPLEX alpha_inverse;

	  alpha_inverse = double_complex_inverse( 
			   *( PLA_DOUBLE_COMPLEX * ) alpha_buffer );
	  for(i = 0; i < local_width_x; i++)
            {
	      PLA_zscal(&local_length_x, &alpha_inverse,
			(PLA_DOUBLE_COMPLEX*)x_buffer_cur, &stride_x);
	      x_buffer_cur =(void*)(((PLA_DOUBLE_COMPLEX*)x_buffer_cur)+ld_x);
	    }
	}
      }
   }

   if ( PLA_ERROR_CHECKING )    /* Perform parameter and error checking */
     value = PLA_Local_inv_scal_exit( alpha, x );

   return value;
}