Exemple #1
0
int main()
{
    CArray array;
    array_initial(&array);
    
    array_recap(&array, 10);
    assert(array_capacity(&array) == 10);
    
    //////////////////////////////////////////////////////////////////////////
    for (int i = 0; i < 20; ++i)
    {
        array_append(&array, i);
    }
    assert(array_size(&array) == 20);
    
//    printarray(&array);
    
    for (int i = 0; i < array_size(&array); ++i)
    {
        assert(*array_at(&array, i) == i);
    }
    
    //////////////////////////////////////////////////////////////////////////
    CArray array2, array3;
    array_initial(&array2);
    array_initial(&array3);
    
    array_copy(&array, &array2);

    assert(array_compare(&array, &array2) == true);
    array_copy(&array, &array3);
    assert(array_compare(&array, &array3) == true);
//    printarray(&array2);
    
    //////////////////////////////////////////////////////////////////////////
    array_insert(&array2, 2, 3);
    assert(array_compare(&array, &array2) == false);
//    printarray(&array2);

    
    //////////////////////////////////////////////////////////////////////////
    *array_at(&array3, 2) = 5;
    assert(array_compare(&array, &array3) == false);
//    printarray(&array3);

    //////////////////////////////////////////////////////////////////////////
    array_destroy(&array);
    array_destroy(&array2);
    array_destroy(&array3);
    
    return 0;
}
Exemple #2
0
static int
ktest_equal_sequence_of_external_principal_identifier(
    krb5_external_principal_identifier **ref,
    krb5_external_principal_identifier **var)
{
    array_compare(ktest_equal_external_principal_identifier);
}
int array_compare(int **sample_list, int row_1, int row_2, int col, int col_max, int cluster){
  if(sample_list[row_1][col] == sample_list[row_2][col]) {
    if(col > 0){
      return array_compare(sample_list, row_1, row_2, col - 1, col_max, cluster);
    }
    else{
      sample_list[row_2][col_max] = cluster + 1;
      return 1;
    }
  }
  else{
    return 0;
  }
}
Exemple #4
0
/*******************************************************************************
** 函数名称:   zigbee_rcv_process
** 函数功能:   zigbee接收数据处理
** 入口参数:  
** 出口参数: 
** 备    注: 
*******************************************************************************/
void zigbee_rcv_process(void)
{
	if(packetReceived==TRUE){
		 packetReceived = FALSE;
		if(array_compare(&rxPacket[1],&Card_Cmd[0],9)){      //判断帧头
			if((array_compare(&rxPacket[10],&Card_Cmd[9],2)|| //判断是否自身编号或0xFFFF,井上呼叫
                (rxPacket[10]==0xFF)&&(rxPacket[11]==0xFF))){
				UpperCommander = TRUE;
              	return;
            }
            else if((rxPacket[10]==0xEE)&&(rxPacket[11]==0xEE)||
                    (rxPacket[10]==Card_Cmd[9])&&(rxPacket[11]==(Card_Cmd[10]&0x80))){
              	UpperCommander = FALSE;                         			//取消呼叫进入静默
              	return;
            }
            else if(0x40==(rxPacket[11]&0xE0)){		      		//日期设置命令,卡号高字节高3位为010表示日期命令,卡号低字节及卡号高字节低6位表示日期
                Factory_Date = (((rxPacket[11]&0x3F)<<8)|rxPacket[10]);//获得出厂日期
                WriteFactoryDateFlag = TRUE;
                return;
			}
		}
	}      
}
Exemple #5
0
/*******************************************************************************
** 函数名称:   Zigbee_Receive
** 函数功能:   zigbee接收处理函数,双向通讯
** 入口参数:  
** 出口参数:  
** 备    注: 
*******************************************************************************/
void Zigbee_Receive(void)
{
	ST_RadioSetChannel(Recieve_Channel);  
    ST_RadioInit(ST_RADIO_POWER_MODE_RX_ON);
		
	RX_Time = 0;
      while(RX_Time <=2200)                                   //接收4ms (5ms 2850个循环)
      {
        if(packetReceived==TRUE)
        {
          if(array_compare(&rxPacket[1],&Card_Cmd[0],9))      //判断帧头
          {
            if((array_compare(&rxPacket[10],&Card_Cmd[9],2)|| //判断是否自身编号或0xFFFF,井上呼叫
                (rxPacket[10]==0xFF)&&(rxPacket[11]==0xFF)))
            {
              UpperCommander = TRUE;
              break;
            }
            else if((rxPacket[10]==0xEE)&&(rxPacket[11]==0xEE)||
                    (rxPacket[10]==Card_Cmd[9])&&(rxPacket[11]==(Card_Cmd[10]&0x80)))
            {
              UpperCommander = FALSE;                         			//取消呼叫进入静默
              break;
            }
            else if(0x40==(rxPacket[11]&0xE0))		      		//日期设置命令,卡号高字节高2位为01表示日期命令,卡号低字节及卡号高字节低6位表示日期
            {
                Factory_Date = (((rxPacket[11]&0x3F)<<8)|rxPacket[10]);//获得出厂日期
                WriteFactoryDateFlag = TRUE;
                break;
            }
          }
          packetReceived = FALSE;
        }      
        RX_Time++;
      }
      packetReceived = FALSE;
}
int natrual_distribution(int **sample_list, int **natrual_distribution_index, int line_max, int col_max){
  int init_row = 0, row = 0, num = 0;
  int i = 0;
  for(init_row = 0; init_row < line_max; init_row++){
    if(sample_list[init_row][col_max] != 0){
      continue;
    }
    for(row = init_row; row < line_max; row++){
      num = num + array_compare(sample_list, init_row, row, col_max - 1, col_max, init_row);
    }
    natrual_distribution_index[i][0] = init_row;
    natrual_distribution_index[i][1] = num;
    i = i + 1;
    num = 0;
  }
  return i;
}
Exemple #7
0
inline void pwm_hunt_target() {
    uint8_t how_many = uart_icount();
    uint8_t current_index = uart_itail;
    if (how_many < TARGET_LENGTH) {
        return;   //abort if not enough data received
    }
    for (uint8_t i=0; i<=(how_many-TARGET_LENGTH); i++) {
        if (current_index >= MAX_IBUFFER_LEN) {
            current_index = 0;
        }
        build_dut(current_index);
        if (array_compare(trigger_target, trigger_compare) == true) {
            pwm_pulse(); //fire off the solenoid
            init_uart_ibuffer(); //flush buffer to prevent retriggering
        }
        current_index++;
    }
}
Exemple #8
0
int checkspecialrangesfast(const Encodedsequence *encseq)
{
  GtArray *rangesforward, *rangesbackward;
  bool haserr = false;
  Specialrangeiterator *sri;
  Sequencerange range;

  if (!hasspecialranges(encseq))
  {
    return 0;
  }
  rangesforward = gt_array_new(sizeof (Sequencerange));
  rangesbackward = gt_array_new(sizeof (Sequencerange));

  sri = newspecialrangeiterator(encseq,true);
  while (nextspecialrangeiterator(&range,sri))
  {
    gt_array_add(rangesforward,range);
  }
  freespecialrangeiterator(&sri);
  sri = newspecialrangeiterator(encseq,false);
  while (nextspecialrangeiterator(&range,sri))
  {
    gt_array_add(rangesbackward,range);
  }
  freespecialrangeiterator(&sri);
  gt_array_reverse(rangesbackward);
  if (!haserr)
  {
    if (array_compare(rangesforward,rangesbackward,
                      compareSequencerange) != 0)
    {
      exit(GT_EXIT_PROGRAMMING_ERROR);
    }
  }
  gt_array_delete(rangesforward);
  gt_array_delete(rangesbackward);
  return haserr ? - 1 : 0;
}
Exemple #9
0
int
ktest_equal_sequence_of_checksum(krb5_checksum **ref, krb5_checksum **var)
{
    array_compare(ktest_equal_checksum);
}
Exemple #10
0
int
ktest_equal_etype_info(krb5_etype_info_entry **ref, krb5_etype_info_entry **var)
{
    array_compare(ktest_equal_krb5_etype_info_entry);
}
Exemple #11
0
int
ktest_equal_sequence_of_principal(krb5_principal *ref, krb5_principal *var)
{
    array_compare(ktest_equal_principal_data);
}
Exemple #12
0
int
ktest_equal_sequence_of_cred_info(krb5_cred_info **ref, krb5_cred_info **var)
{
    array_compare(ktest_equal_cred_info);
}
Exemple #13
0
int
ktest_equal_sequence_of_ticket(krb5_ticket **ref, krb5_ticket **var)
{
    array_compare(ktest_equal_ticket);
}
Exemple #14
0
int
ktest_equal_last_req(krb5_last_req_entry **ref, krb5_last_req_entry **var)
{
    array_compare(ktest_equal_last_req_entry);
}
Exemple #15
0
int
ktest_equal_addresses(krb5_address **ref, krb5_address **var)
{
    array_compare(ktest_equal_address);
}
int main(int argc,char *argv[]){
  
  int comm_sz;
  int my_rank = 0;
  MPI_Status mystatus;
  
  int line_length = 0;
  int file_length = 0;
  int line = 0;
  int cols = 0;
  int i = 0, j = 0, k = 0;
  int position = 0;
  
  int single_argument_buffer[4] = {0};
  int size_argument_buffer = sizeof(int) * 4;
  int size_buffer_double = 0;
  int package_length = 0;


  MPI_Init(&argc, &argv);
  //MPI_Init(NULL,NULL);
  MPI_Comm_size(MPI_COMM_WORLD, &comm_sz);
  MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
  
  if(my_rank == 0){
    FILE *fp ,*wp;
    int **sample_list;
    double **angle_list;
    static int **natrual_distribution_index;
    
    fp = fopen(argv[1], "r");
    //fp = fopen("/home/dubc/SS_01/H_2-0.dat", "r");
    if (fp == NULL) {
      printf(" Do not exist\n");
      exit(1);
    }
    
    while(fgetc(fp) != '\n'){
      line_length = (int) ftell(fp) + 1;
    }
    fseek(fp, SEEK_SET, SEEK_END);
    file_length = (int) ftell(fp);
    rewind(fp);
    
    line = file_length/line_length;
    cols = line_length/WORD_LENGTH;
    
    sample_list =  (int **) malloc(sizeof(int *) * file_length/line_length);
    angle_list =  (double **) malloc(sizeof(double *) * file_length/line_length);
    
    for (j = 0; j < file_length/line_length; j++){
      sample_list[j] = (int *) malloc(sizeof(int) * (line_length/WORD_LENGTH + 1));
      for (i = 0; i < line_length/WORD_LENGTH + 1; i++){
        sample_list[j][i] = 0;
      }
    }
    
    for (j = 0; j < file_length/line_length; j++){
      angle_list[j] = (double *) malloc(sizeof(double) * (line_length/WORD_LENGTH + 1));
      for (i = 0; i < line_length/WORD_LENGTH + 1; i++){
        angle_list[j][i] = 0;
      }
    }
    
    natrual_distribution_index =  (int **) malloc(sizeof(int *) * file_length/line_length);
    for (j = 0; j < file_length/line_length; j++){
      natrual_distribution_index[j] = (int *) malloc(sizeof(int) * line_length/WORD_LENGTH);
      for (i = 0; i < line_length/WORD_LENGTH; i++){
        natrual_distribution_index[j][i] = 0;
      }
    }
    
    i = 0;
    int num_break = 0;
    double sample = 0;
    while( 1 ) {
      fscanf(fp, "%lf", &sample);
      if (ftell(fp) == file_length) {
        break;
      }
      if(sample == 360 || sample == -360){
        sample = 0;
      }
      sample_list[i][num_break] = (int) ((sample + 180) / (COUNT) + 0.5);
      angle_list[i][num_break] = sample;
      num_break = num_break + 1;
      if(num_break % (line_length / WORD_LENGTH) == 0){
        i = i + 1;
        num_break = 0;
      }
    }
    fclose(fp);
    printf("Reading Done! %d \n", i);
    
    //PACKAGE
    int package_length = line / (comm_sz - 1);
    size_buffer_double = sizeof(double) * cols * package_length ;
    double *line_buffer = NULL;
    
    line_buffer =  (double *) malloc(sizeof(double) * size_buffer_double);
    printf("%d %d %d %d \n", line, cols, package_length, comm_sz);
    MPI_Pack( &line, 1, MPI_INT, single_argument_buffer, size_argument_buffer, &position, MPI_COMM_WORLD );
    MPI_Pack( &cols, 1, MPI_INT, single_argument_buffer, size_argument_buffer, &position, MPI_COMM_WORLD );
    MPI_Pack( &package_length, 1, MPI_INT, single_argument_buffer, size_argument_buffer, &position, MPI_COMM_WORLD );
    MPI_Pack( &size_buffer_double , 1, MPI_INT, single_argument_buffer, size_argument_buffer, &position, MPI_COMM_WORLD );
    
    MPI_Bcast( single_argument_buffer, size_argument_buffer, MPI_PACKED, 0, MPI_COMM_WORLD);
    position = 0;
    
    for(i = 1; i < comm_sz; i++){
      for(j = ( i - 1 ) * package_length; j <  i * package_length; j++) {
        MPI_Pack( angle_list[j], cols, MPI_DOUBLE, line_buffer, size_buffer_double, &position, MPI_COMM_WORLD );
      }
      MPI_Send( line_buffer, size_buffer_double, MPI_PACKED, i, 0, MPI_COMM_WORLD );
      position = 0;
    }


//
    int line_left = line - (comm_sz - 1) * package_length;
    //printf("LEFT:%d \n", line_left);

    int **sample_list_left =  (int **) malloc(sizeof(int *) * line_left);
    for (j = 0; j < line_left; j++){
      sample_list_left[j] = (int *) malloc(sizeof(int) * (cols + 1));
      for (i = 0; i < cols + 1; i++){
        if( i != cols ){
          sample_list_left[j][i] = sample_list[j + (line - line_left)][i];
          //printf("K:%lf ", angle_list[j + (line - line_left)][i]);
        }
        else{
          sample_list_left[j][i] = 0;
        }
      }
      //printf("\n");
    }

    int **natrual_distribution_indexs_left = NULL;
    natrual_distribution_indexs_left =  (int **) malloc(sizeof(int *) * (line - line_left));
    for (j = 0; j < (line - line_left); j++){
      natrual_distribution_indexs_left[j] = (int *) malloc(sizeof(int) * 2);
      for (i = 0; i < 2; i++){
        natrual_distribution_indexs_left[j][i] = 0;
      }
    }
    if(line_left > 1 ){ 
      natrual_distribution(sample_list_left, natrual_distribution_indexs_left, 1, 0);
    }
    else{
      natrual_distribution_indexs_left[0][0] = line - line_left;
      natrual_distribution_indexs_left[0][1] = 0;
    }
//
    int ND_index = 0;
    int ND_index_sum = 0;
    int ND_I_size = 0;
    int *ND_I_line_buffer = NULL;
    int *ND_I_single_line = (int *) malloc(sizeof(int) * 2);
    int **ND_I_check = (int **) malloc(sizeof(int *) * line);
    for(i = 0; i < line; i++){
      ND_I_check[i] = (int *) malloc(sizeof(int) * 2);
      for(j = 0; j < 2; j++){
        ND_I_check[i][j] = 0;
      } 
    }

    for(i = 1; i < comm_sz; i++){
      MPI_Recv( &ND_index, 1, MPI_INT, i, 0, MPI_COMM_WORLD, &mystatus );
    //  printf("%d %d \n", i, ND_index);
      ND_I_size = sizeof(int) * 2 * ND_index;
      ND_I_line_buffer = (int *) malloc(sizeof(int) * ND_I_size);

      MPI_Recv( ND_I_line_buffer, ND_I_size, MPI_PACKED, i, 0, MPI_COMM_WORLD, &mystatus );
      position = 0;
      for(j = 0; j < ND_index; j++) {
        MPI_Unpack( ND_I_line_buffer, ND_I_size, &position, ND_I_single_line, 2, MPI_INT, MPI_COMM_WORLD );
        ND_I_check[j + ND_index_sum][0] = ND_I_single_line[0] + ( i - 1 ) * package_length;
        ND_I_check[j + ND_index_sum][1] = ND_I_single_line[1];
        //printf("%d %d \n", ND_I_check[j + ND_index_sum][0], ND_I_check[j + ND_index_sum][1]);
      }
      position = 0;
      ND_index_sum = ND_index_sum + ND_index;
      //printf("SUM:%d \n", ND_index_sum);
    }

    int *cluster_array = (int *) malloc(sizeof(int) * line);
    int *cluster_array_part = (int *) malloc(sizeof(int) * package_length);
    int *cluster_array_buffer = (int *) malloc(sizeof(int) * package_length);
    int cluster_array_buffer_size = sizeof(int) * package_length;
    for (i = 0; i < package_length; i++){
      cluster_array_buffer[i] = 0;
    }
    for (i = 0; i < line; i++){
      cluster_array[i] = 0;
    }

    for(i = 1; i < comm_sz; i++){
      MPI_Recv( cluster_array_buffer, cluster_array_buffer_size, MPI_PACKED, i, 0, MPI_COMM_WORLD, &mystatus );
      position = 0;
      MPI_Unpack( cluster_array_buffer, cluster_array_buffer_size, &position, cluster_array_part, package_length, MPI_INT, MPI_COMM_WORLD );
      for(j = 0; j < package_length; j++) {
        cluster_array[ ( i - 1 ) * package_length + j ] = cluster_array_part[j] + ( i - 1 ) * package_length;
//        printf("%d %d %d\n", ( i - 1 ) * package_length + j, cluster_array_part[j], cluster_array[ ( i - 1 ) * package_length + j ]);
      }
      position = 0;
    }    

    for(i = 0; i < ND_index_sum; i++) {
      for(j = 0; j < ND_index_sum; j++) {
        if(i == j || ND_I_check[j][0] == -1 || ND_I_check[i][0] == -1) {
          continue;
        }
        if( array_compare(sample_list, ND_I_check[i][0], ND_I_check[j][0], cols - 1, cols, ND_I_check[i][0]) == 1 ) {
          for( k = 0; k < line; k++){
            if(cluster_array[k] - 1 == ND_I_check[j][0]) {
              cluster_array[k] = ND_I_check[i][0] + 1;
            }
          }
          ND_I_check[j][0] = -1;
          ND_I_check[i][1] = ND_I_check[i][1] + ND_I_check[j][1];
        }
      }
    }

   for(i = 0; i < line; i++){
     sample_list[i][cols] = cluster_array[i];
//     printf("%d %d \n", i, cluster_array[i]);
    }

    char outfile[50] = {0};
    sprintf(outfile, "%s.prob", argv[1]);
    wp = fopen(outfile, "w");

    int ND_I = 0;
    for(i = 0; i < ND_index_sum; i++) {
      if(ND_I_check[i][0] != -1) {
        //printf("%d %d %d \n", i, ND_I_check[i][0], ND_I_check[i][1]); 
        natrual_distribution_index[ND_I][0] = ND_I_check[i][0];
        natrual_distribution_index[ND_I][1] = ND_I_check[i][1];
        ND_I = ND_I + 1;
      }
    }
    cluster(sample_list, angle_list, natrual_distribution_index, ND_I, line, cols, outfile);
  //  printf("%s Seems Done! \n", argv[1]);
   
   int state_index = 0, state_count = 0;
   double eq1 = 0, eq2 = 1, eq3 = 1, eq4 = 1;
   for(i=0;i<ND_I;i++){
   state_index = natrual_distribution_index[i][0];
   state_count = natrual_distribution_index[i][1];
   
   //eq1
   for(k = 0; k < line_length/WORD_LENGTH; k++){
   if(k == 0){
   eq1 = single_distribution(sample_list, state_index, k, sample_list[state_index][k], line_length/WORD_LENGTH, file_length/line_length);
   }
   else{
   eq1 = eq1 * single_distribution(sample_list, state_index, k, sample_list[state_index][k], line_length/WORD_LENGTH, file_length/line_length);
   }
   }
   
   //eq2
   for(k = 0; k < line_length/WORD_LENGTH - 1; k++){
   eq2 = eq2 * conditional_probability_2nd(sample_list, state_index,  k, k+1, sample_list[state_index][k], sample_list[state_index][k+1], line_length/WORD_LENGTH, file_length/line_length);
   }
   
   //eq3
   if(line_length/WORD_LENGTH-2 > 0){
   for(k=0;k<line_length/WORD_LENGTH-2;k++){
   eq3 = eq3 * conditional_probability_3nd(sample_list, state_index, k, k+1, k+2, sample_list[state_index][k], sample_list[state_index][k+1], sample_list[state_index][k+2], line_length/WORD_LENGTH, file_length/line_length);
   }
   }
   else{
   eq3 = 0;
   }
   
   //eq4
   if(line_length/WORD_LENGTH-3 > 0){
   for(k=0;k<line_length/WORD_LENGTH-3;k++){
   eq4 = eq4 * conditional_probability_4nd(sample_list, state_index, k, k+1, k+2, k+3, sample_list[state_index][k], sample_list[state_index][k+1], sample_list[state_index][k+2], sample_list[state_index][k+3], line_length/WORD_LENGTH, file_length/line_length);
   }
   }
   else{
   eq4 = 0;
   }
   
   fprintf(wp, "%lf %lf %lf %lf %lf\n", (double)state_count/(double)(file_length/line_length), eq1, eq2, eq3, eq4);
   }
   fclose(wp);
   
   }

  else{
    MPI_Bcast( single_argument_buffer, size_argument_buffer, MPI_PACKED, 0, MPI_COMM_WORLD);
    position = 0;
    MPI_Unpack(single_argument_buffer, size_argument_buffer, &position, &line, 1, MPI_INT, MPI_COMM_WORLD);
    MPI_Unpack(single_argument_buffer, size_argument_buffer, &position, &cols, 1, MPI_INT, MPI_COMM_WORLD);
    MPI_Unpack(single_argument_buffer, size_argument_buffer, &position, &package_length, 1, MPI_INT, MPI_COMM_WORLD);
    MPI_Unpack(single_argument_buffer, size_argument_buffer, &position, &size_buffer_double, 1, MPI_INT, MPI_COMM_WORLD);
//    printf("%d %d %d %d \n", line, cols, package_length, size_buffer_double);
    
    double *lines = NULL;
    lines =  (double *) malloc(sizeof(double) * size_buffer_double);
    
    double *single_line_buffer = NULL;
    single_line_buffer =  (double *) malloc(sizeof(double) * cols);
    
    double **lines_array = NULL;
    lines_array =  (double **) malloc(sizeof(double *) * package_length);
    for (j = 0; j < package_length; j++){
      lines_array[j] = (double *) malloc(sizeof(double) * cols);
      for (i = 0; i < cols; i++){
        lines_array[j][i] = 0;
      }
    }
    
    int **lines_array_sample = NULL;
    lines_array_sample = (int **) malloc(sizeof(int *) * package_length);
    
    MPI_Recv( lines, size_buffer_double, MPI_PACKED, 0, 0, MPI_COMM_WORLD, &mystatus);
    
    position = 0;
    for(j = 0; j < package_length; j++) {
      MPI_Unpack(lines, size_buffer_double, &position, single_line_buffer, cols, MPI_DOUBLE, MPI_COMM_WORLD);
      //      memcpy ( lines_array[j], single_line_buffer, sizeof(single_line_buffer) );
      for(i = 0; i < cols; i++){
        lines_array[j][i] = single_line_buffer[i];
      }
      //printf("%lf %lf %lf %lf\n", single_line_buffer[0], single_line_buffer[1], lines_array[j][0], lines_array[j][1]);
    }
    for (j = 0; j < package_length; j++){
      lines_array_sample[j] = (int *) malloc(sizeof(int) * (cols + 1) );
      for (i = 0; i < cols; i++){
        lines_array_sample[j][i] = (int) ((lines_array[j][i] + 180) / (COUNT) + 0.5);
//        printf("%d ", lines_array_sample[j][i]);
      }
//      printf("\n");
    }
    
    int ND_I = 0;
    int **natrual_distribution_indexs = NULL;
    natrual_distribution_indexs =  (int **) malloc(sizeof(int *) * package_length);
    
    for (j = 0; j < package_length; j++){
      natrual_distribution_indexs[j] = (int *) malloc(sizeof(int) * 2);
      for (i = 0; i < 2; i++){
        natrual_distribution_indexs[j][i] = 0;
      }
    }
    
    ND_I = natrual_distribution(lines_array_sample, natrual_distribution_indexs, package_length, cols);
    MPI_Send( &ND_I, 1, MPI_INT, 0, 0, MPI_COMM_WORLD );

    //cluster(lines_array_sample, lines_array, natrual_distribution_index, ND_I, line, cols, outfile);
//    printf("%d \n", ND_I);

    int ND_I_size = sizeof(int) * 2 * ND_I;
    int *ND_I_line_buffer = (int *) malloc(sizeof(int) * ND_I_size);
 
    position = 0;
    for(j = 0; j < package_length; j++) {
      MPI_Pack( natrual_distribution_indexs[j], 2, MPI_INT, ND_I_line_buffer, size_buffer_double, &position, MPI_COMM_WORLD );
    }
    MPI_Send( ND_I_line_buffer, ND_I_size, MPI_PACKED, 0, 0, MPI_COMM_WORLD );

    int *cluster_array = NULL;
    int *cluster_array_buffer = NULL;
    int cluster_array_buffer_size = sizeof(int) * package_length;

    cluster_array = (int *) malloc(sizeof(int) * package_length);
    cluster_array_buffer = (int *) malloc(sizeof(int) * package_length);
    for (i = 0; i < package_length; i++){
      cluster_array[i] = lines_array_sample[i][cols];
      cluster_array_buffer[i] = 0;
    }

    position = 0;
    MPI_Pack( cluster_array, package_length, MPI_INT, cluster_array_buffer, cluster_array_buffer_size, &position, MPI_COMM_WORLD );
    position = 0;
    MPI_Send( cluster_array_buffer, cluster_array_buffer_size, MPI_PACKED, 0, 0, MPI_COMM_WORLD );       
  }

  MPI_Finalize();
    printf("%s Seems Done! \n", argv[1]);

  return 0;
}
Exemple #17
0
/*
 * Implementation of the FFT tester described in
 *
 * Funda Ergün. Testing multivariate linear functions: Overcoming the
 * generator bottleneck. In Proceedings of the Twenty-Seventh Annual
 * ACM Symposium on the Theory of Computing, pages 407-416, Las Vegas,
 * Nevada, 29 May--1 June 1995.
 */
