Beispiel #1
0
static void
pwdfile_search( struct ldop *op, FILE *ofp )
{
    struct passwd	*pw;
    struct ldentry	*entry;
    int			oneentry;

    oneentry = ( strchr( op->ldop_dn, '@' ) != NULL );

    for ( pw = getpwent(); pw != NULL; pw = getpwent()) {
	if (( entry = pw2entry( op, pw )) != NULL ) {
	    if ( oneentry ) {
		if ( strcasecmp( op->ldop_dn, entry->lde_dn ) == 0 ) {
		    write_entry( op, entry, ofp );
		    break;
		}
	    } else if ( test_filter( op, entry ) == LDAP_COMPARE_TRUE ) {
			write_entry( op, entry, ofp );
	    }
	    free_entry( entry );
	}
    }
    endpwent();

    write_result( ofp, LDAP_SUCCESS, NULL, NULL );
}
Beispiel #2
0
int main(int argc, char *argv[]) {
  myResult *rtn;

  double sim_time = 25;
  double dt = 0.01;
  int print_interval = 10;
  int print_amount = 1;
  int method = MTHD_RUNGE_KUTTA;
  boolean use_lazy_method = false;

  if (argc < 2) {
    printf("Input SBML file is not specified.\n  Usage: %s sbml.xml\n", argv[0]);
    exit(1);
  }
  rtn = simulateSBMLFromFile(argv[1], sim_time, dt, print_interval, print_amount, method, use_lazy_method);
  if (rtn == NULL) {
    printf("Returned result is NULL\n");
  } else if (myResult_isError(rtn)) {
    printf("ERROR: %s\n", myResult_getErrorMessage(rtn));
  } else {
    /*  print_result(rtn); */
    /* write_csv(rtn, "cresult.csv"); */
    write_result(rtn, "test.dat");
    printf("Simulation result is written to test.dat.\n");
  }
  if (rtn != NULL)
    free_myResult(rtn);
  return 0;
}
Beispiel #3
0
int take_result(int score,char* name,char* names,int* scores)
{
	int i,j,value;
	for(i=0;i<10;i++)
	{
		if (score>=scores[i])
		{
			value=i;
			break;
		}
	}
	for(i=9;i>=value;i--)
	{
		scores[i]=scores[i-1];
		for(j=0;j<10;j++)
		{
			names[i*10+j]=names[(i-1)*10+j];
		}	
	}
	for(i=0;i<10;i++)
	{
		names[value*10+i]=name[i];
	}
	scores[value]=score;
	write_result(names,scores);	
	return 0;
}
int main(int argc, char *argv[])
{
    print_time("Begin");
    char *topo[5000];
    int edge_num;
    char *demand;
    int demand_num;

    char *topo_file = argv[1];
    edge_num = read_file(topo, 5000, topo_file);
    if (edge_num == 0)
    {
        printf("Please input valid topo file.\n");
        return -1;
    }
    char *demand_file = argv[2];
    demand_num = read_file(&demand, 1, demand_file);
    if (demand_num != 1)
    {
        printf("Please input valid demand file.\n");
        return -1;
    }
    search_route(topo, edge_num, demand);

    
    char *result_file = argv[3];
    write_result(result_file);
    
    release_buff(topo, edge_num);
    release_buff(&demand, 1);

    print_time("End");

	return 0;
}
Beispiel #5
0
int
main( int argc, char **argv )
{
    int			c, errflg;
    struct ldop		op;

    if (( progname = strrchr( argv[ 0 ], '/' )) == NULL ) {
	progname = estrdup( argv[ 0 ] );
    } else {
	progname = estrdup( progname + 1 );
    }

    errflg = debugflg = 0;

    while (( c = getopt( argc, argv, "d" )) != EOF ) {
	switch( c ) {
	case 'd':
#ifdef LDAP_DEBUG
	    ++debugflg;
#else /* LDAP_DEBUG */
	    fprintf( stderr, "%s: compile with -DLDAP_DEBUG for debugging\n",
		    progname );
#endif /* LDAP_DEBUG */
	    break;
	default:
	    ++errflg;
	}
    }

    if ( errflg || optind < argc ) {
	fprintf( stderr, "usage: %s [-d]\n", progname );
	exit( EXIT_FAILURE );
    }

    debug_printf( "started\n" );

    (void) memset( (char *)&op, '\0', sizeof( op ));

    if ( parse_input( stdin, stdout, &op ) < 0 ) {
	exit( EXIT_SUCCESS );
    }

    if ( op.ldop_op != LDOP_SEARCH ) {
	write_result( stdout, LDAP_UNWILLING_TO_PERFORM, NULL,
		"Command Not Implemented" );
	exit( EXIT_SUCCESS );
    }

#ifdef LDAP_DEBUG
    dump_ldop( &op );
#endif /* LDAP_DEBUG */

    pwdfile_search( &op, stdout );

    exit( EXIT_SUCCESS );
}
Beispiel #6
0
int main(int argc, char *argv[])
{
	int *matrix_a;
	int *matrix_b;
	int *matrix_c;

	const char *matrix_a_filename = argv[1];
	const char *matrix_b_filename = argv[2];
	const char *matrix_c_filename = argv[3];

	MPI_Comm matrix_comm;

	MPI_Init(&argc, &argv);

	create_matrix_comm(MPI_COMM_WORLD, &matrix_comm);
	MPI_Comm_size(matrix_comm, &size);
	MPI_Comm_rank(matrix_comm, &rank);

	compute_matrixes_variables(matrix_a_filename, matrix_comm);

	alloc_submatrix_buffer(&matrix_a);
	alloc_submatrix_buffer(&matrix_b);
	alloc_submatrix_buffer(&matrix_c);

	distribute_matrix(matrix_a_filename, matrix_a, matrix_comm);
	distribute_matrix(matrix_b_filename, matrix_b, matrix_comm);

	/* The actual cannon algorithms */
	int row_source, row_dst;
	int col_source, col_dst;
	MPI_Cart_shift(matrix_comm, 0, -1, &row_source, &row_dst);
	MPI_Cart_shift(matrix_comm, 1, -1, &col_source, &col_dst);
	int i;
	for (i = 0; i < pp_dims; i++) {
		compute_matrix_mul(matrix_a, matrix_b, matrix_c, N);
		MPI_Sendrecv_replace(matrix_a, sub_n * sub_n, MPI_INT,
				     row_source, MPI_ANY_TAG, row_dst, MPI_ANY_TAG,
				     matrix_comm, MPI_STATUS_IGNORE);

		MPI_Sendrecv_replace(matrix_b, sub_n * sub_n, MPI_INT,
				     col_source, MPI_ANY_TAG, col_dst, MPI_ANY_TAG,
				     matrix_comm, MPI_STATUS_IGNORE);
	}


	write_result(matrix_c_filename, matrix_c, matrix_comm);

	free(matrix_a);
	free(matrix_b);
	free(matrix_c);

	MPI_Comm_free(&matrix_comm);

	MPI_Finalize();
	return 0;
}
Beispiel #7
0
static void
cli_command_end_complete(int sock_fd, const cl_error_desc_t *err_desc)
{
  char *result;

  result = xml_command_end(err_desc);

  write_result(sock_fd, result);

  os_free(result);
}
Beispiel #8
0
static void interpret(GSList* atoms, const char* fn)
{
    GSList* stack = NULL;
    g_slist_foreach(atoms, interpret_one, &stack);

    fold_to(&stack, 1);
    write_result(GMIME_MESSAGE(stack->data), fn);

    g_slist_foreach(atoms, free_atom, NULL);
    g_object_unref(stack->data);
    g_slist_free(stack);
}
Beispiel #9
0
/*--------------- main routine ---------------*/
int main( int argc, char *argv[] )
{
   THD_3dim_dataset * countset=NULL;
   param_t          * params = &g_params;
   int                rv, limit;

   if( argc < 1 ) { show_help();  return 0; }

   /* general stuff */
   mainENTRY("3dmask_tool"); machdep(); AFNI_logger("3dmask_tool",argc,argv);
   enable_mcw_malloc();

   /* process options: a negative return is considered an error */
   rv = process_opts(params, argc, argv);
   if( rv ) RETURN(rv < 0);

   /* open, convert to byte, zeropad, dilate, unzeropad */
   if( process_input_dsets(params) ) RETURN(1);

   /* create mask count dataset and return num volumes (delete old dsets) */
   if( count_masks(params->dsets, params->ndsets, params->verb,
                   &countset, &params->nvols) ) RETURN(1);

   /* limit to frac of nvols (if not counting, convert to 0/1 mask) */
   limit = ceil((params->frac>1) ? params->frac : params->nvols*params->frac );
   if( params->verb )
      INFO_message("frac %g over %d volumes gives min count %d\n",
                   params->frac, params->nvols, limit);
   if( limit <= 0 ) limit = 1;

   /* if not counting, result is binary 0/1 */
   if( limit_to_frac(countset, limit, params->count, params->verb) )
      RETURN(1);

   /* maybe apply dilations to output */
   if( params->RESD.num > 0 ) {
      countset = apply_dilations(countset, &params->RESD, 0, params->verb);
      if( !countset ) RETURN(1);
   }

   /* maybe fill any remaining holes */
   if( params->fill )
      if ( fill_holes(countset, params->verb) ) RETURN(1);

   /* create output */
   if( write_result(params, countset, argc, argv) ) RETURN(1);

   /* clean up a little memory */
   DSET_delete(countset);
   free(params->dsets);

   RETURN(0);
}
Beispiel #10
0
int bind_interface(char* interface_name,int sockfd)
{
	struct ifreq interface;
	memset(&interface, 0, sizeof(interface));
	strncpy(interface.ifr_ifrn.ifrn_name, interface_name, strlen(interface_name));
	if(setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, (char *)&interface, sizeof(interface)) < 0){
		IK_APP_ERR_LOG("ik_speed bind to device failed\n");
		write_result(interface_name," 绑定网卡失败 ");
		return 1;
	}
	return 0;
}
Beispiel #11
0
void cli_payload_str(unsigned int uid, const char *str)
{
  char *result;
  int i;

  if (uid == CMD_UID_INVALID)
    return;

  result = xml_payload_str_new(str);
  for (i = 0; i < MAX_CONNECTION; i++)
    if (uid == connectlist[i].uid)
      write_result(connectlist[i].fd, result);
  os_free(result);
}
/* unique_lock 을 이용하여 lock 의 granularity 를 세분화 하여 lock 경합을 줄였다. */
void get_and_process_data()
{
	std::mutex m;
	some_class get_next_data_chunk;

	std::unique_lock<std::mutex> my_lock(m);
	some_class data_to_process = get_next_data_chunk;
	my_lock.unlock(); /* (1) */

	/* 이 시점에 get_and_process_data 를 다른 스레드에서 호출할 경우 invariant 가 파괴될 가능성이 매우 크다. */ 
	int result = process(data_to_process);

	my_lock.lock(); /* (2) */
	write_result(data_to_process, result);
}
int main() {
	/* read config file information */
    config_t *config = read_config();
    /* get cluster number k */
    int k = config->k;
    /* initialize dataset into an array */
    point_t *dataset = init_dataset(config);
    /* get number of points */
    int num_of_points = config->count;
    /* compute initial centroids from dataset */
    point_t *centroids = init_centroid(dataset, k, num_of_points);
    /* start the kmeans process */
    kmeans(centroids, dataset, k, num_of_points);
    /* print the results */
    print_result(centroids, k);
    write_result(centroids, k, config);
    return 0;
}
Beispiel #14
0
void cli_write_inprogress(unsigned int uid, const char *src_node,
                          const char *desc, int err, const char *str)
{
  char text_buf[EXA_MAXSIZE_BUFFER + 1];
  cl_error_desc_t err_desc;
  int i;

  if (uid == CMD_UID_INVALID)
    return;

  set_error(&err_desc, err, str);

  xml_inprogress(text_buf, sizeof(text_buf), src_node, desc, &err_desc);

  for (i = 0; i < MAX_CONNECTION; i++)
    if (uid == connectlist[i].uid)
      write_result(connectlist[i].fd, text_buf);
}
Beispiel #15
0
int main(int argc, char *argv[])
{
	Floyd test;
	test.initialvector((int *)V,6);
	test.floyd();

	Dijkstra test_dijkstra;
	test_dijkstra.dijkstra(3,(int*)V,6);

    //print_time("Begin");
    char *topo[5000];
    int edge_num;
    char *demand;
    int demand_num;

    char *topo_file = argv[1];
    edge_num = read_file(topo, 5000, topo_file);
    if (edge_num == 0)
    {
        printf("Please input valid topo file.\n");
        return -1;
    }
    char *demand_file = argv[2];
    demand_num = read_file(&demand, 1, demand_file);
    if (demand_num != 1)
    {
        printf("Please input valid demand file.\n");
        return -1;
    }

    search_route(topo, edge_num, demand);

    char *result_file = argv[3];
    write_result(result_file);
    release_buff(topo, edge_num);
    release_buff(&demand, 1);

    //print_time("End");

	return 0;
}
int main()
{
        //system("date");
        int i,a;
        iAntCount=1000;
        counts[0]=150;
        counts[1]=300;
        ihapsize[0]=6;
        ihapsize[1]=3;
        alpha=1;
        rou=0.05;
        phe=100;
        iTopModel=1000;
        iTopLoci=200;
        iEpiModel=2;
        pvalue=0.01;
        char* para="parameters.txt";
        loadparameters(para);
        SNPdata.input_data(inputfile);
        //SNPdata.setpheromone(phe);
        iLociCount=SNPdata.iLoci-1;
        char* logpath="AntEpiSeeker.log";
        char* minipath="results_maximized.txt";
        write_result(logpath,0);
        for(a=0;a<2;a++)
        {
        iItCount=counts[a];
        cout<<a+1<<" round search"<<endl;
        iLociModel=ihapsize[a];
        loci_TopModel=new int* [iTopModel];
        for(i=0;i<iTopModel;i++)
                loci_TopModel[i]=new int [iLociModel];
        loci_TopLoci=new int [iTopLoci];
        phe_TopLoci=new double [iTopLoci];
        eva_TopModel=new double [iTopModel];
        for(i=0;i<iTopModel;i++)
            eva_TopModel[i]=0;
///////////////////////////////////////////////////////////////
        cout<<"-----Initializing parameters-----"<<endl;
        cout<<"Number of ants: "<<iAntCount<<endl;
        cout<<"Number of iterations: "<<iItCount<<endl;
        cout<<"Start pheromone level: "<<phe<<endl;
        cout<<"Rou: "<<rou<<endl;
        cout<<"Alpha: "<<alpha<<endl;
        cout<<"Number of top ranking SNP sets: "<<iTopModel<<endl;
        cout<<"Number of top ranking loci: "<<iTopLoci<<endl;
        cout<<"Size of SNP sets: "<<ihapsize[a]<<endl;
        cout<<"Number of SNPs in an epistatic interaction: "<<iEpiModel<<endl;
///////////////////////////////////////////////////////////////
        SNPdata.setpheromone(phe);
        project episeeker;
        episeeker.StartSearch();
        get_toploci();
        write_result(logpath,3);
        postprocessing();
        for(i=0;i<iTopModel;i++)
        {
         delete [] loci_TopModel[i];
        }
         delete [] loci_TopModel;
         delete [] loci_TopLoci;
         delete [] phe_TopLoci;
         delete [] eva_TopModel;
         
        }
        mini_fp();
//////////////////permutation///////////////////////////////
       // cout<<"Permuting genotypes:\n";
       // for(i=0;i<10000;i++)
       // {
       // if(i%500==0)
       // cout<<i<<" iteractions"<<endl;
       // rnd_values[i]=random_chi();
       // }
////////////////////////////////////////////////////////////
        write_result(minipath,4);
        write_result(outputfile,1);
        SNPdata.destroy();
        return 1;
}
/////////////////////////////////////////////////////////////////////////////////////////////
//int main(int argc, char *argv[ ])
//{
 int main(void)
 {
   	sortingindex = 0;
	if((fpp = fopen(INPUT_FILE, "r")) == NULL)
	{
		printf("Cannot open 'parameter_file'.\n");
	}

	for(j = 0; j < 11; j++)
	{
		if(fscanf(fpp, "%lf", &tmp) != EOF) 
		{
				my_array[j] = tmp;
				
		} else 		{
			printf("Not enough data in 'input_parameter'!");
		}
	}

	fclose(fpp);
 

   	In_n= (int) my_array[0];
	In_vect_n= (int) my_array[1];
	Out_n= (int) my_array[2];
	Mf_n= (int) my_array[3];
	training_data_n= (int) my_array[4];
	checking_data_n= (int) my_array[5];
	epoch_n= (int) my_array[6];
	step_size=my_array[7];
	increase_rate=my_array[8];
	decrease_rate=my_array[9];
	threshold = my_array[10];
		
	Rule_n = (int)pow((double)Mf_n, (double)In_n); //number of rules 
	Node_n = In_n + In_n*Mf_n + 3*Rule_n + In_n*Rule_n + Out_n;

	/* allocate matrices and memories */
	int trnnumcheck[training_data_n + 1];
	int trnnumchecku[training_data_n + 1];
	for(i=0; i<training_data_n +1; i++)
	{
	trnnumcheck[i]=0;
	trnnumchecku[i]=0;
	}
	
	diff =(double **)create_matrix(Out_n, training_data_n, sizeof(double)); 
	double chkvar[checking_data_n];
	double cdavg[checking_data_n];
	double chkvar_un[checking_data_n];
	double cdavg_un[checking_data_n];
	target = calloc(Out_n, sizeof(double));
	de_out = calloc(Out_n, sizeof(double));
	node_p = (NODE_T **)create_array(Node_n, sizeof(NODE_T *)); 
	config = (int **)create_matrix(Node_n, Node_n, sizeof(int)); 
	training_data_matrix = (double **)create_matrix(training_data_n, In_n*In_vect_n + Out_n, sizeof(double));
	if(checking_data_n > 0)
	{
		checking_data_matrix = (double **)create_matrix(checking_data_n, In_n*In_vect_n +Out_n, sizeof(double));
		checking_data_matrix_un = (double **)create_matrix(checking_data_n, Out_n, sizeof(double));
		chk_output =  (double **)create_matrix(checking_data_n, Out_n, sizeof(double));
	}
	layer_1_to_4_output = (COMPLEX_T **)create_matrix(training_data_n, In_n*Mf_n + 3*Rule_n, sizeof(COMPLEX_T));
	trn_rmse_error = calloc(epoch_n, sizeof(double));
	trnNMSE = calloc(epoch_n, sizeof(double));
	chk_rmse_error = calloc(epoch_n, sizeof(double));
	kalman_parameter = (double **)create_matrix(Out_n ,(In_n*In_vect_n + 1)*Rule_n, sizeof(double)); 
	kalman_data = (double **)create_matrix(Out_n ,(In_n*In_vect_n + 1)*Rule_n, sizeof(double));
	step_size_array = calloc(epoch_n, sizeof(double));
	ancfis_output = (double **)create_matrix(training_data_n , Out_n, sizeof(double)); 
	trn_error =calloc(Out_n +1, sizeof(double));
	chk_error_n = calloc(Out_n +1, sizeof(double));// changing size for adding new error measures
	chk_error_un = calloc(Out_n +1, sizeof(double));// changing size for adding new error measures
	trn_datapair_error = calloc(training_data_n, sizeof(double));
	trn_datapair_error_sorted = (double **)create_matrix(2,training_data_n, sizeof(double));
	NMSE = calloc(Out_n, sizeof(double));
	NDEI = calloc(Out_n, sizeof(double));
	unNMSE = calloc(Out_n, sizeof(double));
	unNDEI = calloc(Out_n, sizeof(double));
	//Build Matrix of 0 nd 1 to show the connected nodes
	gen_config(In_n, Mf_n,Out_n, config);//gen_config.c
	//With the above matrix, build ANCFIS connected nodes
	build_ancfis(config); //datastru.c
	//Find total number of nodes in layer 1 and 5
	parameter_n = set_parameter_mode(); //datastru.c
	parameter_array = calloc(parameter_n, sizeof(double));
	initpara(TRAIN_DATA_FILE, training_data_n, In_n, In_vect_n+1, Mf_n); // initpara.c
// after this step, the parameters (they are present in layer 1 and layer 5 only) are assigned a random initial value 
// using some basic algebra and these value are then stored in "para.ini"
	get_parameter(node_p,Node_n,INIT_PARA_FILE); //input.c
// after this step, the initial random values of the parametrs are read from "oara.ini" and assigned to the appropriate nodes in the node structure by accessing their para list.
	//Get training and testing data
	get_data(TRAIN_DATA_FILE, training_data_n, training_data_matrix); //input.c
// after this step, the training input data is read from the "data.trn" fle and stroed in the training data matrix.
	get_data(CHECK_DATA_FILE, checking_data_n, checking_data_matrix); //input.c
// after the above step, the checking data is read from the "data.chk" file and then stored in the checking data matrix.

	for(i=0; i< Out_n; i++)
	{
	for(j=0; j<training_data_n; j++)
	{
	trnavg = trnavg + training_data_matrix[j][(i+1)*In_vect_n +i];
	}
	}
	trnavg = trnavg /(Out_n * training_data_n);
	
	for(i=0; i< Out_n; i++)
	{
	for(j=0; j<training_data_n; j++)
	{
	temp = training_data_matrix[j][(i+1)*In_vect_n +i]- trnavg;
	temp = temp*temp;
	trnvariance = trnvariance + temp;
	}
	}
	trnvariance = trnvariance /((Out_n * training_data_n)-1);

	temp = 0.0;
	for(i=0; i< Out_n; i++)
	{
	for(j=0; j< checking_data_n; j++)
	{
	chkavg = chkavg + checking_data_matrix[j][(i+1)*In_vect_n +i];
	}
	}
	chkavg = chkavg /(Out_n * checking_data_n);
	
	for(i=0; i< Out_n; i++)
	{
	for(j=0; j<checking_data_n; j++)
	{
	temp = checking_data_matrix[j][(i+1)*In_vect_n +i]- chkavg;
	temp = temp*temp;
	chkvariance = chkvariance + temp;
	}
	}
	chkvariance = chkvariance /((Out_n * checking_data_n)-1);
	printf("epochs \t trn error \t tst error\n");
	printf("------ \t --------- \t ---------\n");
	//printf("not entering the epoch loop and the i loop yoyoyo\n");
/**************
	for(ep_n = 0; ep_n < epoch_n; ep_n++)
	{ 
		//step_size_pointer= &step_size;		
		//printf("epoch numbernumber %d \n", ep_n);	
		//step_size_array[ep_n] = step_size_pointer;
		step_size_array[ep_n] = step_size;
	// after the above step, the updated stepsize at the end of the last loop is stored in the step_size_array.
	// this will keep happening every time we start en epoch and hence at the end of the loop, step_size_array will 
	// have a list of all the updated step sizes. Since this is a offline version, step sizes are updated only
	// at the end of an epoch. 
		for(m = 0; m < Out_n; m++)
		{ 	
			//printf("m loop number %d \n", m);	
			for(j = 0; j < training_data_n; j++)
			{ 
				//printf("j loop number %d \n", j);				
				//copy the input vector(s) to input node(s)
				put_input_data(node_p,j, training_data_matrix); //input.c
	// after this(above) step, the input data is transferred frm the training data matrix to the "node" structure.
				//printf("testing \n");	
				//printf("reeeetesting \n");	
				target[m] = training_data_matrix[j][(m+1)*In_vect_n+m]; // *** 
	// this step assigns the value of the "m"th output of "j" th trainig data pair to target.
				//printf("testing \n");	
				//forward pass, get node outputs from layer 1 to layer 4
				calculate_output(In_n, In_n + In_n*Mf_n + 3*Rule_n - 1, j); //forward.c
	// after this step, output of nodes in layer 1 to 4 is calculated. Please note that when this happens for the first
	// time, i.e. when ep_n=0, our network parametrs are already initialized. thus, it is possible to get the
	// output of each node using the function definitios proposed in forward.c. After first epoch, our parametrs get 
	// updated and this output is then calculated using teh new parameters. The essential point to note here is that
	// we can always calculate the output of each node since we have already initialized our parameters.
				//printf("testing \n");	
				//put outputs of layer 1 to 4 into layer_1_to_4_output
		
				for(k = 0; k < Mf_n*In_n + 3*Rule_n; k++)
				{
				//printf("testing \n");	
				layer_1_to_4_output[j][k] = *node_p[k + In_n]->value;
				}
	// the above loop simply puts the values of nodes from layer 1 to layer 4 in the layer_1_to_4_output matrix.

				//identify layer 5 params using LSE (Kalman filter)
				//printf("testing \n");	
				get_kalman_data(kalman_data, target); //kalman.c
	// this function call finds out the values of O4iXnl .. these are basically the coefficients
	// of the kalman parametrs for a given training data pair
	//puts them in kalman_data matrix.
	// this kalman_data matrix has In_n number of rows and number of columns equal to number of parametrs that are
	// responsible for determining each output... as stated above, the outputs are actually the coefficients of the
	// parameters.

				//printf("testing \n");	
				//calculate Kalman parameters
				
				kalman(ep_n, j+(m*training_data_n), m, kalman_data, kalman_parameter,target); //kalman.c
	// this function call evaluates kalman parametrs for a given output, for a given epoch.. that is it takes the epoch 
	// number from us, takes the info about how many times has kalman been invoked before, also takes in the
	// output number(row number) for whihc the parametrs are to be found out... it also takes kalman_data and reads 
	// from it to estimate the kalman parameters... it also takes target .. and stores the output in the mth row of 
	// kalman_parameter.
				//printf("testing \n");	
			}
	// let me tell u what the abopve loop is doing.. after observing closely, it is easy to see that in the above loop, 
	// for a given output node, one by one, all the training data are taken inside the ANCFIS structure, outputs
	// are calculated from one to 4, then a recursive kalman filetr is used to identify the kalman
	// parametrs corresponding to the output node.. these kalman parameters are updated after every tarining data pair 
	// and finally at the end of all the training data, we have an estimate for the kalman parametrs corresponding to 		// the output node.
		}
	// thus, at the of the above loop, the kalman parametrs for all the output nodes are evaluated...

	// now, we are ready to actually calculate the outputs.. plase remember that, all this while, the actual 
	// values of the parametrs of nodes in layer 1 and layer 5 are the ones that were randomly initialized.

		for(j = 0; j < training_data_n; j++)
		{ 
			//printf("testing 1\n");	
			put_input_data(node_p,j, training_data_matrix); //input.c
			//printf("testing 2 \n");	
			for(k = 0; k < Mf_n*In_n + 3*Rule_n; k++)
			{
				*node_p[k + In_n]->value = layer_1_to_4_output[j][k];
			}
	// u must be able to see that in the above two loops, each time, whatever output we got for a given training 
	// datta pair, it was safely stored in layer_1_to_4 array...and each time, the value on the actual nodes in the
	// structure got changed.. due to new incoming training data pair..this was periodic with period trainingdata_n..
	// that is for each output node, we got the same results for a given training dat aapir.. that is the node values
	// were independent of m. Now, for a given traing data pair, we are getting those value back in the actual node 
	// node structure from that laye blh blah matrix..

			//printf("testing 3\n");	
			put_kalman_parameter(Out_n,kalman_parameter); //kalman.c
	// using this function call, we are placing the setimated value of the layer 5 parametrs in the node structure
	// by accessing each node and its parameter list.
			// Do forward pass for L5 and L6
			calculate_output(In_n + In_n*Mf_n + 3*Rule_n, Node_n, j); //forward.c
	// for a given value of the training data pair, this function calculates the output of layer 5 and layer 6 nodes 
	// and places them in the node structure.

			calculate_root(training_data_matrix,diff,j,node_p); //debug.c
	// this function call calculates the square of the erro between the predicted value of an output node and the 
	// corresponding actual value in the training data matrix..(actual output) and stores it in diff.
	// this call performs the above action for a given training data pair and for all output nodes.

			// Do backward pass and calculate all error rate for each node
			calculate_de_do(j,Out_n,target,ancfis_output); //backward.c
	// calculates de_do for each node fora given training data pair
			update_de_dp(j); //de_dp.c	
	// updates de_do for each node....
		}
	// thus at the end of this loop, estimated outputs for all the training data are calculated..also back propogatin 
	// is done and de_dp for all the nodes is updated.
		
		//printf("testing 1\n");	
		calculate_trn_err(diff,trn_error,trn_datapair_error,training_data_n); //debug.c
		//printf("testing 2 \n");	
		//training_error_measure(target,ancfis_output,diff, training_data_n, trn_error,out_n); //trn_err.c
		trn_rmse_error[ep_n] = trn_error[Out_n];
		printf("%3d \t %.11f \n", ep_n+1, trn_error[Out_n]);
		//Find RMSE of testing error
	/*************************************	if(checking_data_n != 0) 
		{
			printf("testing 3 \n");	
			epoch_checking_error(checking_data_matrix, checking_data_n, chk_error, training_data_n, chk_output, ep_n); //chk_err.c  writes to tracking.txt
			printf("testing 4 \n");	
			chk_rmse_error[ep_n] = chk_error[Out_n];
			for (i=0; i<Out_n; i++)
			//printf("%3d \t %.11f \t %.11f\n", ep_n+1, trn_error[i], chk_error[i]);
			printf("%3d \t %.11f \n", ep_n+1, trn_error[i]);
			//printf("%.11f\t %.11f\n", trn_error[Out_n],chk_error[Out_n]);
			printf("%.11f\t %.11f\n", trn_error[Out_n]);
			write_result(ep_n+1,Out_n,trn_error,chk_error);  //debug.c writes to result.txt
		} 
		else 
		{
			for (i=0; i<Out_n; i++)	
			printf("%4d \t %.11f\n", ep_n+1, trn_error[i]);
		}
***************************/

/**
		//Find minimum training error and its epoch-number
		if(trn_rmse_error[ep_n] < min_trn_RMSE) {
			min_trn_RMSE_epoch = ep_n +1;
			min_trn_RMSE = trn_rmse_error[ep_n];
			record_parameter(parameter_array);
		}

		if(ep_n < epoch_n-1)
		{ 
			//update parameters in 1st layer (Using VNCSA)
			update_parameter(1, step_size); //new_para.c
			//update stepsize
			update_step_size(trn_rmse_error, ep_n, &step_size, decrease_rate, increase_rate); //stepsize.c
		}
	}
***/
////////////////////////////////////////////////////////////

fppp = (FILE *)open_file("status.txt", "w");
fpppp = (FILE *)open_file("trn.txt", "w");


	ep_n=0;

	do
	{
		//step_size_pointer= &step_size;		
		printf("epoch numbernumber %d \n", ep_n+1);	
		//step_size_array[ep_n] = step_size_pointer;
		step_size_array[ep_n] = step_size;
	// after the above step, the updated stepsize at the end of the last loop is stored in the step_size_array.
	// this will keep happening every time we start en epoch and hence at the end of the loop, step_size_array will 
	// have a list of all the updated step sizes. Since this is a offline version, step sizes are updated only
	// at the end of an epoch. 
		for(m = 0; m < Out_n; m++)
		{ 	
			//printf("m loop number %d \n", m);	
			for(j = 0; j < training_data_n; j++)
			{ 
				//printf("j loop number %d \n", j);				
				//copy the input vector(s) to input node(s)
				put_input_data(node_p,j, training_data_matrix); //input.c
	// after this(above) step, the input data is transferred frm the training data matrix to the "node" structure.
				//printf("testing \n");	
				//printf("reeeetesting \n");	
				target[m] = training_data_matrix[j][(m+1)*In_vect_n+m]; // *** 
	// this step assigns the value of the "m"th output of "j" th trainig data pair to target.
				//printf("testing \n");	
				//forward pass, get node outputs from layer 1 to layer 4
				calculate_output(In_n, In_n + In_n*Mf_n + 3*Rule_n, j); //forward.c
	// after this step, output of nodes in layer 1 to 4 is calculated. Please note that when this happens for the first
	// time, i.e. when ep_n=0, our network parametrs are already initialized. thus, it is possible to get the
	// output of each node using the function definitios proposed in forward.c. After first epoch, our parametrs get 
	// updated and this output is then calculated using teh new parameters. The essential point to note here is that
	// we can always calculate the output of each node since we have already initialized our parameters.
				//printf("testing \n");	
				//put outputs of layer 1 to 4 into layer_1_to_4_output
		
				for(k = 0; k < Mf_n*In_n + 3*Rule_n; k++)
				{
				//printf("testing \n");	
				layer_1_to_4_output[j][k] = *node_p[k + In_n]->value;
				//fprintf(fppp, "%lf \t %lf \t \n", (layer_1_to_4_output[j][k]).real, (layer_1_to_4_output[j][k]).imag);
				}
	// the above loop simply puts the values of nodes from layer 1 to layer 4 in the layer_1_to_4_output matrix.

				//identify layer 5 params using LSE (Kalman filter)
				//printf("testing \n");	
				get_kalman_data(kalman_data, target); //kalman.c
	// this function call finds out the values of O4iXnl .. these are basically the coefficients
	// of the kalman parametrs for a given training data pair
	//puts them in kalman_data matrix.
	// this kalman_data matrix has In_n number of rows and number of columns equal to number of parametrs that are
	// responsible for determining each output... as stated above, the outputs are actually the coefficients of the
	// parameters.

				//printf("testing \n");	
				//calculate Kalman parameters
				
				kalman(ep_n, j+(m*training_data_n), m, kalman_data, kalman_parameter,target); //kalman.c
	// this function call evaluates kalman parametrs for a given output, for a given epoch.. that is it takes the epoch 
	// number from us, takes the info about how many times has kalman been invoked before, also takes in the
	// output number(row number) for whihc the parametrs are to be found out... it also takes kalman_data and reads 
	// from it to estimate the kalman parameters... it also takes target .. and stores the output in the mth row of 
	// kalman_parameter.
				//printf("testing \n");	
			}
	// let me tell u what the abopve loop is doing.. after observing closely, it is easy to see that in the above loop, 
	// for a given output node, one by one, all the training data are taken inside the ANCFIS structure, outputs
	// are calculated from one to 4, then a recursive kalman filetr is used to identify the kalman
	// parametrs corresponding to the output node.. these kalman parameters are updated after every tarining data pair 
	// and finally at the end of all the training data, we have an estimate for the kalman parametrs corresponding to 		// the output node.
		}
	// thus, at the of the above loop, the kalman parametrs for all the output nodes are evaluated...

	// now, we are ready to actually calculate the outputs.. plase remember that, all this while, the actual 
	// values of the parametrs of nodes in layer 1 and layer 5 are the ones that were randomly initialized.

		for(j = 0; j < training_data_n; j++)
		{ 
			//printf("testing 1\n");	
			put_input_data(node_p,j, training_data_matrix); //input.c
			//printf("testing 2 \n");	
			for(k = 0; k < Mf_n*In_n + 3*Rule_n; k++)
			{
				*node_p[k + In_n]->value = layer_1_to_4_output[j][k];
				/*if(ep_n==1)
				{
				fprintf(fppp, "%d.\t %lf \t + \t i%lf \n", k, (layer_1_to_4_output[j][k]).real,(layer_1_to_4_output[j][k]).imag);
				}*/
			}
	// u must be able to see that in the above two loops, each time, whatever output we got for a given training 
	// datta pair, it was safely stored in layer_1_to_4 array...and each time, the value on the actual nodes in the
	// structure got changed.. due to new incoming training data pair..this was periodic with period trainingdata_n..
	// that is for each output node, we got the same results for a given training dat aapir.. that is the node values
	// were independent of m. Now, for a given traing data pair, we are getting those value back in the actual node 
	// node structure from that laye blh blah matrix..

			//printf("testing 3\n");	
			put_kalman_parameter(Out_n,kalman_parameter); //kalman.c
			//printf("hihahahha \n");
	// using this function call, we are placing the setimated value of the layer 5 parametrs in the node structure
	// by accessing each node and its parameter list.
			// Do forward pass for L5 and L6
			calculate_output(In_n + In_n*Mf_n + 3*Rule_n, Node_n, j); //forward.c
	// for a given value of the training data pair, this function calculates the output of layer 5 and layer 6 nodes 
	// and places them in the node structure.
			//printf("hihahahha  no 2 \n");
	calculate_root(training_data_matrix,diff,j,node_p); //debug.c
	// this function call calculates the square of the erro between the predicted value of an output node and the 
	// corresponding actual value in the training data matrix..(actual output) and stores it in diff.
	// this call performs the above action for a given training data pair and for all output nodes.

			// Do backward pass and calculate all error rate for each node
			calculate_de_do(j,Out_n,target,ancfis_output); //backward.c
			//printf("hihahahha no 3 \n");
	// calculates de_do for each node fora given training data pair
			update_de_dp(j); //de_dp.c	
	// updates de_do for each node....
		}
	// thus at the end of this loop, estimated outputs for all the training data are calculated..also back propogatin 
	// is done and de_dp for all the nodes is updated.
		
		//printf("testing 1\n");	
		calculate_trn_err(diff,trn_error, trn_datapair_error, training_data_n); //debug.c
		//printf("testing 2 \n");	
		//training_error_measure(target,ancfis_output,diff, training_data_n, trn_error,out_n); //trn_err.c
		trn_rmse_error[ep_n] = trn_error[Out_n];
		trnNMSE[ep_n] = trn_rmse_error[ep_n]*trn_rmse_error[ep_n]/trnvariance;
		fprintf(fppp, "epoch number is %d \t trn RMSE is %.11f \t trn NMSE is  %lf \t \n", ep_n + 1,  trn_rmse_error[ep_n], trnNMSE[ep_n]);
		//fprintf(fpppp, "\n");
		fprintf(fpppp, "epoch number is %d \t trn RMSE is %.11f \t trn NMSE is  %lf \t \n", ep_n + 1,  trn_rmse_error[ep_n], trnNMSE[ep_n]);
		printf("trn RMSE is \t %lf \n", trn_rmse_error[ep_n]);
		printf("trn NMSE is \t %lf \n", trnNMSE[ep_n]);
		for(i=0; i<training_data_n; i++)
		{
		trn_datapair_error_sorted[0][i]=trn_datapair_error[i];
		trn_datapair_error_sorted[1][i]= i+1;
		}

		for(j=1; j<training_data_n; j++)
		{		
		for(i=0; i<training_data_n-j; i++)
		{
		if(trn_datapair_error_sorted[0][i]>trn_datapair_error_sorted[0][i+1])
		{	
		sorting=trn_datapair_error_sorted[0][i+1];
		trn_datapair_error_sorted[0][i+1]=trn_datapair_error_sorted[0][i];
		trn_datapair_error_sorted[0][i]=sorting;
		sortingindex = sorting=trn_datapair_error_sorted[1][i+1];
		trn_datapair_error_sorted[1][i+1]=trn_datapair_error_sorted[1][i];
		trn_datapair_error_sorted[1][i]=sortingindex;
		}
		}
		}

		for(j=0; j<training_data_n; j++)
		{
		fprintf(fppp, "\n");		
		fprintf(fppp, "training data pair sorted number \t %d \n", j+1);
		fprintf(fppp, "training data pair original number \t %d \n", (int)(trn_datapair_error_sorted[1][j]));
		fprintf(fppp, "training data pair sorted error in RMSE is \t %lf \n",trn_datapair_error_sorted[0][j]);
		fprintf(fpppp, "%d \t", (int)(trn_datapair_error_sorted[1][j]));
		complexsum = complex(0.0, 0.0);
		fprintf(fppp,"Normalized layer 3 outputs are as follows \n");
		for(k= In_n*Mf_n + Rule_n; k< In_n*Mf_n + 2*Rule_n; k++)
		{
		fprintf(fppp, "%d.\t %lf + i%lf \t %lf < %lf \n", k, (layer_1_to_4_output[j][k]).real,(layer_1_to_4_output[j][k]).imag, c_abs(layer_1_to_4_output[j][k]), c_phase(layer_1_to_4_output[j][k])*180/PI);
		complexsum = c_add(complexsum, layer_1_to_4_output[j][k]);
		}
		
		
		fprintf(fppp, "Sum of the outputs of layer 3 is \t %lf+i%lf \t %lf<%lf \n", complexsum.real, complexsum.imag, c_abs(complexsum), c_phase(complexsum)*180/PI);
		complexsum = complex(0.0, 0.0);
		fprintf(fppp,"dot producted layer 4 outputs are as follows \n");
		for(k=In_n*Mf_n + 2*Rule_n; k< In_n*Mf_n + 3*Rule_n; k++)
		{
		
		fprintf(fppp, "%d.\t %lf + i%lf \t %lf < %lf \n", k, (layer_1_to_4_output[j][k]).real,(layer_1_to_4_output[j][k]).imag, c_abs(layer_1_to_4_output[j][k]), c_phase(layer_1_to_4_output[j][k])*180/PI);
		complexsum = c_add(complexsum, layer_1_to_4_output[j][k]);
		}

		fprintf(fppp, "sum of the outputs of layer 4 is \t %lf +i%lf \t %lf<%lf \n", complexsum.real, complexsum.imag, c_abs(complexsum), c_phase(complexsum)*180/PI);
		if(j> training_data_n -6 )
		{
		trnnumcheck[(int)(trn_datapair_error_sorted[1][j])]= trnnumcheck[(int)(trn_datapair_error_sorted[1][j])] +1;
		}
		if(j<5 )
		{
		trnnumchecku[(int)(trn_datapair_error_sorted[1][j])]= trnnumchecku[(int)(trn_datapair_error_sorted[1][j])] +1;
		}

		}
		fprintf(fpppp, "\n");
		
		//Find RMSE of testing error
/********************************************************************************
if(checking_data_n != 0) 
		{
			printf("testing 3 \n");	
			epoch_checking_error(checking_data_matrix, checking_data_n, chk_error, training_data_n, chk_output, ep_n); //chk_err.c  writes to tracking.txt
			printf("testing 4 \n");	
			chk_rmse_error[ep_n] = chk_error[Out_n];
			for (i=0; i<Out_n; i++)
			printf("%3d \t %.11f \t %.11f\n", ep_n+1, trn_error[i], chk_error[i]);
			printf("%.11f\t %.11f\n", trn_error[Out_n],chk_error[Out_n]);
			write_result(ep_n+1,Out_n,trn_error,chk_error);  //debug.c writes to result.txt
		} 
		else 
		{
			for (i=0; i<Out_n; i++)	
			printf("%4d \t %.11f\n", ep_n+1, trn_error[i]);
		}
**************************************************************************************/

		// check whether the current training RMSE is less than the threhold and store its epch number and parametrs
		
		if(trn_rmse_error[ep_n] < min_trn_RMSE) 
		{
			min_trn_RMSE_epoch = ep_n +1;
			min_trn_RMSE = trn_rmse_error[ep_n];
			min_trnNMSE = trnNMSE[ep_n];
			record_parameter(parameter_array);
		}

		if(ep_n < epoch_n-1)
		{ 
			//update parameters in 1st layer (Using VNCSA)
			update_parameter(1, step_size); //new_para.c
			//update stepsize
			update_step_size(trn_rmse_error, ep_n, &step_size, decrease_rate, increase_rate); //stepsize.c
		}
		ep_n++;
		
	} while((trnNMSE[ep_n -1]>= threshold) && (ep_n <= epoch_n -1));

for(i=1; i<=training_data_n; i++)
{
	fprintf(fpppp, "%d \t %d \n", i, trnnumcheck[i]);
}
for(i=1; i<=training_data_n; i++)
{
	fprintf(fpppp, "%d \t %d \n", i, trnnumchecku[i]);
}


if(trnNMSE[ep_n -1]< threshold)
{
fprintf(fppp, "\n");
fprintf(fppp, "We have gone below the threshold value \n");
fprintf(fppp, "the epoch number in which this happened is %d \n", min_trn_RMSE_epoch);
}
else
{
fprintf(fppp, "\n");
fprintf(fppp, "We exhausted the available epochs and threshold was not broken :( \n");
fprintf(fppp, "the epoch number which yielded minimum training RMSE is %d \n", min_trn_RMSE_epoch);
}


fclose(fppp);
fclose(fpppp);

double *minmaxc;
minmaxc= (double *)calloc(2*In_n, sizeof(double));
	
	if((fpp = fopen("minmax.txt", "r")) == NULL)
	{
		printf("Cannot open 'parameter_file'.\n");
	}

	for(j = 0; j < 2*In_n; j++)
	{
		if(fscanf(fpp, "%lf", &tmp) != EOF) 
		{
				minmaxc[j] = tmp;
				
		} else 		{
			printf("Not enough data in 'input_parameter'!");
		}
	}

	fclose(fpp);
//////////////////////////////////////////////////////////////


	restore_parameter(parameter_array); //output.c
	write_parameter(FINA_PARA_FILE); //output.c
	write_array(trnNMSE, epoch_n, TRAIN_ERR_FILE); //lib.c
	if (checking_data_n != 0)
	{
		//printf("testing 3 \n");	
		epoch_checking_error(checking_data_matrix, checking_data_n, chk_error_n, chk_error_un, training_data_n, chk_output, ep_n -1, minmaxc); //chk_err.c  writes to tracking.txt
		//printf("testing 4 \n");	
		//chk_rmse_error[ep_n] = chk_error[Out_n];
		min_chk_RMSE_n = chk_error_n[Out_n];
		printf(" initial checking RMSE is %lf \n ", min_chk_RMSE_n);
		min_chk_RMSE_un = chk_error_un[Out_n];
		//for (i=0; i<Out_n; i++)
		//printf("%3d \t %.11f \t %.11f\n", ep_n+1, trn_error[i], chk_error[i]);
		//printf("%3d \t %.11f \n", ep_n+1, trn_error[i]);
			//printf("%.11f\t %.11f\n", trn_error[Out_n],chk_error[Out_n]);
		//printf("%.11f\t \n", trn_error[Out_n]);
		//write_result(min_trn_RMSE_epoch ,Out_n,trn_rmse_error,chk_error);  //debug.c writes to result.txt about the epoch number at which the stopping was done and the corresponding training RMSE and checking RMSE
	} 
	//write_array(chk_rmse_error, epoch_n, CHECK_ERR_FILE); //lib.c
	//}
	
	write_array(step_size_array, epoch_n, STEP_SIZE_FILE); //lib.c

/**************************************************************************
	min_chk_RMSE = chk_rmse_error[epoch_n -1];
	min_chk_RMSE_epoch = epoch_n -1;	
	for(j=0; j< epoch_n; j++)
	{
	if(chk_rmse_error[j]< min_chk_RMSE)
	{
	min_chk_RMSE = chk_rmse_error[j];
	min_chk_RMSE_epoch = j;
	}
	}
*************************************************************************/
/**************************************************************
	double minmaxc[2*In_n];
	
	if((fpp = fopen("minmax.txt", "r")) == NULL)
	{
		printf("Cannot open 'parameter_file'.\n");
	}

	for(j = 0; j < 2*In_n; j++)
	{
		if(fscanf(fpp, "%lf", &tmp) != EOF) 
		{
				minmaxc[j] = tmp;
				
		} else 		{
			printf("Not enough data in 'input_parameter'!");
		}
	}

	fclose(fpp);
***************************************************************************/
	for(k=0; k< Out_n; k++)
	{
	for(j=0; j< checking_data_n; j++)
		{
		 checking_data_matrix_un[j][k]= (checking_data_matrix[j][(k+1)*In_vect_n +k])* (minmaxc[(2*k) +1] - minmaxc[2*k]) + minmaxc[2*k];
		}
	}





// the following code calculates the cdavg_un and checking datat average bothe un normalized
for(k=0; k< Out_n; k++)
	{
	for(j=0; j< checking_data_n; j++)
		{
		checking_data_average_un = checking_data_average_un + checking_data_matrix_un[j][k];
		}
	cdavg_un[k]=checking_data_average_un/checking_data_n;
	checking_data_average_un_temp=checking_data_average_un_temp+checking_data_average_un;
	checking_data_average_un=0;
		}
	
	checking_data_average_un = checking_data_average_un_temp/(Out_n*checking_data_n);
	printf("%lf is the checking datat average non normalized\n", checking_data_average_un);





// the following code calcuates the chkvar_un un normalized 
for(k=0; k< Out_n; k++)
	{	
	for(j=0; j< checking_data_n; j++)
		{				
		temp= temp + (checking_data_matrix_un[j][k] - cdavg_un[k])*(checking_data_matrix_un[j][k] - cdavg_un[k]);
		}
	chkvar_un[k]=temp/(checking_data_n-1);
	//checking_variance_un = checking_variance_un + temp;
	temp=0;
	}




temp =0.0;
// the following code cacluates the un normalized checking varinace
for(j=0; j< checking_data_n; j++)
	{
	for(k=0; k< Out_n; k++)
		{
		temp = checking_data_matrix_un[j][k] - checking_data_average_un;
		temp = temp*temp;
		checking_variance_un = checking_variance_un + temp;
		}
	}
	checking_variance_un = checking_variance_un/((Out_n*checking_data_n)-1);
	printf("%lf is the checking variance non normalized \n", checking_variance_un);

temp =0.0;




checking_data_average_n=0.0;
checking_data_average_n_temp=0.0;
// the following code calculates the cdavg and checking data average both normalized
for(k=0; k< Out_n; k++)
	{	
for(j=0; j< checking_data_n; j++)
		{		
		checking_data_average_n = checking_data_average_n + checking_data_matrix[j][(k+1)*In_vect_n +k];
		}
		cdavg[k]=checking_data_average_n/checking_data_n;
		checking_data_average_n_temp=checking_data_average_n_temp+checking_data_average_n;
		checking_data_average_n=0;
	}
	checking_data_average_n = checking_data_average_n_temp/(Out_n*checking_data_n);
	printf("%lf is the checking datat average  normalized\n", checking_data_average_n);


temp =0.0;
checking_variance_n =0.0;
// the following code cacluates the normalized checking varinace
for(j=0; j< checking_data_n; j++)
	{
	for(k=0; k< Out_n; k++)
		{
		temp = checking_data_matrix[j][(k+1)*In_vect_n +k] - checking_data_average_n;
		temp = temp*temp;
		checking_variance_n = checking_variance_n + temp;
		}
	}
checking_variance_n = checking_variance_n/((Out_n*checking_data_n)-1);
temp = 0.0;
printf("%lf is the checking variance normalized \n", checking_variance_n);



// the following code calcuatres the normalized chkvar[k]
temp=0.0;
for(k=0; k< Out_n; k++)
	{
	for(j=0; j< checking_data_n; j++)
		{	
		temp= temp + (checking_data_matrix[j][(k+1)*In_vect_n +k] - cdavg[k])*(checking_data_matrix[j][(k+1)*In_vect_n +k] - cdavg[k]);
	}
	chkvar[k]=temp/(checking_data_n-1);
	//checking_variance_n = checking_variance_n + temp;
	temp=0;
	}


	
	
	

	NMSE_un = min_chk_RMSE_un * min_chk_RMSE_un / checking_variance_un;
	NMSE_n = min_chk_RMSE_n * min_chk_RMSE_n / checking_variance_n;
	NMSE_n2 = min_chk_RMSE_n * min_chk_RMSE_n / chkvariance;
	NDEI_un = sqrt(NMSE_un);
	NDEI_n = sqrt(NMSE_n);




	for(k=0;k<Out_n;k++)
	{
	NMSE[k]=chk_error_n[k]*chk_error_n[k]/chkvar[k];
	NDEI[k]=sqrt(NMSE[k]);
	unNMSE[k]=chk_error_un[k]*chk_error_un[k]/chkvar_un[k];
	unNDEI[k]=sqrt(unNMSE[k]);
	}






	write_result(min_trn_RMSE_epoch ,Out_n,trn_rmse_error,chk_error_un, chk_error_n, NDEI_un, NMSE_un, NDEI_n, NMSE_n, NMSE, NDEI, unNMSE, unNDEI); //debug.c writes to result.txt about the epoch number at which the stopping was done and the corresponding training RMSE and checking RMSE
	printf("Minimum training RMSE is \t %f \t \n",min_trn_RMSE); 
	printf("Minimum training RMSE epoch is \t %d \n",min_trn_RMSE_epoch); 
	printf("Minimum training NMSE is \t %f \t \n",min_trnNMSE); 
	//printf("Minimum training RMSE epoch is \t %d \n",min_trnNMSE_epoch); 
	//printf("Minimum training RMSE is \t %f \t \n",min_trn_RMSE); 
	//printf("Minimum training RMSE epoch is \t %d \n",min_trn_RMSE_epoch); 
	printf("%f \t is the checking RMSE non normalized\n",min_chk_RMSE_un);
	printf("%f \t is the checking RMSE normalized\n",min_chk_RMSE_n);
	//printf("%f \t is the checking RMSE normalized22222222 \n",min_chk_RMSE_n2);
	printf(" checking NMSE non normlized is %f \t NDEI non normalized is %f \n",NMSE_un, NDEI_un); 
	printf("checking NMSE normalized is %f \t NDEI normalized is %f \n",NMSE_n, NDEI_n); 
	printf("checking NMSE2 normalized is %f \n",NMSE_n2); 
	printf("traning data variance is  %f \n",trnvariance); 
	return(0);
Beispiel #18
0
int est_load_cacerts(struct hs20_osu_client *ctx, const char *url)
{
	char *buf, *resp;
	size_t buflen;
	unsigned char *pkcs7;
	size_t pkcs7_len, resp_len;
	int res;

	buflen = os_strlen(url) + 100;
	buf = os_malloc(buflen);
	if (buf == NULL)
		return -1;

	os_snprintf(buf, buflen, "%s/cacerts", url);
	wpa_printf(MSG_INFO, "Download EST cacerts from %s", buf);
	write_summary(ctx, "Download EST cacerts from %s", buf);
	ctx->no_osu_cert_validation = 1;
	http_ocsp_set(ctx->http, 1);
	res = http_download_file(ctx->http, buf, "Cert/est-cacerts.txt",
				 ctx->ca_fname);
	http_ocsp_set(ctx->http,
		      (ctx->workarounds & WORKAROUND_OCSP_OPTIONAL) ? 1 : 2);
	ctx->no_osu_cert_validation = 0;
	if (res < 0) {
		wpa_printf(MSG_INFO, "Failed to download EST cacerts from %s",
			   buf);
		write_result(ctx, "Failed to download EST cacerts from %s",
			     buf);
		os_free(buf);
		return -1;
	}
	os_free(buf);

	resp = os_readfile("Cert/est-cacerts.txt", &resp_len);
	if (resp == NULL) {
		wpa_printf(MSG_INFO, "Could not read Cert/est-cacerts.txt");
		write_result(ctx, "Could not read EST cacerts");
		return -1;
	}

	pkcs7 = base64_decode((unsigned char *) resp, resp_len, &pkcs7_len);
	if (pkcs7 && pkcs7_len < resp_len / 2) {
		wpa_printf(MSG_INFO, "Too short base64 decode (%u bytes; downloaded %u bytes) - assume this was binary",
			   (unsigned int) pkcs7_len, (unsigned int) resp_len);
		os_free(pkcs7);
		pkcs7 = NULL;
	}
	if (pkcs7 == NULL) {
		wpa_printf(MSG_INFO, "EST workaround - Could not decode base64, assume this is DER encoded PKCS7");
		pkcs7 = os_malloc(resp_len);
		if (pkcs7) {
			os_memcpy(pkcs7, resp, resp_len);
			pkcs7_len = resp_len;
		}
	}
	os_free(resp);

	if (pkcs7 == NULL) {
		wpa_printf(MSG_INFO, "Could not fetch PKCS7 cacerts");
		write_result(ctx, "Could not fetch EST PKCS#7 cacerts");
		return -1;
	}

	res = pkcs7_to_cert(ctx, pkcs7, pkcs7_len, "Cert/est-cacerts.pem",
			    NULL);
	os_free(pkcs7);
	if (res < 0) {
		wpa_printf(MSG_INFO, "Could not parse CA certs from PKCS#7 cacerts response");
		write_result(ctx, "Could not parse CA certs from EST PKCS#7 cacerts response");
		return -1;
	}
	unlink("Cert/est-cacerts.txt");

	return 0;
}
Beispiel #19
0
static int pkcs7_to_cert(struct hs20_osu_client *ctx, const u8 *pkcs7,
			 size_t len, char *pem_file, char *der_file)
{
#ifdef OPENSSL_IS_BORINGSSL
	CBS pkcs7_cbs;
#else /* OPENSSL_IS_BORINGSSL */
	PKCS7 *p7 = NULL;
	const unsigned char *p = pkcs7;
#endif /* OPENSSL_IS_BORINGSSL */
	STACK_OF(X509) *certs;
	int i, num, ret = -1;
	BIO *out = NULL;

#ifdef OPENSSL_IS_BORINGSSL
	certs = sk_X509_new_null();
	if (!certs)
		goto fail;
	CBS_init(&pkcs7_cbs, pkcs7, len);
	if (!PKCS7_get_certificates(certs, &pkcs7_cbs)) {
		wpa_printf(MSG_INFO, "Could not parse PKCS#7 object: %s",
			   ERR_error_string(ERR_get_error(), NULL));
		write_result(ctx, "Could not parse PKCS#7 object from EST");
		goto fail;
	}
#else /* OPENSSL_IS_BORINGSSL */
	p7 = d2i_PKCS7(NULL, &p, len);
	if (p7 == NULL) {
		wpa_printf(MSG_INFO, "Could not parse PKCS#7 object: %s",
			   ERR_error_string(ERR_get_error(), NULL));
		write_result(ctx, "Could not parse PKCS#7 object from EST");
		goto fail;
	}

	switch (OBJ_obj2nid(p7->type)) {
	case NID_pkcs7_signed:
		certs = p7->d.sign->cert;
		break;
	case NID_pkcs7_signedAndEnveloped:
		certs = p7->d.signed_and_enveloped->cert;
		break;
	default:
		certs = NULL;
		break;
	}
#endif /* OPENSSL_IS_BORINGSSL */

	if (!certs || ((num = sk_X509_num(certs)) == 0)) {
		wpa_printf(MSG_INFO, "No certificates found in PKCS#7 object");
		write_result(ctx, "No certificates found in PKCS#7 object");
		goto fail;
	}

	if (der_file) {
		FILE *f = fopen(der_file, "wb");
		if (f == NULL)
			goto fail;
		i2d_X509_fp(f, sk_X509_value(certs, 0));
		fclose(f);
	}

	if (pem_file) {
		out = BIO_new(BIO_s_file());
		if (out == NULL ||
		    BIO_write_filename(out, pem_file) <= 0)
			goto fail;

		for (i = 0; i < num; i++) {
			X509 *cert = sk_X509_value(certs, i);
			X509_print(out, cert);
			PEM_write_bio_X509(out, cert);
			BIO_puts(out, "\n");
		}
	}

	ret = 0;

fail:
#ifdef OPENSSL_IS_BORINGSSL
	if (certs)
		sk_X509_pop_free(certs, X509_free);
#else /* OPENSSL_IS_BORINGSSL */
	PKCS7_free(p7);
#endif /* OPENSSL_IS_BORINGSSL */
	if (out)
		BIO_free_all(out);

	return ret;
}
Beispiel #20
0
int main(int argc, char *argv[ ]) {

     FILE *modelIn, *dataIn, *out;


          init_data(example, sv, lambda, svNonZeroFeature, nonZeroFeature, target, weight, output, zeroFeatureExample, rbfConstant, degree
                    , b, numSv, numExample, kernelType, maxFeature);

          char* mfile = "C:\\Users\\Owner\\Desktop\\SVM\\SMO\\smosynth\\smosynth\\linear_results\\model.dat";

           if(( modelIn = fopen( mfile, "r" ) ) == ((void *)0) ) {
            fprintf( (&_iob[2]), "Can't open %s\n", mfile);
             exit(2);
           }

           char* tfile = "C:\\Users\\Owner\\Desktop\\SVM\\SMO\\smosynth\\smosynth\\linear_results\\test.dat";

           if(( dataIn = fopen( tfile, "r" ) ) == ((void *)0) ) {
               fprintf( (&_iob[2]), "Can't open %s\n", tfile );
               exit(2);
           }

           char* pfile = "C:\\Users\\Owner\\Desktop\\SVM\\SMO\\smosynth\\smosynth\\linear_results\\pred.dat";
         if(( out = fopen( pfile, "w" ) ) == ((void *)0) ) {
           fprintf( (&_iob[2]), "Can't open %s\n", pfile );
           exit(2);
         }

           if( ! readModel( modelIn, example, sv, lambda, svNonZeroFeature, nonZeroFeature, target, weight, output, zeroFeatureExample, rbfConstant, degree
                    , b, numSv, numExample, kernelType, maxFeature ) ) {
              fprintf( (&_iob[2]), "Error in reading model file %s\n", mfile );
              exit (3);
           } else fclose( modelIn );
            printf("Finish reading model file\n");

         if( !readData( dataIn, example, sv, lambda, svNonZeroFeature, nonZeroFeature, target, weight, output, zeroFeatureExample, rbfConstant, degree
                    , b, numSv, numExample, kernelType, maxFeature )) {
            printf("Error reading data file\n");
            exit(4);
         }
           fclose( dataIn );
           printf("Finish reading test data file\n");

          int ret=synth_top(example, sv, lambda, svNonZeroFeature, nonZeroFeature, weight, output, 0);

           if ( ret==0 )
             printf("Classification is completed\n");
           else
           fprintf( (&_iob[2]), "Classification process failed\n");

       write_result(out, output, b);

       fclose( out );

         ret = diff_files();
        printf("RETURN VALUE %d\n", ret);

   if (ret != 0) {
      printf("Test failed %d!!!\n", ret);
      return 1;
   } else {
      printf("Test passed %d!\n", ret);
      return 0;
   }

}
Beispiel #21
0
void similarity_for_set(
    unsigned int set_index,
    FILE* fout,
    float good_threshold,
    unsigned int* set_ids,
    unsigned int set_id_count,
    unsigned int* indexptr,
    unsigned int* arraysptr,
    struct fileinfo arrays) {

  clock_t started_at = clock();
  unsigned int set_id_a = set_ids[set_index],
               set_id_b, set_a_length;
  unsigned int *set_a_start, *set_a_end, *set_b_start, *set_b_end;
  // be super careful to subtract addresses and not sizeof(int) quantities
  set_a_start = (unsigned int*)((char*)arraysptr + indexptr[set_id_a]);
  if (set_index + 1 == set_id_count) {
    set_a_end = (unsigned int*)((char*)arraysptr + arrays.filesize);
  } else {
	  set_a_end = (unsigned int*)((char*)arraysptr + indexptr[set_ids[set_index+1]]);
  }
  set_a_length = (unsigned int)((char*)set_a_end - (char*)set_a_start);

  if (set_a_start == set_a_end) { return; }

  // goodmatches is a basic heuristic for preventing any set_a's iteration
  // from taking too long. Once sampling is effective, this can be removed
  unsigned short int goodmatches = 0;
  for (int b = set_index + 1; b < set_id_count; b++) {
    // We don't compare sets to themselves.
    if (set_index == b) { continue; }

    set_id_b = set_ids[b];
    set_b_start = (unsigned int*)((char*)arraysptr + indexptr[set_id_b]);
    if (set_index + 1 == set_id_count) {
      set_b_end = (unsigned int*)((char*)arraysptr + arrays.filesize);
    } else {
      set_b_end = (unsigned int*)((char*)arraysptr + indexptr[set_ids[b+1]]);
    }

    unsigned int intersection_count = set_intersection(
      set_a_start, set_a_end, set_b_start, set_b_end
    );

    // Calculate the percentage of set_a that intersects with set_b.
    double intersection_percent = ((double) intersection_count)/set_a_length;
    // record "good" matches
    if (intersection_percent >= good_threshold) {
      write_result(fout, set_id_a, set_id_b, intersection_percent);
      ++goodmatches;
      // early out when we have "enough" good matches
      if (goodmatches >= 100) { break; }
    }
  }
  printf(
    "%9u %9u %9u %20d %20.4f \n",
    (unsigned int)getpid(),
    set_id_a, set_a_length,
    goodmatches,
    ((float)clock() - started_at) / CLOCKS_PER_SEC
  );
}
Beispiel #22
0
int main( int argc, char *argv[] ) {
    if ( argc < 4 ) {
        printf( "Usage: %s format_file input_file output_file\n", argv[0] );
        return EXIT_FAILURE;
    }

    // For checking the library initialisation
    int retval;

    // EventSet for L2 & L3 cache misses and accesses
    int EventSet = PAPI_NULL;
    int EventSet1 = PAPI_NULL;

    // Data pointer for getting the cpu info
    const PAPI_hw_info_t * hwinfo = NULL;

    PAPI_mh_info_t mem_hrch;

    // Initialising the library
    retval = PAPI_library_init( PAPI_VER_CURRENT );

    if ( retval != PAPI_VER_CURRENT ) {
        printf( "Initialisation of Papi failed \n" );
        exit( 1 );
    }

    if ( ( hwinfo = PAPI_get_hardware_info() ) == NULL ) {
        printf( "Unable to access hw info \n" );
        return 1;
    }

    /* Accessing the cpus per node, threads per core, memory, frequency */
    printf( "No. of cpus in one node : %d \n", hwinfo->ncpu );
    printf( "Threads per core : %d \n", hwinfo->threads );
    printf( "No. of cores per socket : %d \n", hwinfo->cores );
    printf( "No. of sockets : %d \n", hwinfo->sockets );
    printf( "Total CPUS in the entire system : %d \n", hwinfo->totalcpus );

    /* Variables for reading counters of EventSet*/
    long long eventValues[NUMEVENTS] = { 0 };
    // long long eventFpValue[ NUM_FPEVENTS ] = {0};

    char *format = argv[1];
    char *file_in = argv[2];
    char *file_out = argv[3];

    char delim[] = ".";
    char *cp = (char *) malloc( sizeof(char) * 10 );
    cp = strcpy( cp, file_in );
    char *token = malloc( sizeof(char) * 10 );
    token = strtok( cp, delim );
    char * res_file = malloc( sizeof(char) * 30 );
    res_file = strcpy( res_file, file_out );
    res_file = strcat( res_file, token );
    free( cp );
    // free( token );
    char *csv_file = malloc( sizeof(char) * 30 );
    csv_file = strcpy( csv_file, res_file );

    FILE *csv_fp = fopen( strcat( csv_file, OPTI ), "w" );
    FILE *res_fp = fopen( strcat( res_file, "_psdats.dat" ), "w" );
    int status = 0;
    free( res_file );
    free( csv_file );

    /** internal cells start and end index*/
    int nintci, nintcf;
    /** external cells start and end index. The external cells are only ghost cells.
     * They are accessed 	only through internal cells*/
    int nextci, nextcf;
    /** link cell-to-cell array. Stores topology information*/
    int **lcc;
    /** red-black colouring of the cells*/
    int *nboard;

    /** boundary coefficients for each volume cell */
    double *bs, *be, *bn, *bw, *bl, *bh, *bp, *su;

    // Parameters for measuring the time
    long long startusec, endusec;

    /*the total number of points (after conversion to unstructured mesh topology)*/
    int nodeCnt;
    /* the array containing the coordinate of the points
     * (after conversion to unstructured mesh topology) */
    int **points;
    /* the array containing the mesh elements (after conversion to unstructured mesh topology) */
    int **elems;

    // Creating the eventSets
    if ( PAPI_create_eventset( &EventSet ) != PAPI_OK ) {
        printf( "Problem in create eventset \n" );
        exit( 1 );
    }

    // Create the Flops eventSet
    /*if ( PAPI_create_eventset( &EventSet1 ) != PAPI_OK ) {
     printf( "Problem in creating the flops eventset \n" );
     exit(1);
     }*/

    int EventCode[NUMEVENTS] = { PAPI_L2_TCM, PAPI_L2_TCA, PAPI_L3_TCM, PAPI_L3_TCA };
    // int EventFpCode[ NUM_FPEVENTS ] = { PAPI_FP_OPS };

    // Adding events to the eventset
    if ( PAPI_add_events( EventSet, EventCode, NUMEVENTS ) != PAPI_OK ) {
        printf( "Problem in adding events \n" );
        exit( 1 );
    }
    /*if( PAPI_add_events( EventSet1, EventFpCode, 1 ) != PAPI_OK ){
     printf( "Problem in adding the flops event \n" );
     exit( 1 );
     }*/
    printf( "Success in adding events \n" );

    // Start the eventset counters
    PAPI_start( EventSet );
    // PAPI_start( EventSet1 );

    startusec = PAPI_get_real_usec();

    /* initialization  */
    // read-in the input file
    int f_status;
    if ( !strcmp( format, "bin" ) ) {
        f_status = read_bin_formatted( file_in, &nintci, &nintcf, &nextci, &nextcf, &lcc, &bs, &be,
                                       &bn, &bw, &bl, &bh, &bp, &su, &nboard );
    } else if ( !strcmp( format, "txt" ) ) {
        f_status = read_formatted( file_in, &nintci, &nintcf, &nextci, &nextcf, &lcc, &bs, &be, &bn,
                                   &bw, &bl, &bh, &bp, &su, &nboard );
    }

    if ( f_status != 0 ) {
        printf( "failed to initialize data! \n" );
        return EXIT_FAILURE;
    }

    // allocate arrays used in gccg
    int nomax = 3;
    /** the reference residual*/
    double resref = 0.0;
    /** the ratio between the reference and the current residual*/
    double ratio;

    /** array storing residuals */
    double* resvec = (double *) calloc( sizeof(double), ( nintcf + 1 ) );
    /** the variation vector -> keeps the result in the end */
    double* var = (double *) calloc( sizeof(double), ( nextcf + 1 ) );

    /** the computation vectors */
    double* direc1 = (double *) calloc( sizeof(double), ( nextcf + 1 ) );
    double* direc2 = (double *) calloc( sizeof(double), ( nextcf + 1 ) );

    /** additional vectors */
    double* cgup = (double *) calloc( sizeof(double), ( nextcf + 1 ) );
    double* oc = (double *) calloc( sizeof(double), ( nintcf + 1 ) );
    double* cnorm = (double *) calloc( sizeof(double), ( nintcf + 1 ) );
    double* adxor1 = (double *) calloc( sizeof(double), ( nintcf + 1 ) );
    double* adxor2 = (double *) calloc( sizeof(double), ( nintcf + 1 ) );
    double* dxor1 = (double *) calloc( sizeof(double), ( nintcf + 1 ) );
    double* dxor2 = (double *) calloc( sizeof(double), ( nintcf + 1 ) );

    // initialize the reference residual
    for ( int nc = nintci; nc <= nintcf; nc++ ) {
        resvec[nc] = su[nc];
        resref = resref + resvec[nc] * resvec[nc];
    }
    resref = sqrt( resref );
    if ( resref < 1.0e-15 ) {
        printf( "i/o - error: residue sum less than 1.e-15 - %lf\n", resref );
        return EXIT_FAILURE;
    }

    // initialize the arrays
    for ( int nc = 0; nc <= 10; nc++ ) {
        oc[nc] = 0.0;
        cnorm[nc] = 1.0;
    }

    for ( int nc = nintci; nc <= nintcf; nc++ ) {
        cgup[nc] = 0.0;
        var[nc] = 0.0;
    }

    for ( int nc = nextci; nc <= nextcf; nc++ ) {
        var[nc] = 0.0;
        cgup[nc] = 0.0;
        direc1[nc] = 0.0;
        bs[nc] = 0.0;
        be[nc] = 0.0;
        bn[nc] = 0.0;
        bw[nc] = 0.0;
        bl[nc] = 0.0;
        bh[nc] = 0.0;
    }

    for ( int nc = nintci; nc <= nintcf; nc++ )
        cgup[nc] = 1.0 / bp[nc];

    int if1 = 0;
    int if2 = 0;
    int iter = 1;
    int nor = 1;
    int nor1 = nor - 1;
    /* finished initalization */

    endusec = PAPI_get_real_usec();

    // Read the eventSet counters
    PAPI_read( EventSet, eventValues );
    // PAPI_read( EventSet1, eventFpValue );

    fprintf( res_fp, "Execution time in microseconds for the initialisation: %lld \n",
             endusec - startusec );
    fprintf( res_fp, "Initialisation.... \n" );
    fprintf( res_fp, "INPUT \t PAPI_L2_TCM \t %lld \n", eventValues[0] );
    fprintf( res_fp, "INPUT \t PAPI_L2_TCA \t %lld \n", eventValues[1] );
    fprintf( res_fp, "INPUT \t PAPI_L3_TCM \t %lld \n", eventValues[2] );
    fprintf( res_fp, "INPUT \t PAPI_L3_TCA \t %lld \n", eventValues[3] );
    // fprintf( res_fp, "INPUT \t PAPI_FP_OPS \t %lld \n", eventFpValue[0] );

    // Cache miss rate calculations
    float L2_cache_miss_rate, L3_cache_miss_rate;
    L2_cache_miss_rate = ( (float) eventValues[0] / eventValues[1] ) * 100;
    L3_cache_miss_rate = ( (float) eventValues[2] / eventValues[3] ) * 100;
    fprintf( res_fp, "INPUT \t L2MissRate \t %f% \n", L2_cache_miss_rate );
    fprintf( res_fp, "INPUT \t L3MissRate \t %f% \n", L3_cache_miss_rate );

    fprintf( csv_fp, "Results for the INPUT phase \n" );
    fprintf( csv_fp, "%s, %lld, %lld, %lld, %lld, %f, %f \n", OPTI, eventValues[0], eventValues[1],
             eventValues[2], eventValues[3], L2_cache_miss_rate, L3_cache_miss_rate );

    // Resetting the event counters
    PAPI_reset( EventSet );
    // PAPI_reset( EventSet1 );

    fprintf( res_fp, "Starting with the computation part \n" );
    startusec = PAPI_get_real_usec();

    /* start computation loop */
    while ( iter < 10000 ) {
        /* start phase 1 */

        // update the old values of direc
        for ( int nc = nintci; nc <= nintcf; nc++ ) {
            direc1[nc] = direc1[nc] + resvec[nc] * cgup[nc];
        }

        // compute new guess (approximation) for direc
        for ( int nc = nintci; nc <= nintcf; nc++ ) {
            direc2[nc] = bp[nc] * direc1[nc] - bs[nc] * direc1[lcc[0][nc]]
                    - bw[nc] * direc1[lcc[3][nc]] - bl[nc] * direc1[lcc[4][nc]]
                    - bn[nc] * direc1[lcc[2][nc]] - be[nc] * direc1[lcc[1][nc]]
                    - bh[nc] * direc1[lcc[5][nc]];
        } /* end phase 1 */

        /*  start phase 2 */
        // execute normalization steps
        double oc1, oc2, occ;
        if ( nor1 == 1 ) {
            oc1 = 0;
            occ = 0;
            for ( int nc = nintci; nc <= nintcf; nc++ ) {
                occ = occ + adxor1[nc] * direc2[nc];
            }
            oc1 = occ / cnorm[1];
            for ( int nc = nintci; nc <= nintcf; nc++ ) {
                direc2[nc] = direc2[nc] - oc1 * adxor1[nc];
                direc1[nc] = direc1[nc] - oc1 * dxor1[nc];
            }
            if1++;

        } else if ( nor1 == 2 ) {
            oc1 = 0;
            occ = 0;
            for ( int nc = nintci; nc <= nintcf; nc++ )
                occ = occ + adxor1[nc] * direc2[nc];

            oc1 = occ / cnorm[1];
            oc2 = 0;
            occ = 0;
            for ( int nc = nintci; nc <= nintcf; nc++ )
                occ = occ + adxor2[nc] * direc2[nc];

            oc2 = occ / cnorm[2];
            for ( int nc = nintci; nc <= nintcf; nc++ ) {
                direc2[nc] = direc2[nc] - oc1 * adxor1[nc] - oc2 * adxor2[nc];
                direc1[nc] = direc1[nc] - oc1 * dxor1[nc] - oc2 * dxor2[nc];
            }

            if2++;
        }

        cnorm[nor] = 0;
        double omega = 0;

        // compute the new residual
        for ( int nc = nintci; nc <= nintcf; nc++ ) {
            cnorm[nor] = cnorm[nor] + direc2[nc] * direc2[nc];
            omega = omega + resvec[nc] * direc2[nc];
        }
        omega = omega / cnorm[nor];

        double resnew = 0.0;
        for ( int nc = nintci; nc <= nintcf; nc++ ) {
            var[nc] = var[nc] + omega * direc1[nc];
            resvec[nc] = resvec[nc] - omega * direc2[nc];
            resnew = resnew + resvec[nc] * resvec[nc];
        }
        resnew = sqrt( resnew );
        ratio = resnew / resref;

        // exit on no improvements of residual
        if ( ratio <= 1.0e-10 )
            break;

        iter++;

        // prepare additional arrays for the next iteration step
        if ( nor == nomax )
            nor = 1;
        else {
            if ( nor == 1 ) {
                for ( int nc = nintci; nc <= nintcf; nc++ ) {
                    dxor1[nc] = direc1[nc];
                    adxor1[nc] = direc2[nc];
                }

            } else if ( nor == 2 ) {
                for ( int nc = nintci; nc <= nintcf; nc++ ) {
                    dxor2[nc] = direc1[nc];
                    adxor2[nc] = direc2[nc];
                }
            }
            nor++;
        }
        nor1 = nor - 1;

    }/* end phase 2 */

    /* finished computation loop */
    endusec = PAPI_get_real_usec();

    // Read the eventSet counters
    PAPI_read( EventSet, eventValues );
    // PAPI_read( EventSet1, eventFpValue );

    fprintf( res_fp, "Execution time in microseconds for the computation : %lld \n",
             endusec - startusec );
    fprintf( res_fp, "CALC \t PAPI_L2_TCM \t %lld \n", eventValues[0] );
    fprintf( res_fp, "CALC \t PAPI_L2_TCA \t %lld \n", eventValues[1] );
    fprintf( res_fp, "CALC \t PAPI_L3_TCM \t %lld \n", eventValues[2] );
    fprintf( res_fp, "CALC \t PAPI_L3_TCA \t %lld \n", eventValues[3] );
    // fprintf( res_fp, "CALC \t PAPI_FP_OPS \t %lld \n", eventFpValue[0] );

    L2_cache_miss_rate = ( (float) eventValues[0] / eventValues[1] ) * 100;
    L3_cache_miss_rate = ( (float) eventValues[2] / eventValues[3] ) * 100;
    fprintf( res_fp, "CALC \t L2MissRate \t %f%\n", L2_cache_miss_rate );
    fprintf( res_fp, "CALC \t L3MissRate \t %f%\n", L3_cache_miss_rate );

    fprintf( csv_fp, "Results for the CALC phase \n" );
    fprintf( csv_fp, "%s, %lld, %lld, %lld, %lld, %f, %f \n", OPTI, eventValues[0], eventValues[1],
             eventValues[2], eventValues[3], L2_cache_miss_rate, L3_cache_miss_rate );

    // Resetting the event counters
    PAPI_reset( EventSet );
    // PAPI_reset( EventSet1 );

    char *vtk_file = malloc( sizeof(char) * 30 );

    fprintf( res_fp, "Starting with the output vtk part \n" );
    startusec = PAPI_get_real_usec();

    /* write output file  */
    vol2mesh( nintci, nintcf, lcc, &nodeCnt, &points, &elems );

    if( write_result( file_in, file_out, nintci, nintcf, var, iter, ratio ) != 0 ) {
        printf( "error when trying to write to file %s\n", file_out );
    }

    if( write_result_vtk( strcat( strcpy( vtk_file, file_out ), "SU.vtk" ), nintci, nintcf, nodeCnt,
                          points, elems, su ) != 0 ) {
        printf( "error when trying to write to vtk file %s\n", "SU.vtk" );
    }

    if( write_result_vtk( strcat( strcpy( vtk_file, file_out ), "CGUP.vtk" ), nintci, nintcf,
                          nodeCnt, points, elems, cgup ) != 0 ) {
        printf( "error when trying to write to vtk file %s\n", "CGUP.vtk" );
    }

    if( write_result_vtk( strcat( strcpy( vtk_file, file_out ), "VAR.vtk" ), nintci, nintcf,
                          nodeCnt, points, elems, var ) != 0 ) {
        printf( "error when trying to write to vtk file %s\n", "VAR.vtk" );
    }

    free( vtk_file );

    /* finished computation loop */
    endusec = PAPI_get_real_usec();

    // Read the eventSet counters
    PAPI_stop( EventSet, eventValues );
    // PAPI_stop( EventSet1, eventFpValue );

    fprintf( res_fp, "Execution time in microseconds for the output vtk part : %lld \n",
             endusec - startusec );
    fprintf( res_fp, "OUTPUT \t PAPI_L2_TCM \t %lld \n", eventValues[0] );
    fprintf( res_fp, "OUTPUT \t PAPI_L2_TCA \t %lld \n", eventValues[1] );
    fprintf( res_fp, "OUTPUT \t PAPI_L3_TCM \t %lld \n", eventValues[2] );
    fprintf( res_fp, "OUTPUT \t PAPI_L3_TCA \t %lld \n", eventValues[3] );
    // fprintf( res_fp, "CALC \t PAPI_FP_OPS \t %lld \n", eventFpValue[0] );

    L2_cache_miss_rate = ( (float) eventValues[0] / eventValues[1] ) * 100;
    L3_cache_miss_rate = ( (float) eventValues[2] / eventValues[3] ) * 100;
    fprintf( res_fp, "OUTPUT \t L2MissRate \t %f%\n", L2_cache_miss_rate );
    fprintf( res_fp, "OUTPUT \t L3MissRate \t %f%\n", L3_cache_miss_rate );

    fprintf( csv_fp, "Results for the OUTPUT phase \n" );
    fprintf( csv_fp, "%s, %lld, %lld, %lld, %lld, %f, %f \n", OPTI, eventValues[0], eventValues[1],
             eventValues[2], eventValues[3], L2_cache_miss_rate, L3_cache_miss_rate );

    /* Free all the dynamically allocated memory */
    free( direc2 );
    free( direc1 );
    free( dxor2 );
    free( dxor1 );
    free( adxor2 );
    free( adxor1 );
    free( cnorm );
    free( oc );
    free( var );
    free( cgup );
    free( resvec );
    free( su );
    free( bp );
    free( bh );
    free( bl );
    free( bw );
    free( bn );
    free( be );
    free( bs );

    printf( "Simulation completed successfully!\n" );

    fclose( res_fp );
    fclose( csv_fp );
    return EXIT_SUCCESS;
}
Beispiel #23
0
/*-------------------------------------*/
void save_result (char *source, char *obj_file, char type, char *prefix, char *clean2, char *contam2)
{
  char *so = NULL, *obj = NULL;
  char *match = (char *)calloc(4 * ONE, sizeof (char)),
       *mismatch = (char *)calloc(4 * ONE, sizeof (char)),
       *so_name = (char *)calloc(4 * ONE, sizeof (char)),
       *obj_name = (char *)calloc(4 * ONE, sizeof (char));
  so = strrchr (source, '/');
  obj = strrchr (obj_file, '/');
  if (so)
  	so += 1;
  else
  	so = NULL;
  if (obj)
  	obj += 1;
  else
  	obj = NULL;
  if (so)
  	strncat (so_name, so, strrchr (source, '.') - so);
  else
  	strncat (so_name, source, strrchr (source, '.') - source);
  if (obj)
  	strncat (obj_name, obj, strrchr (obj_file, '.') - obj);
  else
  	strncat (obj_name, obj_file, strrchr (obj_file, '.') - obj_file);
  if (prefix)
  {
  	strcat (match, prefix);
  	strcat (mismatch, prefix);
  }
  else if (so)
  {
  	strncat (match, source, so - source);
  	strncat (mismatch, source, so - source);
  }
  strcat (match, so_name);
  strcat (mismatch, so_name);
  strcat (match, "_");
  strcat (mismatch, "_");
  strcat (match, obj_name);
  strcat (mismatch, obj_name);
  strcat (match, "_contam");
  strcat (mismatch, "_clean");
  if (type == '>')
  {
  	strcat (match, ".fasta");
  	strcat (mismatch, ".fasta");
  }
  else
  {
  	strcat (match, ".fastq");
  	strcat (mismatch, ".fastq");
  }
  printf ("match->%s\n", match);
  printf ("mis->%s\n", mismatch);
  write_result (match, contam2);
  write_result (mismatch, clean2);
  memset(contam2,0,strlen(contam2));
  memset(clean2,0,strlen(clean2));

  free (match);
  free (mismatch);
  free (so_name);
  free (obj_name);
}
Beispiel #24
0
int main(int argc, char *argv[])
{
    if (argc < 4) {
        printf("Usage: %s <format> <input_file> <output_file_prefix>\n", argv[0]);
        return EXIT_FAILURE;
    }

    char *format = argv[1];
    char *file_in = argv[2];
    char *file_out = argv[3];

    int status = 0;

    /** internal cells start and end index*/
    int nintci, nintcf;
    /** external cells start and end index. The external cells are only ghost 
     * cells. They are accessed only through internal cells*/
    int nextci, nextcf;
    /** link cell-to-cell array. Stores topology information*/
    int **lcc;
    /** red-black colouring of the cells*/
    int *nboard;

    /** boundary coefficients for each volume cell */
    double *bs, *be, *bn, *bw, *bl, *bh, *bp, *su;

    const PAPI_hw_info_t* hw_info = PAPI_get_hardware_info();

    if ( test_start() != 0 ) exit(1);


    /************************************************************/
    /* initialization  */
    // read-in the input file
    int f_status;

    if (strcmp(format, "text") == 0) 
        f_status = read_formatted(file_in, &nintci, &nintcf, &nextci, &nextcf, 
                                  &lcc, &bs, &be, &bn, &bw, &bl, &bh, &bp, &su, 
                                  &nboard);
    else
        f_status = read_formatted_bin(file_in, &nintci, &nintcf, &nextci, 
                                      &nextcf, &lcc, &bs, &be, &bn, &bw, &bl, 
                                      &bh, &bp, &su, &nboard);

    if (f_status != 0) {
        printf("failed to initialize data!\n");
        return EXIT_FAILURE;
    }

    // allocate arrays used in gccg
    int nomax = 3;
    /** the reference residual*/
    double resref = 0.0;
    /** the ratio between the reference and the current residual*/
    double ratio;

    /** array storing residuals */
    double* resvec = (double *) calloc(sizeof(double), (nintcf + 1));
    /** the variation vector -> keeps the result in the end */
    double* var = (double *) calloc(sizeof(double), (nextcf + 1));

    /** the computation vectors */
    double* direc1 = (double *) calloc(sizeof(double), (nextcf + 1));
    double* direc2 = (double *) calloc(sizeof(double), (nextcf + 1));

    /** additional vectors */
    double* cgup = (double *) calloc(sizeof(double), (nextcf + 1));
    double* oc = (double *) calloc(sizeof(double), (nintcf + 1));
    double* cnorm = (double *) calloc(sizeof(double), (nintcf + 1));
    double* adxor1 = (double *) calloc(sizeof(double), (nintcf + 1));
    double* adxor2 = (double *) calloc(sizeof(double), (nintcf + 1));
    double* dxor1 = (double *) calloc(sizeof(double), (nintcf + 1));
    double* dxor2 = (double *) calloc(sizeof(double), (nintcf + 1));

    // initialize the reference residual
    for (int nc = nintci; nc <= nintcf; nc++) {
        resvec[nc] = su[nc];
        resref = resref + resvec[nc] * resvec[nc];
    }
    resref = sqrt(resref);
    if (resref < 1.0e-15) {
        printf("i/o - error: residue sum less than 1.e-15 - %lf\n", resref);
        return EXIT_FAILURE;
    }

    // initialize the arrays
    for (int nc = 0; nc <= 10; nc++) {
        oc[nc] = 0.0;
        cnorm[nc] = 1.0;
    }

    for (int nc = nintci; nc <= nintcf; nc++) {
        cgup[nc] = 0.0;
        var[nc] = 0.0;
    }

    for (int nc = nextci; nc <= nextcf; nc++) {
        var[nc] = 0.0;
        cgup[nc] = 0.0;
        direc1[nc] = 0.0;
        bs[nc] = 0.0;
        be[nc] = 0.0;
        bn[nc] = 0.0;
        bw[nc] = 0.0;
        bl[nc] = 0.0;
        bh[nc] = 0.0;
    }

    for (int nc = nintci; nc <= nintcf; nc++)
        cgup[nc] = 1.0 / bp[nc];

    int if1 = 0;
    int if2 = 0;
    int iter = 1;
    int nor = 1;
    int nor1 = nor - 1;
    /* finished initalization */


    if ( test_measure("INPUT") != 0 ) exit( 1 );

    /***************************************************/

    while (iter < 10000) {

        /* start phase 1 */

        // update the old values of direc
        for (int nc = nintci; nc <= nintcf; nc++) {
            direc1[nc] = direc1[nc] + resvec[nc] * cgup[nc];
        }

        // compute new guess (approximation) for direc
        for (int nc = nintci; nc <= nintcf; nc++) {
            direc2[nc] = bp[nc] * direc1[nc] - bs[nc] * direc1[lcc[0][nc]]
                         - bw[nc] * direc1[lcc[3][nc]] - bl[nc] * direc1[lcc[4][nc]]
                         - bn[nc] * direc1[lcc[2][nc]] - be[nc] * direc1[lcc[1][nc]]
                         - bh[nc] * direc1[lcc[5][nc]];
        } /* end phase 1 */

        /*  start phase 2 */
        // execute normalization steps
        double oc1, oc2, occ;
        if (nor1 == 1) {
            oc1 = 0;
            occ = 0;
            for (int nc = nintci; nc <= nintcf; nc++) {
                occ = occ + adxor1[nc] * direc2[nc];
            }
            oc1 = occ / cnorm[1];
            for (int nc = nintci; nc <= nintcf; nc++) {
                direc2[nc] = direc2[nc] - oc1 * adxor1[nc];
                direc1[nc] = direc1[nc] - oc1 * dxor1[nc];
            }
            if1++;

        } else if (nor1 == 2) {
            oc1 = 0;
            occ = 0;
            for (int nc = nintci; nc <= nintcf; nc++)
                occ = occ + adxor1[nc] * direc2[nc];

            oc1 = occ / cnorm[1];
            oc2 = 0;
            occ = 0;
            for (int nc = nintci; nc <= nintcf; nc++)
                occ = occ + adxor2[nc] * direc2[nc];

            oc2 = occ / cnorm[2];
            for (int nc = nintci; nc <= nintcf; nc++) {
                direc2[nc] = direc2[nc] - oc1 * adxor1[nc] - oc2 * adxor2[nc];
                direc1[nc] = direc1[nc] - oc1 * dxor1[nc] - oc2 * dxor2[nc];
            }

            if2++;
        }

        cnorm[nor] = 0;
        double omega = 0;

        // compute the new residual
        for (int nc = nintci; nc <= nintcf; nc++) {
            cnorm[nor] = cnorm[nor] + direc2[nc] * direc2[nc];
            omega = omega + resvec[nc] * direc2[nc];
        }
        omega = omega / cnorm[nor];

        double resnew = 0.0;
        for (int nc = nintci; nc <= nintcf; nc++) {
            var[nc] = var[nc] + omega * direc1[nc];
            resvec[nc] = resvec[nc] - omega * direc2[nc];
            resnew = resnew + resvec[nc] * resvec[nc];
        }
        resnew = sqrt(resnew);
        ratio = resnew / resref;

        // exit on no improvements of residual
        if (ratio <= 1.0e-10)
            break;

        iter++;

        // prepare additional arrays for the next iteration step
        if (nor == nomax)
            nor = 1;
        else {
            if (nor == 1) {
                for (int nc = nintci; nc <= nintcf; nc++) {
                    dxor1[nc] = direc1[nc];
                    adxor1[nc] = direc2[nc];
                }

            } else if (nor == 2) {
                for (int nc = nintci; nc <= nintcf; nc++) {
                    dxor2[nc] = direc1[nc];
                    adxor2[nc] = direc2[nc];
                }
            }
            nor++;
        }
        nor1 = nor - 1;

    }/* end phase 2 */

    /* finished computation loop */

    if ( test_measure("CALC") != 0 ) exit( 1 );

    /**************************************************************/

    /* write output file  */
    if ( write_result(file_in, file_out, nintci, nintcf, var, iter, ratio) != 0 )
        printf("error when trying to write to file %s\n", file_out);

    if ( test_measure("OUTPUT") != 0 ) exit( 1 );


    int nodeCnt;
    int** points;
    int** elems;

    vol2mesh(nintci, nintcf, lcc, &nodeCnt, &points, &elems);

    write_result_vtk("SU.vtk", nintci, nintcf, nodeCnt, points, elems, su);
    write_result_vtk("VAR.vtk", nintci, nintcf, nodeCnt, points, elems, var);
    write_result_vtk("CGUP.vtk", nintci, nintcf, nodeCnt, points, elems, cgup);



    /* Free all the dynamically allocated memory */
    free(direc2);
    free(direc1);
    free(dxor2);
    free(dxor1);
    free(adxor2);
    free(adxor1);
    free(cnorm);
    free(oc);
    free(var);
    free(cgup);
    free(resvec);
    free(su);
    free(bp);
    free(bh);
    free(bl);
    free(bw);
    free(bn);
    free(be);
    free(bs);


    printf("Simulation completed successfully!\n");
    return EXIT_SUCCESS;
}
Beispiel #25
0
int
parse_input( FILE *ifp, FILE *ofp, struct ldop *op )
{
    char		*p, *args, line[ MAXLINELEN + 1 ];
    struct inputparams	*ip;

    if ( fgets( line, MAXLINELEN, ifp ) == NULL ) {
	write_result( ofp, LDAP_OTHER, NULL, "Empty Input" );
    }
    line[ strlen( line ) - 1 ] = '\0';
    if ( strncasecmp( line, STR_OP_SEARCH, sizeof( STR_OP_SEARCH ) - 1 )
	    != 0 ) {
	write_result( ofp, LDAP_UNWILLING_TO_PERFORM, NULL,
		"Operation Not Supported" );
	return( -1 );
    }

    op->ldop_op = LDOP_SEARCH;

    while ( fgets( line, MAXLINELEN, ifp ) != NULL ) {
	line[ strlen( line ) - 1 ] = '\0';
	debug_printf( "<< %s\n", line );

	args = line;
	if (( ip = find_input_tag( &args )) == NULL ) {
	    debug_printf( "ignoring %s\n", line );
	    continue;
	}

	switch( ip->ip_type ) {
	case IP_TYPE_SUFFIX:
	    add_strval( &op->ldop_suffixes, args );
	    break;
	case IP_TYPE_BASE:
	    op->ldop_dn = estrdup( args );
	    break;
	case IP_TYPE_SCOPE:
	    if (( op->ldop_srch.ldsp_scope = atoi( args )) != LDAP_SCOPE_BASE &&
		    op->ldop_srch.ldsp_scope != LDAP_SCOPE_ONELEVEL &&
		    op->ldop_srch.ldsp_scope != LDAP_SCOPE_SUBTREE ) {
		write_result( ofp, LDAP_OTHER, NULL, "Bad scope" );
		return( -1 );
	    }
	    break;
	case IP_TYPE_ALIASDEREF:
	    op->ldop_srch.ldsp_aliasderef = atoi( args );
	    break;
	case IP_TYPE_SIZELIMIT:
	    op->ldop_srch.ldsp_sizelimit = atoi( args );
	    break;
	case IP_TYPE_TIMELIMIT:
	    op->ldop_srch.ldsp_timelimit = atoi( args );
	    break;
	case IP_TYPE_FILTER:
	    op->ldop_srch.ldsp_filter = estrdup( args );
	    break;
	case IP_TYPE_ATTRSONLY:
	    op->ldop_srch.ldsp_attrsonly = ( *args != '0' );
	    break;
	case IP_TYPE_ATTRS:
	    if ( strcmp( args, "all" ) == 0 ) {
		op->ldop_srch.ldsp_attrs = NULL;
	    } else {
		while ( args != NULL ) {
		    if (( p = strchr( args, ' ' )) != NULL ) {
			*p++ = '\0';
			while ( isspace( (unsigned char) *p )) {
			    ++p;
			}
		    }
		    add_strval( &op->ldop_srch.ldsp_attrs, args );
		    args = p;
		}
	    }
	    break;
	}
    }

    if ( op->ldop_suffixes == NULL || op->ldop_dn == NULL ||
		op->ldop_srch.ldsp_filter == NULL ) {
	write_result( ofp, LDAP_OTHER, NULL,
		"Required suffix:, base:, or filter: missing" );
	return( -1 );
    }

    return( 0 );
}
Beispiel #26
0
int main(int argc, char** argv)
{
  printf("Checking arguments.\n");
  int n_workers;
  check_args(argc, argv, &n_workers);

  printf("Reading file.\n");
  int xsize, ysize, colmax;
  pixel* image = read_file(argv, &xsize, &ysize, &colmax);


  pthread_t workers[n_workers];
  thread_data t_data[n_workers];

  int i;
  for(i = 0; i < n_workers; i++){
    t_data[i].tid = i;
    t_data[i].n_workers = &n_workers;
    t_data[i].xsize = &xsize;
    t_data[i].ysize = &ysize;
    t_data[i].colmax = &colmax;
    t_data[i].image = image;
  }
  
  /* printf("rank: %d\t ystart: %d\t yend: %d\t diff: %d\t count %d\t displ %d\n", */
  /* 	 rank, ystarts[rank], yends[rank], yends[rank] - ystarts[rank], sendcounts[rank], displs[rank]); */

  /* start timing */
  struct timespec stime;
  clock_gettime(0, &stime);
  
  /* calculate average. */
  for(i = 0; i < n_workers; i++){
    pthread_create(&workers[i], NULL, threshold_average, &t_data[i]);
  }

  for(i = 0; i < n_workers; i++){
    pthread_join(workers[i], NULL);
  }

  /* calculate average. */
  int avg = 0;
  for(i = 0; i < n_workers; i++){
    avg += t_data[i].own_avg;
  }
  
  avg /= n_workers;
  
  /* filter */
  printf("Running filter.\n");
  for(i = 0; i < n_workers; i++){
    t_data[i].own_avg = avg;
    pthread_create(&workers[i], NULL, threshold_filter, &t_data[i]);
  }
  
  for(i = 0; i < n_workers; i++){
    pthread_join(workers[i], NULL);
  }

  /* stop timing */
  struct timespec etime;
  clock_gettime(0, &etime);
  printf("Filtering took: %g secs\n", (etime.tv_sec  - stime.tv_sec) +
  	 1e-9*(etime.tv_nsec  - stime.tv_nsec)) ;
  
  printf("Writing output.\n");
  write_result(argv, xsize, ysize, colmax, image);
  free(image);
  
  exit(0);
}
Beispiel #27
0
int main()
{
	int i;
	double cl;
	kase = 1;

	// The final output will be written in the outFile and the initial input will be read from inFile
	std::string outFile = "output.txt";
	std::string inFile = "input.txt";

	// Create the output file
	FILE *fpout = fopen(outFile.c_str(), "wt");
	fclose(fpout);

	// Open the input file
	FILE *fpin = fopen(inFile.c_str(), "rt");

	// Reading each of the cases, There may be two types of cases, with 4 parameters, with 5 parameters
	// There may also be comments that starts with #
	while(fgets(buff, 1000, fpin))
	{
		// No data
		if(strlen(buff) == 0)
			continue;
		// Comment
		if(buff[0] == '#')
			continue;
		StringTokenizer token;

		// tokeniize using space
		token.parse(buff, " \n\r");
		std::vector<std::string> vecToken; 
		token.getTokens(vecToken);

		int totParam = vecToken.size();

		// Not enough parameters
		if(totParam < 4)
			continue;

		// First token is the graph file name
		std::string graphFile = vecToken[0];

		// 2nd and 3rd tokens are start and end node id respectively
		int startNode = atoi(vecToken[1].c_str());
		int endNode = atoi(vecToken[2].c_str());

		// 4th Token is the result file for this query
		std::string pathFile = vecToken[3];
		int ind = pathFile.length() - 1;
		while(pathFile[ind] < 32)
		{
			pathFile[ind] = '\0';
			ind--;
		}

		// Load edge information from graph file
		loadGraph(graphFile);

		// Use bidirectional AStar to get the route
		BiDirAStar gdef;
		cl = clock();
		int res = gdef.bidir_astar(edges, edge_count, maxNode, startNode, endNode, &path, &path_count, &err_msg);
		cl = clock() - cl;

		// Write the route in the result file
		write_result(pathFile, res);
		
		// There is an answer file
		if(totParam > 4)
		{
			std::string ansFile = vecToken[4];
			ind = ansFile.length() - 1;
			while(ansFile[ind] < 32)
			{
				ansFile[ind] = '\0';
				ind--;
			}
			// Match and write result in the final output file
			match(pathFile, ansFile, outFile, cl / CLOCKS_PER_SEC);
		}
		else
		{
			// Provide information that the route is generated in path file.
			fpout = fopen(outFile.c_str(), "a+");
			fprintf(fpout, "Case %d: Path Written to file %s", kase, pathFile.c_str());
			fprintf(fpout, "Query Time: %lf sec\n\n", cl / CLOCKS_PER_SEC);
			fclose(fpout);
		}
		kase++;
		free(path);
		delete [] edges;
	}
	return 0;
}
Beispiel #28
0
void getBestServer(char* interface_name)
{
	FILE* file_fd;
	char buffer[BUF_SIZE];
	char vist_url[BUF_SIZE];
	char vist_ip[IPV4_SIZE];
	char result_ip[IPV4_SIZE];
	double min_delay = MIN_DELAY;
	/*choice best from 5 address */
	int test_num = 0;
	file_fd = fopen("/tmp/speed_best","r");
	if(file_fd == NULL){
		IK_APP_ERR_LOG("ik_speed_test open file best failed\n");
		exit(1);
	}
	
	while(!feof(file_fd)){
		bzero(buffer,BUF_SIZE);
		bzero(vist_url,BUF_SIZE);
		bzero(vist_ip,IPV4_SIZE);
		test_num++;
		if(fgets(buffer,1024,file_fd) == NULL){
			write_result(interface_name,"ik_speed getbestserver 读取失败");
			exit(1);
		}
		char* url = strstr(buffer,"url");
		if(url==NULL)
			continue;
		char* http = strstr(url,"http://");
		if(http == NULL){
			continue;
		}
		int len1 = strlen(http);
		char* http_end = strstr(http,"speedtest/upload.");
		if(http_end == NULL){
			continue;
		}
		int len2 = strlen(http_end);
		int diff = len1 - len2 - 7;
		snprintf(vist_url,diff,"%s",http+7);

		struct hostent *host;
		
		if((host = gethostbyname(vist_url)) == NULL){
			write_result(interface_name,"ik_speed getbestserver  dns 解析失败");
			exit(1);
		}
		if(inet_ntop(host->h_addrtype,*host->h_addr_list,vist_ip,IPV4_SIZE) == NULL){
			write_result(interface_name,"ik_speed getbestserver   转换ip失败");
			exit(1);
		}
		double delay=0.0;
		int delay_loop;
		for(delay_loop=0;delay_loop<3;delay_loop++){
			delay+=get_average_delay(vist_ip,vist_url,interface_name);
		}
		//printf("%s : %f\n",vist_url,delay);
		if(delay<min_delay){
			min_delay = delay;
			strncpy(result_ip,vist_ip,IPV4_SIZE);
		}	

		/* loop number limit*/
		if(5 == test_num)
			break;
	}
	
	fclose(file_fd);
	printf("min_delay : %f,last_ip : %s\n",min_delay,result_ip);
	printf("start test download speed! ......\n");
	download_speed(result_ip,interface_name,vist_url);
	sleep(1);
	printf("start test upload speed! ......\n");
	pool_init(pthread_number);
	upload_speed(result_ip,interface_name,vist_url);
}
Beispiel #29
0
void* file_upload(void *arg)
{
	struct download_post_info *info;
	info = (struct download_post_info *)arg;
	int i = 0,seek;
	int size = 250*100*100;
	int loop_num = size / (36*30);
	char * chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	char * first_one = "content1=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int  first_len = strlen(first_one);
	char post_string[SEND_BUF+1];
	long long send_sum = 0;
	
	bzero(post_string,(SEND_BUF+1));
	
	for(i=0;i<30;i++){
		seek = i*36;
		snprintf((post_string+seek),SEND_BUF,"%s",chars);
	}
	int post_string_len = strlen(post_string);
	/* socket init */
	int sockfd;
	struct sockaddr_in dest_addr;
	dest_addr.sin_family = AF_INET;
	dest_addr.sin_port = htons(HTTP_PORT);
	dest_addr.sin_addr.s_addr = inet_addr(info->server_ip);
	
	/* create socket*/
	if((sockfd = socket(AF_INET,SOCK_STREAM,0)) < 0){
		IK_APP_ERR_LOG("ik_speed upload socket() %s\n",strerror(errno));
		goto psend;
	}
	
	/* bind choice */
	if(bind_fd == 1){
		if(bind_interface(info->interface,sockfd)==1){
			goto psend;
		}
	}
	
	/*connect timeout  set time */
	struct timeval timeo = {TIME_OUT_MIN,0};
	socklen_t len = sizeof(timeo);
	
	if(setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &timeo, len) == -1){
		IK_APP_ERR_LOG("ik_speed upload setsockopt() %s \n",strerror(errno));
		goto psend;
	}
	
		/* http connect to server ip */		
	int connect_res = connect(sockfd,(struct sockaddr *)&dest_addr,sizeof(dest_addr));
	if(connect_res == -1){
		IK_APP_ERR_LOG("ik_speed upload connect() %s\n",strerror(errno));
		goto psend;;
	}
	
	/*set recv  time out time */
	if(setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeo, len) == -1){
		IK_APP_ERR_LOG("ik_speed upload setsockopt() %s\n",strerror(errno));
		write_result(info->interface,"线程 设置接受超时时间失败");
		goto psend;
	}
	
	/*get upload delay*/
	int nSend,nRecv;	
	int head_sendlen = strlen(info->post_string);
	nSend = send(sockfd,info->post_string,head_sendlen,0);	
	if(nSend<0){
		write_result(info->interface," upload 线程发送数据包失败");
		goto psend;
	}
	send_sum += nSend;
	nSend = send(sockfd,first_one,first_len,0);
	if(nSend<0){
		write_result(info->interface," upload 线程发送数据包失败");
		goto psend;
	}
	
	//send_sum = head_sendlen + first_len;
	send_sum += nSend;
	/*send post string */
	for(i=1;i<loop_num;i++){
		nSend = send(sockfd,post_string,post_string_len,0);
		if(nSend<0){
			IK_APP_ERR_LOG("ik_speed upload send() %s\n",strerror(errno));
			goto psend;
		}
		//send_sum += post_string_len;
		send_sum += nSend;
	}
	char read_buf[20];
	nRecv = recv(sockfd,read_buf,11,0);			
	if(nRecv<0){
		IK_APP_ERR_LOG("ik_speed upload recv %s\n",strerror(errno));	
		goto psend;
	}
	
