コード例 #1
0
ファイル: keep_alive.c プロジェクト: VoxOx/VoxOx
/* parse the return of keep-alive packet, it includes some system information */
void qq_process_keep_alive_reply(guint8 *buf, gint buf_len, GaimConnection *gc) 
{
	qq_data *qd;
	gint len;
	gchar **segments;
	guint8 *data;

	g_return_if_fail(buf != NULL && buf_len != 0);

	qd = (qq_data *) gc->proto_data;
	len = buf_len;
	data = g_newa(guint8, len);

	if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
		/* the last one is 60, don't know what it is */
		if (NULL == (segments = split_data(data, len, "\x1f", 6)))
			return;
		/* segments[0] and segment[1] are all 0x30 ("0") */
		qd->all_online = strtol(segments[2], NULL, 10);
		if(0 == qd->all_online)
			gaim_connection_error(gc, _("Keep alive error, seems connection lost!"));
		g_free(qd->my_ip);
		qd->my_ip = g_strdup(segments[3]);
		qd->my_port = strtol(segments[4], NULL, 10);
		g_strfreev(segments);
	} else
		gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt keep alive reply\n");

	/* we refresh buddies's online status periodically */
	/* qd->last_get_online is updated when setting get_buddies_online packet */
	if ((time(NULL) - qd->last_get_online) >= QQ_UPDATE_ONLINE_INTERVAL)
		qq_send_packet_get_buddies_online(gc, QQ_FRIENDS_ONLINE_POSITION_START);
}
コード例 #2
0
ファイル: vt_ncc.cpp プロジェクト: StevenLOL/kaggle-lshtc-1
int
main(void)
{
	DataReader reader;
	std::vector<fv_t> data;
	std::vector<fv_t> test_data;
	std::vector<label_t> labels;
	std::vector<label_t> test_labels;
	category_index_t category_index;
	NearestCentroidClassifier centroid_classifier;
	TFIDFTransformer tfidf;
	long t = tick();
	long t_all = tick();
	Evaluation evaluation;
	
	if (!reader.open(TRAIN_DATA)) {
		fprintf(stderr, "cant read file\n");
		return -1;
	}
	reader.read(data, labels);
	printf("read %ld, %ld, %ldms\n", data.size(), labels.size(), tick() - t);
	reader.close();
	
	t = tick();
	srand(VT_SEED);
	build_category_index(category_index, data, labels);
	split_data(test_data, test_labels, data, labels, category_index, 0.05f);
	build_category_index(category_index, data, labels);
	printf("split train:%ld, test:%ld\n", data.size(), test_data.size());
	
	t = tick();
	tfidf.train(data);
	tfidf.transform(data);
	tfidf.transform(test_data);
	centroid_classifier.train(category_index, data);
	printf("build index %ldms\n", tick() -t );
	
	t = tick();
#ifdef _OPENMP
#pragma omp parallel for schedule(dynamic, 1)	
#endif
	for (int i = 0; i < (int)test_data.size(); ++i) {
		std::vector<int> topn_labels;
		centroid_classifier.predict(topn_labels, K, test_data[i]);
#ifdef _OPENMP
#pragma omp critical
#endif
		{
			evaluation.update(topn_labels, test_labels[i]);
			if (i % 1000 == 0) {
				print_evaluation(evaluation, i, t);
				t = tick();
			}
		}
	}
	printf("----\n");
	print_evaluation(evaluation, test_data.size(), t_all);
	
	return 0;
}
コード例 #3
0
ファイル: buddy_opt.c プロジェクト: bf4/pidgin-mac
void qq_process_add_buddy_no_auth(PurpleConnection *gc,
		guint8 *data, gint data_len, guint32 uid)
{
	qq_data *qd;
	gchar **segments;
	gchar *dest_uid, *reply;
	PurpleBuddy *buddy;

	g_return_if_fail(data != NULL && data_len != 0);
	g_return_if_fail(uid != 0);

	qd = (qq_data *) gc->proto_data;

	purple_debug_info("QQ", "Process buddy add for id [%u]\n", uid);
	qq_show_packet("buddy_add_no_auth", data, data_len);

	if (NULL == (segments = split_data(data, data_len, "\x1f", 2)))
		return;

	dest_uid = segments[0];
	reply = segments[1];
	if (strtoul(dest_uid, NULL, 10) != qd->uid) {	/* should not happen */
		purple_debug_error("QQ", "Add buddy reply is to [%s], not me!", dest_uid);
		g_strfreev(segments);
		return;
	}

	if (strtol(reply, NULL, 10) == 0) {
		/* add OK */
		qq_buddy_find_or_new(gc, uid);

		qq_request_buddy_info(gc, uid, 0, 0);
		if (qd->client_version >= 2007) {
			qq_request_get_level_2007(gc, uid);
		} else {
			qq_request_get_level(gc, uid);
		}
		qq_request_get_buddies_online(gc, 0, 0);

		purple_debug_info("QQ", "Successed adding into %u's buddy list", uid);
		g_strfreev(segments);
		return;
	}

	/* need auth */
	purple_debug_warning("QQ", "Failed adding buddy, need authorize\n");

	buddy = qq_buddy_find(gc, uid);
	if (buddy == NULL) {
		buddy = qq_buddy_new(gc, uid);
	}
	if (buddy != NULL && buddy->proto_data != NULL) {
		/* Not authorized now, free buddy data */
		qq_buddy_data_free(buddy->proto_data);
		buddy->proto_data = NULL;
	}

	add_buddy_authorize_input(gc, uid, NULL, 0);
	g_strfreev(segments);
}
コード例 #4
0
ファイル: ini.c プロジェクト: rxi/ini
ini_t* ini_load(const char *filename) {
  ini_t *ini = NULL;
  FILE *fp = NULL;
  int n, sz;

  /* Init ini struct */
  ini = malloc(sizeof(*ini));
  if (!ini) {
    goto fail;
  }
  memset(ini, 0, sizeof(*ini));

  /* Open file */
  fp = fopen(filename, "rb");
  if (!fp) {
    goto fail;
  }

  /* Get file size */
  fseek(fp, 0, SEEK_END);
  sz = ftell(fp);
  rewind(fp);

  /* Load file content into memory, null terminate, init end var */
  ini->data = malloc(sz + 1);
  ini->data[sz] = '\0';
  ini->end = ini->data  + sz;
  n = fread(ini->data, 1, sz, fp);
  if (n != sz) {
    goto fail;
  }

  /* Prepare data */
  split_data(ini);

  /* Clean up and return */
  fclose(fp);
  return ini;

fail:
  if (fp) fclose(fp);
  if (ini) ini_free(ini);
  return NULL;
}
コード例 #5
0
ファイル: buddy_opt.c プロジェクト: wosigh/messaging-plugins
/*  process reply to add_buddy_auth request */
void qq_process_add_buddy_auth(guint8 *data, gint data_len, PurpleConnection *gc)
{
	qq_data *qd;
	gchar **segments, *msg_utf8;

	g_return_if_fail(data != NULL && data_len != 0);

	qd = (qq_data *) gc->proto_data;

	if (data[0] == '0') {
		purple_debug_info("QQ", "Reply OK for sending authorize\n");
		return;
	}

	if (NULL == (segments = split_data(data, data_len, "\x1f", 2))) {
		purple_notify_error(gc, _("QQ Buddy"), _("Failed sending authorize"), NULL);
		return;
	}
	msg_utf8 = qq_to_utf8(segments[1], QQ_CHARSET_DEFAULT);
	purple_notify_error(gc, _("QQ Buddy"), _("Failed sending authorize"), msg_utf8);
	g_free(msg_utf8);
}
コード例 #6
0
ファイル: rf.cpp プロジェクト: OlafLee/SUML
void CART::build_tree(TreeNode *tnode) {
    queue<TreeNode*> node_queue;   
    int cur_node_index = 0;
    int cur_node_layer_index = 0;
    // random n times to get the sample
    vector<int> indexes;
    for (int i = 0; i < N; i ++) {
        indexes.push_back(random_int(N, i_seed + 20141015));
    }
    tnode = new TreeNode(indexes, 1);
    while (!node_queue.empty()) {
        if (cur_node_index > MTN) {
            break;
        }
        node *tp = node_queue.front();
        node_queue.pop();
        int feat_index;
        float feat_value;
        vector<int> l_indexes, r_indexes;
        find_best_feat(feat_index, feat_value, tp->indexes);
        split_data(l_indexes, r_indexes, feat_index, feat_value, tp->indexes);
        
        float tot = 0.0;
        for (int j = 0; j < tp->indexes.size(); j ++) {
            tot += y[tp->indexes[j]];
        }
        if (tp->node_layer_index == MLN) {
            tp->is_leaf_node = true;
        }
        else {
            tp->is_leaf_node = false;
        }
        
        tp->l_child = new TreeNode(l_indexes, tp->node_layer_index + 1);
        tp->r_child = new TreeNode(r_indexes, tp->node_layer_index + 1);
        node_queue.push(tp->l_child);
        node_queue.push(tp->r_child);
    }
}
コード例 #7
0
int main(int argc,char *argv[])
{	
	int i,j;
	int genelen;
	int profilenum1,profilenum2;
	int linelen1,linelen2;
	struct Profile_triple *triples1,**triples2;
	float **local_ES_Matrix;		//part of the ES_Matrix in this process
	float *ES_test;  //ES used for testing without writing
	int	my_rank;   /* My process rank           */
    int	p;         /* The number of processes   */
    int source,dest;  
    int tag = 0;
    MPI_Status  status;
	int local_P;	//the data number of each processes must hand
	int begin,end;
	int parameternum;
	int corenum;
	int siglen;	
	int load_time;
	float proportion;
	int ifwrite;
	

	double start,finish,duration;
	
	/* Let the system do what it needs to start up MPI */
    MPI_Init(&argc, &argv);

    /* Get my process rank */
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

    /* Find out how many processes are being used */
    MPI_Comm_size(MPI_COMM_WORLD, &p);
	
	/* check parameter*/
	if(my_rank == 0)
	{
		parameternum = argc;
		if(parameternum == 1)
			Usage();
	}
	MPI_Bcast(&parameternum, 1, MPI_INT, 0, MPI_COMM_WORLD);
	if(parameternum == 1)
	{
		MPI_Finalize();
		exit(0);
	}
	
	// Unset flags (value -1).
	corenum = -1;
	siglen = -1;
	load_time = -1;
	proportion = -1;
	ifwrite = -1;
    // Unset options (value 'UNSET').
	char * const UNSET = "unset";
    char * input1   = UNSET;
	char * input2   = UNSET;
	char * output   = UNSET;
	
	int c;
	while (1) {
		int option_index = 0;
		static struct option long_options[] = {
			{"thread",             required_argument,        0, 't'},
			{"siglen",             required_argument,        0, 'l'},
			{"loadtime",           required_argument,        0, 'a'},
			{"proportion",         required_argument,        0, 'p'},
			{"write",              required_argument,        0, 'w'},
			{"input1",             required_argument,        0, '1'},
			{"input2",             required_argument,        0, '2'},
			{"output",             required_argument,        0, 'o'},
			{0, 0, 0, 0}
		};

		c = getopt_long(argc, argv, "t:l:a:p:w:1:2:o:",
            long_options, &option_index);
	
		if(c==-1)	break;
		
		switch (c) {
		
		case 0:
			// A flag was set. //
			break;

		case '1':
			if (input1 == UNSET) 
			{
				input1 = optarg;
			}
			else 
			{
				if(my_rank==0)
				{
					fprintf(stderr, "%s --input1 set more than once\n", ERRM);
					Usage();
				}		
				MPI_Finalize();
				exit(0);
			}
			break;
		
		case '2':
			if (input2 == UNSET) 
			{
				input2 = optarg;
			}
			else 
			{
				if(my_rank==0)
				{
					fprintf(stderr, "%s --input2 set more than once\n", ERRM);
					Usage();
				}		
				MPI_Finalize();
				exit(0);
			}
			break;
		
		case 'o':
			if (output == UNSET) 
			{
				output = optarg;
			}
			else 
			{
				if(my_rank==0)
				{
					fprintf(stderr, "%s --output set more than once\n", ERRM);
					Usage();
				}		
				MPI_Finalize();
				exit(0);
			}
			break;
		
		case 't':
			if (corenum < 0) {
				corenum = atoi(optarg);
				if (corenum < 1) {
					if(my_rank==0)
					{
						fprintf(stderr, "%s --thread must be a positive integer\n", ERRM);
						Usage();
					}		
					MPI_Finalize();
					exit(0);
				}
			}
			else {
				if(my_rank==0)
				{
					fprintf(stderr,"%s --thread set more " "than once\n", ERRM);
					Usage();
				}		
				MPI_Finalize();
				exit(0);
			}
			break;
			
		case 'l':
			if (siglen < 0) {
				siglen = atoi(optarg);
				if (siglen < 1) {
					if(my_rank==0)
					{
						fprintf(stderr, "%s --siglen must be a positive integer\n", ERRM);
						Usage();
					}		
					MPI_Finalize();
					exit(0);
				}
			}
			else {
				if(my_rank==0)
				{
					fprintf(stderr,"%s --siglen set more " "than once\n", ERRM);
					Usage();
				}		
				MPI_Finalize();
				exit(0);
			}
			break;
			
		case 'a':
			if (load_time < 0) {
				load_time = atoi(optarg);
				if (load_time < 1) {
					if(my_rank==0)
					{
						fprintf(stderr, "%s --load time must be a positive integer\n", ERRM);
						Usage();
					}		
					MPI_Finalize();
					exit(0);
				}
			}
			else {
				if(my_rank==0)
				{
					fprintf(stderr,"%s --load time set more " "than once\n", ERRM);
					Usage();
				}		
				MPI_Finalize();
				exit(0);
			}
			break;
		
		case 'p':
			if (proportion < 0) {
				proportion = atof(optarg);
				if (proportion > 1 || proportion <= 0) {
					if(my_rank==0)
					{
						fprintf(stderr, "%s -- proportion must be kept in (0,1]\n", ERRM);
						Usage();
					}		
					MPI_Finalize();
					exit(0);
				}
			}
			else {
				if(my_rank==0)
				{
					fprintf(stderr,"%s --proportion set more " "than once\n", ERRM);
					Usage();
				}		
				MPI_Finalize();
				exit(0);
			}
			break;
		
		case 'w':
			if (ifwrite < 0) {
				ifwrite = atof(optarg);
			}
			else {
				if(my_rank==0)
				{
					fprintf(stderr,"%s --write set more " "than once\n", ERRM);
					Usage();
				}		
				MPI_Finalize();
				exit(0);
			}
			break;
			
		default:
			// Cannot parse. //
			if(my_rank==0)
				Usage();
			MPI_Finalize();
			exit(0);
		}		
	}

	//check the parameters
	if(corenum == -1)
		corenum = 1;
	
	if(siglen == -1)
		siglen = 50;
	
	if(load_time == -1)
		load_time = 1;
	
	if(proportion == -1)
		proportion = 1;
	
	if(ifwrite == -1)
		ifwrite = 1;
	
	if(output == UNSET)
	{
		if(my_rank==0)
			fprintf(stderr," [ param error : -o ] Not Set output parameter!\n");
		MPI_Finalize();
		exit(0);
	}
	
	triples2 = (struct Profile_triple **)malloc(load_time*sizeof(struct Profile_triple *));
	
	//barrier all processes to compute time
	MPI_Barrier(MPI_COMM_WORLD); 
	if(my_rank == 0){
		printf("Profile Set is Loading...!\n");
		GET_TIME(start);
	}
	
	//read file parameters in all processes
	ReadFilePara(input1, &profilenum1, &genelen, &linelen1);
	ReadFilePara(input2, &profilenum2, &genelen, &linelen2);
	
	profilenum1 *= proportion;
	profilenum2 *= proportion;
	
	//input file check
	if( profilenum1 <= 0 || genelen <= 0)
	{
		if(my_rank==0)
			fprintf(stderr," [ param error : -1 ] this file input1 is not exist!\n");
		MPI_Finalize();
		exit(0);
	}
	
	if( profilenum2 <= 0 || genelen <= 0)
	{
		if(my_rank==0)
			fprintf(stderr," [ param error : -2 ] this file input2 is not exist!\n");
		MPI_Finalize();
		exit(0);
	}
	
	if(my_rank==0)
	{
		printf("Genelen:	%d\n", genelen);
		printf("Profiles1 length:	%d\n", profilenum1);
		printf("Profiles2 length:	%d\n", profilenum2);
	}
	
	// compute the local size 、up boundary and down boundary for every process in dataset1
	split_data(profilenum1, p, my_rank, &begin, &end, &local_P);
	
	if(my_rank==0)
		printf("Memory check......\n");
	
	unsigned long memavail = memoryAvailable(1);
	
	unsigned long memneed = sizeof(struct Profile_triple)/1024*(local_P+profilenum2/load_time) + local_P/1024*profilenum2*sizeof(float);
	
	unsigned long memallneed = sizeof(struct Profile_triple)/1024*(profilenum1+profilenum2) + profilenum1/1024*profilenum2*sizeof(float);
	
	if(my_rank==0)
	{
		printf("Available Memory:      %ld KB\n", memavail);
		printf("Needed Memory:      %ld KB\n", memneed);
		printf("All Needed Memory:      %ld KB\n", memallneed);
	}

	unsigned long mem1 = sizeof(struct Profile_triple)/1024*(local_P+profilenum2/load_time);
	unsigned long mem2 = profilenum1/1024*profilenum2*sizeof(float);
	
	int nodenum = (int)(mem2/(memavail-mem1)+1);
	if( memneed > memavail )
	{
		if( my_rank==0 )
		{
			//printf("mem1:      %ld KB\n", mem1);
			//printf("mem2:      %ld KB\n", mem2);
			printf("available memory is not enough to store all results, recommend to use more than %d nodes!!!\n", nodenum);
		}
		if(ifwrite==1){
			MPI_Finalize();
			exit(0);
		}else{
			if( my_rank==0 )
			{
				printf("because we are just testing without writing, we will continue!!!\n");
			}
		}
	}
	
		
	/*****read the local part file of dataset1 in every process and get their triples****************/
	triples1 = (struct Profile_triple *)malloc(sizeof(struct Profile_triple)*local_P);	
	getTriples(local_P, genelen, siglen, profilenum1, linelen1, begin, end, input1, triples1);
	
	
	if(ifwrite==1)
	{
		//not test, then allocate the local_ES_Matrix memory
		local_ES_Matrix = (float **)malloc(local_P*sizeof(float *));
		for(i=0;i<local_P;i++)
			local_ES_Matrix[i] = (float *)malloc(profilenum2*sizeof(float));
	}else{
		ES_test = (float *)malloc(corenum*sizeof(float));
	}
	
	int current_time = 0;
	int begin_localfile2, end_localfile2, len_localfile2;
	while( current_time < load_time )
	{
		/********************para load profile dataset2 by openmp******************************/
		split_data(profilenum2, load_time, current_time, &begin_localfile2, &end_localfile2, &len_localfile2);
		//allocate the triples memory for local dataset2
		triples2[current_time] = (struct Profile_triple *)malloc(sizeof(struct Profile_triple)*len_localfile2);
		#pragma omp parallel num_threads(corenum)
		{
			int local_t;	//the data number of each thread must hand
			int begin_t,end_t;
			int threadID = omp_get_thread_num();
		
			// compute the local size 、up boundary and down boundary for every thread in dataset2
			split_data(len_localfile2, corenum, threadID, &begin_t, &end_t, &local_t);
		
			// compute the begin_t to end_t triples
			getFreeTriples(genelen, siglen, profilenum2, linelen2, begin_localfile2 + begin_t, begin_t, local_t, input2, triples2[current_time]);
			//getPartTriples(genelen, siglen, profilenum2, linelen2, begin_t, end_t,  input2, triples2[current_time]);
		}
		
		MPI_Barrier(MPI_COMM_WORLD);
		if(my_rank == 0){
			GET_TIME(finish);
			//compute the IO time
			duration = finish-start;     
			printf("phase %d -->  loading IO and prework time in no communication way: %.4f s\n", current_time+1, duration);

			printf("phase %d -->  Paral compute the ES_Matrix is Starting...!\n", current_time+1);
			GET_TIME(start);
		}
		
		
		/*
		if(my_rank == 0){
			int k;
			for(k=0;k<siglen;k++)
				printf("%d ",triples1[0].gsUp[k]);
			printf("\n");
			for(k=0;k<genelen;k++)
				printf("%d ",triples2[current_time][profilenum2-1].index[k]);
			printf("\n");
		}
		*/
	
		/********************para compute the part of ES_Matrix******************************/
		
		#pragma omp parallel num_threads(corenum)
		{
			int k,t;
			int local_t;	//the data number of each thread must hand
			int begin_t,end_t;
			int threadID = omp_get_thread_num();
		
			// compute the local size 、up boundary and down boundary for every thread in dataset2
			split_data(len_localfile2, corenum, threadID, &begin_t, &end_t, &local_t);
		
			// compute the part of the ES matrix
			if(ifwrite==1){
				for(k=0;k<local_P;k++)
					for(t=begin_t;t<end_t;t++)
						local_ES_Matrix[k][begin_localfile2 + t] = ES_Profile_triple(triples1[k],triples2[current_time][t],genelen,siglen);
			}else{ //just calculate for testing
				for(k=0;k<local_P;k++)
					for(t=begin_t;t<end_t;t++)
						ES_test[threadID] = ES_Profile_triple(triples1[k],triples2[current_time][t],genelen,siglen);
			}
		}
	
		MPI_Barrier(MPI_COMM_WORLD);
		if(my_rank == 0){
			GET_TIME(finish);
			//compute the compute time
			duration = finish-start;     
			printf("phase %d --> Paral compute the ES_Matrix time: %.4f s\n", current_time+1, duration);
		
			if(current_time==load_time-1)
				if(ifwrite==1)
					printf("Writing file is Starting...!\n");
			
			GET_TIME(start);		
		}
			
		free(triples2[current_time]);
		current_time++;	
	}

	
	/*
	if(my_rank == 0){
		int k;
		for(k=0;k<profilenum2;k++)
			printf("%f ",local_ES_Matrix[0][k]);
		printf("\n");
	}
	*/
	
	if(ifwrite==1)
	{
		char Res[128];
		sprintf(Res,"%s_%d.txt",output,my_rank);
		WritetxtResult(0, local_P, profilenum2, Res, local_ES_Matrix);
	
		MPI_Barrier(MPI_COMM_WORLD);
		if(my_rank == 0){
			GET_TIME(finish);
			//compute the write time
			duration = finish-start;     
			printf("Write Result spent: %.4f s\n",duration);
		}
	}else{
		if(my_rank == 0){   
			printf("Just run for test, no results output\n");
		}
	}
	
	//free the memory
	if(ifwrite==1)
	{
		for(i=0;i<local_P;i++)
			free(local_ES_Matrix[i]);
		free(local_ES_Matrix);
	}else{
		free(ES_test);
	}
	free(triples1);
	free(triples2);
	
	MPI_Finalize();
	return 0;
}
コード例 #8
0
ファイル: buddy_info.c プロジェクト: bf4/pidgin-mac
/* process reply to get_info packet */
void qq_process_get_buddy_info(guint8 *data, gint data_len, guint32 action, PurpleConnection *gc)
{
	qq_data *qd;
	gchar **segments;
	gint field_count;
	gchar *icon_name;

	g_return_if_fail(data != NULL && data_len != 0);

	qd = (qq_data *) gc->proto_data;

	if (qd->client_version >= 2008) {
		field_count = QQ_INFO_LAST;
	} else {
		field_count = QQ_INFO_LAST_2007;
	}
	if (NULL == (segments = split_data(data, data_len, "\x1e", field_count)))
		return;

#ifdef DEBUG
	info_debug(segments);
#endif

	if (action == QQ_BUDDY_INFO_SET_ICON) {
		if (strtol(segments[QQ_INFO_FACE], NULL, 10) != qd->my_icon) {
			icon_name = g_strdup_printf("%d", qd->my_icon);
			g_free(segments[QQ_INFO_FACE]);
			segments[QQ_INFO_FACE] = icon_name;

			/* Update me in buddy list */
			update_buddy_info(gc, segments);
			/* send new face to server */
			request_change_info(gc, segments);
		}
		g_strfreev(segments);
		return;
	}

	update_buddy_info(gc, segments);
	switch (action) {
		case QQ_BUDDY_INFO_DISPLAY:
			info_display_only(gc, segments);
			break;
		case QQ_BUDDY_INFO_SET_ICON:
			g_return_if_reached();
			break;
		case QQ_BUDDY_INFO_MODIFY_BASE:
			info_modify_dialogue(gc, segments, QQ_FIELD_BASE);
			break;
		case QQ_BUDDY_INFO_MODIFY_EXT:
			info_modify_dialogue(gc, segments, QQ_FIELD_EXT);
			break;
		case QQ_BUDDY_INFO_MODIFY_ADDR:
			info_modify_dialogue(gc, segments, QQ_FIELD_ADDR);
			break;
		case QQ_BUDDY_INFO_MODIFY_CONTACT:
			info_modify_dialogue(gc, segments, QQ_FIELD_CONTACT);
			break;
		default:
			g_strfreev(segments);
			break;
	}
	return;
}
コード例 #9
0
ファイル: main.c プロジェクト: taylor123454321/c_control
// Main function
void main(void) {
	reset_peripheral(); initClock(); initTimer(); initDisplay(); initPin();
	initGPIO(); initADC(); initConsole(); int i = 0;
	//init_password();
	send_data();

	initCircBuf (&speed_buffer, BUF_SIZE); init_set_speed_data(&speed_set_data);

	int screen = 0; int screen_prev = 0; float speed = 0; float buffed_speed = 0;
	int fake_speed = 0; float acc = 0; float max_acc = 0; //float fuel_eco = 0;
	float distance = 0;

	bool fix = 0; uint8_t satillite = 0; float quality = 0; clock time;
	int aim_pos = 0; unsigned long adc = 0; //int error_stepper = 0;

	IntMasterEnable();

	while(1){
		//reading data
		read_data = split_data(UART_char_data_old, read_data); 	// decode data
		speed = read_speed();									//read data into variables
		adc = run_adc()/7;

		//calculations
		aim_pos = speed_feedback(buffed_speed, encoder_1/40, speed_set_data.speed);
		if (speed_set_data.enable == 1){
			step_motor_control(encoder_1/40, aim_pos);
		}

		//sending fake data
		fake_speed = (int)adc;//= random_at_most(100/1.852);
		send_info(fake_speed);//knots

		//storing data
		store_speed(speed);
		buffed_speed = analysis_speed();
		acc = read_acceleration(buffed_speed);
		max_acc = max_acc_func(acc, max_acc);
		time = read_time();
		satillite = read_satillite();
		fix = read_fix();
		quality = read_quality();
		debounce_button();										// debounce buttons
		screen = read_button_screen(screen, fix);
		distance = read_distance();
		select_read();											//need a mosfet for turning power off
																// select adds a an on and off switch yo

		if (screen == 1){
			if(screen_prev != 1 && screen == 1){
				speed_set_data.speed = buffed_speed;
			}
			speed_set_data.speed = set_speed(speed_set_data.speed);					// set the speed to cruise at
		}
		if (screen == 2){ //0 to 100
			acceleration_test(speed);
		}
		// refresh chainging
		if (fix == 1 && speed_set_data.old == speed_set_data.speed && refresh_rate < 4){
			UARTSend((unsigned char *)PMTK_SET_NMEA_UPDATE_5HZ, 18, 0);
			refresh_rate += 1;
		}
		if (i >= 50){
			display(screen, buffed_speed, acc, max_acc, speed_set_data.speed, satillite,
					encoder_1/40, time, distance, quality, UART_char_data_old, aim_pos, adc, acc_times);
			i = 0;
		}
		screen_prev = screen;
		i++;
	}
}
コード例 #10
0
int main(int argc,char *argv[])
{	
	int i,j;
	int genelen;
	int profilenum1,profilenum2;
	int linelen1,linelen2;
	struct Profile_triple *triples1,*triples2;
	float **local_ES_Matrix;		//part of the ES_Matrix in this process
	int	my_rank;   /* My process rank           */
    int	p;         /* The number of processes   */
    int source,dest;  
    int tag = 0;
    MPI_Status  status;
	int local_P;	//the data number of each processes must hand
	int begin,end;
	int parameternum;
	int corenum;
	int siglen;

	double start,finish,duration;
	
	/* Let the system do what it needs to start up MPI */
    MPI_Init(&argc, &argv);

    /* Get my process rank */
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

    /* Find out how many processes are being used */
    MPI_Comm_size(MPI_COMM_WORLD, &p);
	
	/* check parameter*/
	if(my_rank == 0)
	{
		parameternum = argc;
		if(parameternum!=6)
			Usage(argv[0]);
	}
	MPI_Bcast(&parameternum, 1, MPI_INT, 0, MPI_COMM_WORLD);
	if(parameternum!=6)
	{
		MPI_Finalize();
		exit(0);
	}
	
	corenum = atoi(argv[1]);
	siglen = atoi(argv[2]);
	//barrier all processes to compute time
	MPI_Barrier(MPI_COMM_WORLD); 
	if(my_rank == 0){
		printf("Profile Set is Loading...!\n");
		GET_TIME(start);
	}
	
	//read file parameters in all processes
	ReadFilePara(argv[3], &profilenum1, &genelen, &linelen1);
	ReadFilePara(argv[4], &profilenum2, &genelen, &linelen2);

	// compute the local size 、up boundary and down boundary for every process in dataset1
	split_data(profilenum1, p, my_rank, &begin, &end, &local_P);
	
	/*****read the local part file of dataset1 in every process and get their triples****************/
	triples1 = (struct Profile_triple *)malloc(sizeof(struct Profile_triple)*local_P);	
	getTriples(local_P, genelen, siglen, profilenum1, linelen1, begin, end, argv[3], triples1);
	
	/********************para load profile dataset2 by openmp******************************/
	//allocate the triples memory for dataset2
	triples2 = (struct Profile_triple *)malloc(sizeof(struct Profile_triple)*profilenum2);
	#pragma omp parallel num_threads(corenum)
	{
		int local_t;	//the data number of each thread must hand
		int begin_t,end_t;
		int threadID = omp_get_thread_num();
		
		// compute the local size 、up boundary and down boundary for every thread in dataset2
		split_data(profilenum2, corenum, threadID, &begin_t, &end_t, &local_t);
		
		// compute the begin_t to end_t triples
		getPartTriples(genelen, siglen, profilenum2, linelen2, begin_t, end_t, argv[4], triples2);		
	}
	
	MPI_Barrier(MPI_COMM_WORLD);
	if(my_rank == 0){
		GET_TIME(finish);
		//compute the IO time
		duration = finish-start;     
		printf("loading IO and prework time in no communication way: %.4f s\n",duration);

		printf("Paral compute the ES_Matrix is Starting...!\n");
		GET_TIME(start);
	}
	
	/*
	if(my_rank == 0){
		int k;
		for(k=0;k<siglen;k++)
			printf("%d ",triples1[0].gsUp[k]);
		printf("\n");
		for(k=0;k<genelen;k++)
			printf("%d ",triples2[profilenum2-1].index[k]);
		printf("\n");
	}
	*/
	
	/********************para compute the part of ES_Matrix******************************/
	//allocate the local_ES_Matrix memory
	local_ES_Matrix = (float **)malloc(local_P*sizeof(float *));
	for(i=0;i<local_P;i++)
		local_ES_Matrix[i] = (float *)malloc(profilenum2*sizeof(float));
	#pragma omp parallel num_threads(corenum)
	{
		int k,t;
		int local_t;	//the data number of each thread must hand
		int begin_t,end_t;
		int threadID = omp_get_thread_num();
		
		// compute the local size 、up boundary and down boundary for every thread in dataset2
		split_data(profilenum2, corenum, threadID, &begin_t, &end_t, &local_t);
		
		// compute the part of the ES matrix
		for(k=0;k<local_P;k++)
			for(t=begin_t;t<end_t;t++)
				local_ES_Matrix[k][t] = ES_Profile_triple(triples1[k],triples2[t],genelen,siglen);
	}
	
	MPI_Barrier(MPI_COMM_WORLD);
	if(my_rank == 0){
		GET_TIME(finish);
		//compute the compute time
		duration = finish-start;     
		printf("Paral compute the ES_Matrix time: %.4f s\n",duration);
		
		printf("Writing file is Starting...!\n");
		GET_TIME(start);
	}
	
	/*
	if(my_rank == 0){
		int k;
		for(k=0;k<profilenum2;k++)
			printf("%f ",local_ES_Matrix[0][k]);
		printf("\n");
	}
	*/
	
	char Res[128];
	sprintf(Res,"%s_%d.txt",argv[5],my_rank);
	WritetxtResult(0, local_P, profilenum2, Res, local_ES_Matrix);
	
	MPI_Barrier(MPI_COMM_WORLD);
	if(my_rank == 0){
		GET_TIME(finish);
		//compute the write time
		duration = finish-start;     
		printf("Write Result spent: %.4f s\n",duration);
	}
	
	//free the memory
	for(i=0;i<local_P;i++)
		free(local_ES_Matrix[i]);
	free(local_ES_Matrix);
	free(triples1);
	free(triples2);
	
	MPI_Finalize();
	return 0;
}