Example #1
0
int
main(int argc, char *argv[])
{
	char *src_hostfile = NULL, *dst_hostfile = NULL;
	gfarm_stringlist paths;
	gfs_glob_t types;
	int mode_src_ch = 0, mode_dst_ch = 0, parallel = -1;
	int i, ch;
	gfarm_error_t e;
	const char *errmsg, *errmsg2 = NULL;
	struct gfrep_arg gfrep_arg;
	struct flist flist;

	if (argc >= 1)
		program_name = basename(argv[0]);
	memset(&gfrep_arg, 0, sizeof(gfrep_arg));
	memset(&flist, 0, sizeof(flist));
	flist.src_domain = "";
	flist.dst_domain = "";

	e = gfarm_initialize(&argc, &argv);
	error_check(e);

#ifdef _OPENMP
	while ((ch = getopt(argc, argv, "h:j:mnqvxS:D:H:N:?")) != -1) {
#else
	while ((ch = getopt(argc, argv, "h:mnqvxS:D:H:N:?")) != -1) {
#endif
		switch (ch) {
		case 'h':
			src_hostfile = optarg;
			conflict_check(&mode_src_ch, ch);
			break;
#ifdef _OPENMP
		case 'j':
			parallel = strtol(optarg, NULL, 0);
			break;
#endif
		case 'm':
			act = &migrate_mode;
			break;
		case 'n':
			opt_noexec = 1;
			break;
		case 'q':
			opt_quiet = 1;
			break;
		case 'v':
			opt_verbose = 1;
			break;
		case 'x':
			opt_remove = 1;
			break;
		case 'S':
			flist.src_domain = optarg;
			conflict_check(&mode_src_ch, ch);
			break;
		case 'D':
			flist.dst_domain = optarg;
			conflict_check(&mode_dst_ch, ch);
			break;
		case 'H':
			dst_hostfile = optarg;
			conflict_check(&mode_dst_ch, ch);
			break;
		case 'N':
			opt_nrep = strtol(optarg, NULL, 0);
			break;
		case '?':
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	/* make writing-to-stderr atomic, for GfarmFS-FUSE log output */
	setvbuf(stderr, NULL, _IOLBF, 0);

	if (!opt_quiet) {
		printf("constructing file list...");
		fflush(stdout);
	}

	e = gfarm_stringlist_init(&paths);
	if (e == GFARM_ERR_NO_ERROR) {
		e = gfs_glob_init(&types);
		if (e == GFARM_ERR_NO_ERROR) {
			for (i = 0; i < argc; i++)
				gfs_glob(argv[i], &paths, &types);
			gfs_glob_free(&types);
		}
	}
	error_check(e);

	e = gfarm_list_init(&flist.slist);
	error_check(e);
	e = gfarm_list_init(&flist.dlist);
	error_check(e);
	flist.srchash = gfarm_hash_table_alloc(HOSTHASH_SIZE,
		gfarm_hash_casefold, gfarm_hash_key_equal_casefold);
	if (flist.srchash == NULL)
		error_check(GFARM_ERR_NO_MEMORY);

	e = create_hosthash_from_file(src_hostfile,
		HOSTHASH_SIZE, &flist.src_hosthash);
	error_check(e);
	e = create_hosthash_from_file(dst_hostfile,
		HOSTHASH_SIZE, &flist.dst_hosthash);
	error_check(e);

	for (i = 0; i < gfarm_stringlist_length(&paths); i++) {
		char *file = gfarm_stringlist_elem(&paths, i), *realpath = NULL;

		e = gfarm_realpath_by_gfarm2fs(file, &realpath);
		if (e == GFARM_ERR_NO_ERROR)
			file = realpath;
		e = gfarm_foreach_directory_hierarchy(
			create_filelist, NULL, NULL, file, &flist);
		free(realpath);
		if (e != GFARM_ERR_NO_ERROR)
			break;
	}
	gfarm_stringlist_free_deeply(&paths);
	error_check(e);

	if (!opt_quiet)
		printf(" done\n");
	if (opt_verbose) {
		printf("files to be replicated\n");
		print_file_list(&flist.slist);
	}
	if (opt_verbose && opt_remove) {
		printf("files having too many replicas\n");
		print_file_list(&flist.dlist);
	}
	if (gfarm_list_length(&flist.slist) <= 0
	    && (!opt_remove || gfarm_list_length(&flist.dlist) <= 0))
		exit(0); /* no file */

	/* replicate files */
	e = gfarm_hash_to_string_array(
		flist.srchash, &gfrep_arg.nsrc, &gfrep_arg.src);
	error_check(e);
	gfarm_hash_table_free(flist.srchash);

	if (!opt_quiet) {
		printf("investigating hosts...");
		fflush(stdout);
	}
	e = create_hostlist_by_domain_and_hash(
		gfarm_list_length(&flist.slist) > 0 ?
		gfarm_list_elem(&flist.slist, 0) :
		gfarm_list_elem(&flist.dlist, 0),
		flist.dst_domain, flist.dst_hosthash,
		&gfrep_arg.ndst, &gfrep_arg.dst, &gfrep_arg.dst_port);
	error_check(e);
	if (!opt_quiet)
		printf(" done\n");

	errmsg = pfor_list(act, &flist.slist, parallel, &gfrep_arg);
	gfarm_list_free(&flist.slist);

	/* remove file replicas */
	if (opt_remove)
		errmsg2 = pfor_list(
			&remove_mode, &flist.dlist, parallel, &gfrep_arg);
	gfarm_list_free(&flist.dlist);
	if (errmsg == NULL)
		errmsg = errmsg2;
	if (errmsg != NULL)
		fprintf(stderr, "%s\n", errmsg), exit(EXIT_FAILURE);

	gfarm_strings_free_deeply(gfrep_arg.nsrc, gfrep_arg.src);
	gfarm_strings_free_deeply(gfrep_arg.ndst, gfrep_arg.dst);
	free(gfrep_arg.dst_port);
	e = gfarm_terminate();
	error_check(e);

	return (0);
}
Example #2
0
int ANBSample::DartThrowing(){

	//Dart-Throwing法

	int trail = 0;
	int neighbor_range = 3; //局部邻域范围
	int rand_pt_ind;        //随机点索引
	if(USING_ONION_ORDER){
		grid.SetUpOnionOrder(neighbor_range);  //开始采样
	}

#if ORDER_TYPE == 0
	random_shuffle(dense_pt_list.begin(),dense_pt_list.end());
	int id_counter = 0;
	vector<sample *>::iterator it;      //设置点迭代器
	for (it=dense_pt_list.begin();it!=dense_pt_list.end();++it){

		(*it)->_ID = id_counter;    //获取采样点的id

	}

	for(int i = 0 ; i < dense_pt_list.size(); i++){

		rand_pt_ind = i;
#elif ORDER_TYPE == 1
	for(int i = 0 ; i < dense_pt_list.size(); i++){
		rand_pt_ind = i;
#else
#endif
	sample *s = dense_pt_list[rand_pt_ind];  //采样点集
	if(pt_list.empty()){

		s->acp_ID = pt_list.size();
		pt_list.push_back(s);

		//将采样点插入到网格中
		vector<int> g_ind = GridIndex(s);
		grid.SetCellValue(g_ind[0],g_ind[1],g_ind[2],s->acp_ID);

		trail = 0;
		continue;
	}
	else{
		vector<int>g_ind =GridIndex(s); 
		vector<int>neighbor;
		if(USING_ONION_ORDER){

			neighbor = grid.GetNeighbor_Onion(g_ind[0],g_ind[1],g_ind[2]);

		}
		else{
			neighbor = grid.GetNeighbor(g_ind[0],g_ind[1],g_ind[2],neighbor_range, neighbor_range,neighbor_range);
		}
		int neighbor_ind;
		bool conflict = false;
		for (unsigned int nsi=0; nsi<neighbor.size(); nsi++){
			neighbor_ind=neighbor[nsi];
			while(true)
			{ 
				if(conflict_check(pt_list[neighbor_ind], s))
				{

					conflict=true;
					trail++;


					nsi=neighbor.size();
					break;
				}



				if(pt_list[neighbor_ind]->next==NULL)// arrive the end of current grid cell
				{
					break;
				}
				else
				{
					neighbor_ind=pt_list[neighbor_ind]->next->acp_ID;
				}
			}// end while(true)
		}//end for (unsigned nsi=0; nsi<neigbor.size(); nsi++)

		if (!conflict){
			s->acp_ID=pt_list.size();
			pt_list.push_back(s);

			// 采样点插入网格
			std::vector<int> g_ind=GridIndex(s);
			if(!grid._grid[g_ind[0]][g_ind[1]][g_ind[2]].empty())
			{
				s->next=pt_list[ grid._grid[g_ind[0]][g_ind[1]][g_ind[2]][0] ];
				pt_list[ grid._grid[g_ind[0]][g_ind[1]][g_ind[2]][0] ]->pre=s;
			}

			grid.SetCellValue(g_ind[0], g_ind[1], g_ind[2], s->acp_ID);

			trail=0;				
			}
		}
	}
	return 1;
}
int ANBSample::process(){
	
	//采样过程
	int grid_size[3];
	grid_size[0]=grid_size[1]=grid_size[2]=1.0f/r_global;
	
	

	real model_width[3]={
		boundingbox[1]-boundingbox[0],
		boundingbox[3]-boundingbox[2],
		boundingbox[5]-boundingbox[4]};

	real cell_wid=(model_width[0])/( grid_size[0]*1.0f );
	grid_size[1]=max((int)floor(model_width[1]/cell_wid),1);
	grid_size[2]=max((int)floor(model_width[2]/cell_wid),1);


	grid.CreateGrid(grid_size[0],grid_size[1],grid_size[2]);
	for (int i=0; i<3; i++)
	{
		grid._bin_width[i]=model_width[i]/(grid._size[i]*1.0f);
	}


	DartThrowing();
	grid.CleanGrid();
	grid.DeleteGrid();
	return 1;
}