psend:
	//printf("thread send : %lld\n",send_sum);
	pthread_mutex_lock (&(pool->queue_lock)); 
	sum_send_lens += send_sum;
	pthread_mutex_unlock (&(pool->queue_lock));
	close(sockfd);
	return NULL;
}
void* maxArray_pthread_func(void* tdata)
{
    maxarray_thread_args targs = get_data(maxarray_thread_args,tdata);
    int tid = get_tid(tdata);
    int dim = targs.dimension;
    int start = get_start(tdata);
    int end = get_end(tdata);
    int* iter_i = targs.iter_i;
    int** ps = targs.ps;

    int max_sum = targs.mat0;
    int top = 0, left = 0, bottom = 0, right = 0;

    //Auxilliary variables
    int sum[dim];
    int pos[dim];
    int local_max;

    int i = 0;
    for(; i<dim&&iter_i[i]<=start; i++);
    int next_i = i<dim ? iter_i[i] : end;
    i--;

    for(int n=start; n<end; n++)
    {
        if(n >= next_i)
            next_i = ++i<dim-1 ? iter_i[i+1] : end;

        int k = i + n - iter_i[i];

        // Kandane over all columns with the i..k rows
        clear(sum, dim);
        clear(pos, dim);
        local_max = 0;

        // We keep track of the position of the max value over each Kandane's execution
        // Notice that we do not keep track of the max value, but only its position

        sum[0] = ps[k][0] - (i==0 ? 0 : ps[i-1][0]);

        for (int j=1; j<dim; j++)
        {
            if (sum[j-1] > 0)
            {
                sum[j] = sum[j-1] + ps[k][j] - (i==0 ? 0 : ps[i-1][j]);
                pos[j] = pos[j-1];
            }
            else
            {
                sum[j] = ps[k][j] - (i==0 ? 0 : ps[i-1][j]);
                pos[j] = j;
            }
            if (sum[j] > sum[local_max])
            {
                local_max = j;
            }
        } //Kandane ends here

        if (sum[local_max] > max_sum)
        {
            // sum[local_max] is the new max value
            // the corresponding submatrix goes from rows i..k.
            // and from columns pos[local_max]..local_max

            max_sum = sum[local_max];
            top = i;
            left = pos[local_max];
            bottom = k;
            right = local_max;
        }
    }

    maxarray_thread_ret ret;
    ret.max_sum = max_sum;
    ret.top = top;
    ret.left = left;
    ret.bottom = bottom;
    ret.right = right;

    write_result(maxarray_thread_ret,tdata,ret);
}