void test_ergun(int n, fftw_direction dir, fftw_plan plan)
{
     fftw_complex *inA, *inB, *inC, *outA, *outB, *outC;
     fftw_complex *tmp;
     fftw_complex impulse;
     int i;
     int rounds = 20;
     FFTW_TRIG_REAL twopin = FFTW_K2PI / (FFTW_TRIG_REAL) n;

     inA = (fftw_complex *) fftw_malloc(n * sizeof(fftw_complex));
     inB = (fftw_complex *) fftw_malloc(n * sizeof(fftw_complex));
     inC = (fftw_complex *) fftw_malloc(n * sizeof(fftw_complex));
     outA = (fftw_complex *) fftw_malloc(n * sizeof(fftw_complex));
     outB = (fftw_complex *) fftw_malloc(n * sizeof(fftw_complex));
     outC = (fftw_complex *) fftw_malloc(n * sizeof(fftw_complex));
     tmp = (fftw_complex *) fftw_malloc(n * sizeof(fftw_complex));

     WHEN_VERBOSE(2,
		  printf("Validating plan, n = %d, dir = %s\n", n,
			 dir == FFTW_FORWARD ? "FORWARD" : "BACKWARD"));

     /* test 1: check linearity */
     for (i = 0; i < rounds; ++i) {
	  fftw_complex alpha, beta;
	  c_re(alpha) = DRAND();
	  c_im(alpha) = DRAND();
	  c_re(beta) = DRAND();
	  c_im(beta) = DRAND();
	  fill_random(inA, n);
	  fill_random(inB, n);
	  fftw_out_of_place(plan, n, inA, outA);
	  fftw_out_of_place(plan, n, inB, outB);
	  array_scale(outA, alpha, n);
	  array_scale(outB, beta, n);
	  array_add(tmp, outA, outB, n);
	  array_scale(inA, alpha, n);
	  array_scale(inB, beta, n);
	  array_add(inC, inA, inB, n);
	  fftw_out_of_place(plan, n, inC, outC);
	  array_compare(outC, tmp, n);
     }

     /* test 2: check that the unit impulse is transformed properly */

     c_re(impulse) = 1.0;
     c_im(impulse) = 0.0;
     
     for (i = 0; i < n; ++i) {
	  /* impulse */
	  c_re(inA[i]) = 0.0;
	  c_im(inA[i]) = 0.0;
	  
	  /* transform of the impulse */
	  outA[i] = impulse;
     }
     inA[0] = impulse;
     
     for (i = 0; i < rounds; ++i) {
	  fill_random(inB, n);
	  array_sub(inC, inA, inB, n);
	  fftw_out_of_place(plan, n, inB, outB);
	  fftw_out_of_place(plan, n, inC, outC);
	  array_add(tmp, outB, outC, n);
	  array_compare(tmp, outA, n);
     }

     /* test 3: check the time-shift property */
     /* the paper performs more tests, but this code should be fine too */
     for (i = 0; i < rounds; ++i) {
	  int j;

	  fill_random(inA, n);
	  array_rol(inB, inA, n, 1, 1);
	  fftw_out_of_place(plan, n, inA, outA);
	  fftw_out_of_place(plan, n, inB, outB);
	  for (j = 0; j < n; ++j) {
	       FFTW_TRIG_REAL s = dir * FFTW_TRIG_SIN(j * twopin);
	       FFTW_TRIG_REAL c = FFTW_TRIG_COS(j * twopin);
	       c_re(tmp[j]) = c_re(outB[j]) * c - c_im(outB[j]) * s;
	       c_im(tmp[j]) = c_re(outB[j]) * s + c_im(outB[j]) * c;
	  }

	  array_compare(tmp, outA, n);
     }

     WHEN_VERBOSE(2, printf("Validation done\n"));

     fftw_free(tmp);
     fftw_free(outC);
     fftw_free(outB);
     fftw_free(outA);
     fftw_free(inC);
     fftw_free(inB);
     fftw_free(inA);
}
Exemple #18
0
int
ktest_equal_sequence_of_algorithm_identifier(krb5_algorithm_identifier **ref,
                                             krb5_algorithm_identifier **var)
{
    array_compare(ktest_equal_algorithm_identifier);
}
Exemple #19
0
//**************************************************************//
//                                                              //
//                  GENERATE INSTRUCTIONS                       //
//                                                              //
//**************************************************************//
instruction generate_instructions(char *S, char *T, uint32_t m, uint32_t n, int *SA, uint32_t *numInstructions){
    
    uint32_t ctr, i, T_len, prevCTR, insCtr, l, r, mid, T_len_1;
    
    int32_t T_ini = 0, LAST_LOW;
    
    uint8_t letterComp, stopCause;
    
    char ch, ch1;
    
    //printf("Size of the target string: %d Mbp\n", m / 1000000 + 1 );
    
    // Allocate enought memory for the instructions
    instruction instructions;
    instructions = (instruction) malloc(m*sizeof(struct instruction_t));
    
    ctr = 0;
    prevCTR = 0;
    i = 0;
    letterComp = 0;
    stopCause = 0;
    
    insCtr = 0;
    
    while (ctr < m ) {
        
        l = 0; r = n-1; mid = 0, T_len = 0, T_len_1 = 0, LAST_LOW = 0;
        
        // We are choosing the first instruction
        while (l < r) {
            mid = (l+r)/2;
            if (array_compare( (S+SA[mid]),(T+ctr), &T_len) == 1) {
                l = mid + 1;
                LAST_LOW = 1;
            }
            else{
                r = mid;
                LAST_LOW = 0;
            }
            
        }
        
        // We need to make sure that we are taking the LONGEST substring
        if(l){
            if(LAST_LOW){
                array_compare( (S+SA[l]),(T+ctr), &T_len_1 );
                T_ini = (T_len>T_len_1)? SA[l-1]: SA[l];
            }
            else{
                array_compare( (S+SA[l-1]),(T+ctr), &T_len_1);
                T_ini = (T_len>T_len_1)? SA[l]: SA[l-1];
            }
        }
        
        ctr += (T_len>T_len_1)? T_len: T_len_1;
        T_len = (T_len>T_len_1)? T_len: T_len_1;
        
        
        // Store the Instruction
        //     printf("%c %d\n", T[ctr], T_len);
        
        if (T[ctr] == '$' && T_len == 0) {
            instructions[insCtr].pos = instructions[insCtr-1].pos + instructions[insCtr-1].length + 1;
            instructions[insCtr].length = 0;
            instructions[insCtr].targetChar = 'N';
            instructions[insCtr].refChar = 'N';
            insCtr++;
            break;
        }
        else if (T[ctr] == '$') {// is the last instruction
            instructions[insCtr].pos = T_ini+1;
            instructions[insCtr].length = T_len;
            instructions[insCtr].targetChar = 'N';
            instructions[insCtr].refChar = 'N';
            insCtr++;
            break;
        }
        
        else if (T_len == 0){ // the target letter doesn't exist in the reference
            
            // Check if we are in the case where the target has N's, but the reference has none
            instructions[insCtr].pos = insCtr ? instructions[insCtr-1].pos + instructions[insCtr-1].length + 1 : 1;
            instructions[insCtr].length = 0;
            instructions[insCtr].targetChar = T[ctr];
            instructions[insCtr].refChar = S[instructions[insCtr].pos - 1];
            insCtr++;
        }
        
        else{
            
            ch = T[ctr];
            ch1 = S[T_ini + T_len];
            
            instructions[insCtr].pos = T_ini+1;
            instructions[insCtr].length = T_len;
            instructions[insCtr].targetChar = ch;
            instructions[insCtr].refChar = ch1;
            
            insCtr++;
        }
        
        
        // start all over again but with the updated T counter (ctr)
        ctr++; // we need to skip the mismatched letter as we explicitily saved it
        prevCTR = ctr;
    }
    
    *numInstructions = insCtr;
    
    // Realloc the Instructions array to free unused memory
    instructions = (instruction) realloc(instructions, insCtr*sizeof(struct instruction_t));
    
    return instructions;
}
Exemple #20
0
/* Same as test_ergun, but for multi-dimensional transforms: */
void testnd_ergun(int rank, int *n, fftw_direction dir, fftwnd_plan plan)
{
     fftw_complex *inA, *inB, *inC, *outA, *outB, *outC;
     fftw_complex *tmp;
     fftw_complex impulse;

     int N, n_before, n_after, dim;
     int i, which_impulse;
     int rounds = 20;
     FFTW_TRIG_REAL twopin;

     N = 1;
     for (dim = 0; dim < rank; ++dim)
	  N *= n[dim];

     inA = (fftw_complex *) fftw_malloc(N * sizeof(fftw_complex));
     inB = (fftw_complex *) fftw_malloc(N * sizeof(fftw_complex));
     inC = (fftw_complex *) fftw_malloc(N * sizeof(fftw_complex));
     outA = (fftw_complex *) fftw_malloc(N * sizeof(fftw_complex));
     outB = (fftw_complex *) fftw_malloc(N * sizeof(fftw_complex));
     outC = (fftw_complex *) fftw_malloc(N * sizeof(fftw_complex));
     tmp = (fftw_complex *) fftw_malloc(N * sizeof(fftw_complex));

     WHEN_VERBOSE(2,
		  printf("Validating plan, N = %d, dir = %s\n", N,
			 dir == FFTW_FORWARD ? "FORWARD" : "BACKWARD"));

     /* test 1: check linearity */
     for (i = 0; i < rounds; ++i) {
	  fftw_complex alpha, beta;
	  c_re(alpha) = DRAND();
	  c_im(alpha) = DRAND();
	  c_re(beta) = DRAND();
	  c_im(beta) = DRAND();
	  fill_random(inA, N);
	  fill_random(inB, N);
	  fftwnd(plan, 1, inA, 1, N, outA, 1, N);
	  fftwnd(plan, 1, inB, 1, N, outB, 1, N);
	  array_scale(outA, alpha, N);
	  array_scale(outB, beta, N);
	  array_add(tmp, outA, outB, N);
	  array_scale(inA, alpha, N);
	  array_scale(inB, beta, N);
	  array_add(inC, inA, inB, N);
	  fftwnd(plan, 1, inC, 1, N, outC, 1, N);
	  array_compare(outC, tmp, N);
     }

     /*
      * test 2: check that the unit impulse is transformed properly -- we
      * need to test both the real and imaginary impulses 
      */

     for (which_impulse = 0; which_impulse < 2; ++which_impulse) {
	  if (which_impulse == 0) {	/* real impulse */
	       c_re(impulse) = 1.0;
	       c_im(impulse) = 0.0;
	  } else {		/* imaginary impulse */
	       c_re(impulse) = 0.0;
	       c_im(impulse) = 1.0;
	  }

	  for (i = 0; i < N; ++i) {
	       /* impulse */
	       c_re(inA[i]) = 0.0;
	       c_im(inA[i]) = 0.0;

	       /* transform of the impulse */
	       outA[i] = impulse;
	  }
	  inA[0] = impulse;

	  for (i = 0; i < rounds; ++i) {
	       fill_random(inB, N);
	       array_sub(inC, inA, inB, N);
	       fftwnd(plan, 1, inB, 1, N, outB, 1, N);
	       fftwnd(plan, 1, inC, 1, N, outC, 1, N);
	       array_add(tmp, outB, outC, N);
	       array_compare(tmp, outA, N);
	  }
     }

     /* test 3: check the time-shift property */
     /* the paper performs more tests, but this code should be fine too */
     /* -- we have to check shifts in each dimension */

     n_before = 1;
     n_after = N;
     for (dim = 0; dim < rank; ++dim) {
	  int n_cur = n[dim];

	  n_after /= n_cur;
	  twopin = FFTW_K2PI / (FFTW_TRIG_REAL) n_cur;

	  for (i = 0; i < rounds; ++i) {
	       int j, jb, ja;

	       fill_random(inA, N);
	       array_rol(inB, inA, n_cur, n_before, n_after);
	       fftwnd(plan, 1, inA, 1, N, outA, 1, N);
	       fftwnd(plan, 1, inB, 1, N, outB, 1, N);

	       for (jb = 0; jb < n_before; ++jb)
		    for (j = 0; j < n_cur; ++j) {
			 FFTW_TRIG_REAL s = dir * FFTW_TRIG_SIN(j * twopin);
			 FFTW_TRIG_REAL c = FFTW_TRIG_COS(j * twopin);

			 for (ja = 0; ja < n_after; ++ja) {
			      c_re(tmp[(jb * n_cur + j) * n_after + ja]) =
				  c_re(outB[(jb * n_cur + j) * n_after + ja]) * c
				  - c_im(outB[(jb * n_cur + j) * n_after + ja]) * s;
			      c_im(tmp[(jb * n_cur + j) * n_after + ja]) =
				  c_re(outB[(jb * n_cur + j) * n_after + ja]) * s
				  + c_im(outB[(jb * n_cur + j) * n_after + ja]) * c;
			 }
		    }

	       array_compare(tmp, outA, N);
	  }

	  n_before *= n_cur;
     }

     WHEN_VERBOSE(2, printf("Validation done\n"));

     fftw_free(tmp);
     fftw_free(outC);
     fftw_free(outB);
     fftw_free(outA);
     fftw_free(inC);
     fftw_free(inB);
     fftw_free(inA);
}
Exemple #21
0
int
ktest_equal_sequence_of_otp_tokeninfo(krb5_otp_tokeninfo **ref,
                                      krb5_otp_tokeninfo **var)
{
    array_compare(ktest_equal_otp_tokeninfo);
}
Exemple #22
0
static int
vmac_list_eq(krb5_verifier_mac **ref, krb5_verifier_mac **var)
{
    array_compare(vmac_eq);
}
Exemple #23
0
static int
ktest_equal_sequence_of_data(krb5_data **ref, krb5_data **var)
{
    array_compare(ktest_equal_data);
}
Exemple #24
0
int
ktest_equal_authorization_data(krb5_authdata **ref, krb5_authdata **var)
{
    array_compare(ktest_equal_authdata);
}