Esempio n. 1
0
void print(int vsz, int hsz, char str[]) {
	print_h(0, hsz, str);
	print_v(1, vsz, hsz, str);
	print_h(2, hsz, str);
	print_v(3, vsz, hsz, str);
	print_h(4, hsz, str);
}
Esempio n. 2
0
int print_e_attr(EdgeType* e) {
    if( e == NULL )
        die(-1, "print_e_attr: NULL pointer.\n");
    GList* klist = g_hash_table_get_keys(e->attributes);
    int l = g_list_length(klist);
    int n = 0;
    printf("<Edge> : Id = %ld \n", e->id);
    printf("vstart");
    if(e->start!=NULL) {
        printf("[");
        print_v(e->start);
        printf("]");
    }
    else
        printf("[NULL]");

    printf("-->vend");

    if(e->end!=NULL) {
        printf("[");
        print_v(e->end);
        printf("]");
    }
    else
        printf("[NULL]");
    printf("\nEdge Attributes:--------------\n");
    for(n; n<l; n++) {
        void* key = g_list_nth_data(klist, n);
        Attribute* value = g_hash_table_lookup(e->attributes, key);
        output_attr( (char *) key, value, stdout);
    }
    printf("------------------------------\n");
    g_list_free(klist);
    return 0;
}
Esempio n. 3
0
int main()
{
  std::vector<std::string> v1 = {
    "Joe", "Sam", "Eli", "Mary", "Emma", "Becka"
  };

  print_v(v1);
  reverse_2(v1);
  print_v(v1);

  return 0;
}
Esempio n. 4
0
int print_g(GraphType* g) {
    if(g==NULL)
        return 0;
    GList* vlist = get_g_allv(g);
    GList* elist = get_g_alle(g);
    int l,n;
    printf("\nGraph------------------------------------------------------------\n");
    l = g_list_length(vlist);
    printf("Vertices: \n");
    for(n=0; n<l; n++) {
        VertexType* v = g_list_nth_data(vlist, n);
        print_v(v);
        printf(" | ");
    }
    printf("\n");

    l = g_list_length(elist);
    printf("Edges: \n");
    for(n=0; n<l; n++) {
        EdgeType* e = g_list_nth_data(elist, n);
        print_e(e);
        printf(" | ");
    }
    printf("\n");
    printf("-----------------------------------------------------------------\n");
    g_list_free(vlist);
    g_list_free(elist);
    return 0;
}
Esempio n. 5
0
int main(int argc, char** argv)
{
	int n=N;

	double in[N]={0.0545,    0.2442,    0.4026,    0.2442,    0.0545};
	double out[N],in_n[N], in2[N],in2_n[N];

	fftw_plan idct =	fftw_plan_r2r_1d(N, in, out, FFTW_REDFT01,
			FFTW_MEASURE);
	fftw_plan dct =	fftw_plan_r2r_1d(N, out, in2, FFTW_REDFT10,
			FFTW_MEASURE);


	for(int i = 0; i < n; i++)
		in_n[i]=in[i]/sqrt(2*n);

	in_n[0]*=sqrt(2);


	fftw_execute(idct);
	fftw_execute(dct);

	for(int i = 0; i < n; i++)
		in2_n[i]=in2[i]/sqrt(2*n);

	in2_n[0]/=sqrt(2);

	print_v(in,n,"in");
	print_v(in_n,n,"in_n");
	print_v(out,n,"out");
	print_v(in2,n,"in2");
	print_v(in2_n,n,"in2_n");

	fftw_destroy_plan(idct);
	fftw_destroy_plan(dct);

	return 0;
}
Esempio n. 6
0
int destroy_vertex(VertexType* v) {
    if(v==NULL) return 0;
    // GC
    int nref;
    if ( (nref = gcDef( (void *) v, VERTEX_T )) > 0 ) return nref;
#ifdef _DEBUG
    fprintf(stdout, "DEBUG: DESTROY VERTEX: ");
    print_v(v);
    fprintf(stdout, "\n");
    fprintf(stdout, "====== REMOVE ALL ATTR\n");
#endif
    g_hash_table_foreach(v->attributes, &destroy_attr_from_table, NULL);
    g_hash_table_destroy(v->attributes);
    EdgeType* e;
    int l = g_list_length(v->outEdges);
    int n = 0;
    while ( g_list_length(v->outEdges) > 0 ) {
#ifdef _DEBUG
        fprintf(stdout, "====== REMOVE OUTEdges %d/%d\n", n++, l );
#endif
        e = (EdgeType*) g_list_nth_data(v->outEdges, 0);
        v->outEdges = g_list_remove( v->outEdges, e );
    }
    l = g_list_length(v->inEdges);
    n = 0;
    while ( g_list_length(v->inEdges) > 0 ) {
#ifdef _DEBUG
        fprintf(stdout, "====== REMOVE INEdges %d/%d\n", n++, l );
#endif
        e = (EdgeType*) g_list_nth_data(v->inEdges, 0);
        v->inEdges = g_list_remove( v->inEdges, e );
    }
    l = g_list_length(v->ings);
#ifdef _DEBUG
    fprintf(stdout, "====== REMOVE me FROM ALL Gs %d/%d\n", n, l );
#endif
    /*    for(n=0; n<l; n++){
            GraphType* g = g_list_nth_data(v->ings, n);
            g_remove_vertex(g, v);
        }*/
#ifdef _DEBUG
    fprintf(stdout, "====== REMOVE MYSELF: outE, inE, ings\n");
#endif
    g_list_free(v->outEdges);
    g_list_free(v->inEdges);
    g_list_free(v->ings);
    free(v);
    return 0;
}
Esempio n. 7
0
int print_list(ListType* list){	
	if(list==NULL)
		die(-1, "list is NULL if function: print_list()\n");
    int i;
	int type = list->type;
	int length = g_list_length(list->list);
    printf("<List>: ");
	for(i=0; i<length; i++){
		switch(type){
			case VERTEX_T:
				print_v((VertexType*)g_list_nth_data(list->list, i));
				break;
			case EDGE_T:
				print_e((EdgeType*)g_list_nth_data(list->list, i));
				break;
            default: die(-1, "print_list: list print wrong type\n");
				break;
		}
        printf(" ");
	}
	printf("\n");
	return 0;
}
Esempio n. 8
0
int
main(int argc, char **argv)
{
	kstat_ctl_t	*kc;
	kstat_t		*ksp;
	kstat_named_t	*knp;
	struct vcpu	*vc;
	struct core	*core;
	struct pchip	*chip;
	struct link	**ins;
	char		*s;
	int		nspec;
	int		optc;
	int		opt_s = 0;
	int		opt_p = 0;
	int		opt_v = 0;
	int		ex = 0;

	cmdname = basename(argv[0]);


	(void) setlocale(LC_ALL, "");
#if !defined(TEXT_DOMAIN)
#define	TEXT_DOMAIN	"SYS_TEST"
#endif
	(void) textdomain(TEXT_DOMAIN);

	/* collect the kstats */
	if ((kc = kstat_open()) == NULL)
		die(_("kstat_open() failed"));

	if ((ksp = kstat_lookup(kc, "cpu_info", -1, NULL)) == NULL)
		die(_("kstat_lookup() failed"));

	for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {

		if (strcmp(ksp->ks_module, "cpu_info") != 0)
			continue;
		if (kstat_read(kc, ksp, NULL) == NULL)
			die(_("kstat_read() failed"));

		vc = find_link(&vcpus, ksp->ks_instance, &ins);
		if (vc == NULL) {
			vc = zalloc(sizeof (struct vcpu));
			vc->v_link.l_id = ksp->ks_instance;
			vc->v_link_core.l_id = ksp->ks_instance;
			vc->v_link_pchip.l_id = ksp->ks_instance;
			vc->v_link.l_ptr = vc;
			vc->v_link_core.l_ptr = vc;
			vc->v_link_pchip.l_ptr = vc;
			ins_link(ins, &vc->v_link);
		}

		if ((knp = kstat_data_lookup(ksp, "state")) != NULL) {
			vc->v_state = mystrdup(knp->value.c);
		} else {
			vc->v_state = "unknown";
		}

		if ((knp = kstat_data_lookup(ksp, "cpu_type")) != NULL) {
			vc->v_cpu_type = mystrdup(knp->value.c);
		}
		if ((knp = kstat_data_lookup(ksp, "fpu_type")) != NULL) {
			vc->v_fpu_type = mystrdup(knp->value.c);
		}

		if ((knp = kstat_data_lookup(ksp, "state_begin")) != NULL) {
			vc->v_state_begin = knp->value.l;
		}

		if ((knp = kstat_data_lookup(ksp, "clock_MHz")) != NULL) {
			vc->v_clock_mhz = knp->value.l;
		}

		if ((knp = kstat_data_lookup(ksp, "brand")) == NULL) {
			vc->v_brand = _("(unknown)");
		} else {
			vc->v_brand = mystrdup(knp->value.str.addr.ptr);
		}

		if ((knp = kstat_data_lookup(ksp, "socket_type")) == NULL) {
			vc->v_socket = "Unknown";
		} else {
			vc->v_socket = mystrdup(knp->value.str.addr.ptr);
		}

		if ((knp = kstat_data_lookup(ksp, "implementation")) == NULL) {
			vc->v_impl = _("(unknown)");
		} else {
			vc->v_impl = mystrdup(knp->value.str.addr.ptr);
		}
		/*
		 * Legacy code removed the chipid and cpuid fields... we
		 * do the same for compatibility.  Note that the original
		 * pattern is a bit strange, and we have to emulate this because
		 * on SPARC we *do* emit these.  The original pattern we are
		 * emulating is: $impl =~ s/(cpuid|chipid)\s*\w+\s+//;
		 */
		if ((s = strstr(vc->v_impl, "chipid")) != NULL) {
			char *x = s + strlen("chipid");
			while (isspace(*x))
				x++;
			if ((!isalnum(*x)) && (*x != '_'))
				goto nochipid;
			while (isalnum(*x) || (*x == '_'))
				x++;
			if (!isspace(*x))
				goto nochipid;
			while (isspace(*x))
				x++;
			(void) strcpy(s, x);
		}
nochipid:
		if ((s = strstr(vc->v_impl, "cpuid")) != NULL) {
			char *x = s + strlen("cpuid");
			while (isspace(*x))
				x++;
			if ((!isalnum(*x)) && (*x != '_'))
				goto nocpuid;
			while (isalnum(*x) || (*x == '_'))
				x++;
			if (!isspace(*x))
				goto nocpuid;
			while (isspace(*x))
				x++;
			(void) strcpy(s, x);
		}
nocpuid:

		if ((knp = kstat_data_lookup(ksp, "chip_id")) != NULL)
			vc->v_pchip_id = knp->value.l;
		chip = find_link(&pchips, vc->v_pchip_id, &ins);
		if (chip == NULL) {
			chip = zalloc(sizeof (struct pchip));
			chip->p_link.l_id = vc->v_pchip_id;
			chip->p_link.l_ptr = chip;
			ins_link(ins, &chip->p_link);
		}
		vc->v_pchip = chip;

		if ((knp = kstat_data_lookup(ksp, "core_id")) != NULL)
			vc->v_core_id = knp->value.l;
		core = find_link(&cores, vc->v_core_id, &ins);
		if (core == NULL) {
			core = zalloc(sizeof (struct core));
			core->c_link.l_id = vc->v_core_id;
			core->c_link.l_ptr = core;
			core->c_link_pchip.l_id = vc->v_core_id;
			core->c_link_pchip.l_ptr = core;
			core->c_pchip = chip;
			ins_link(ins, &core->c_link);
			chip->p_ncore++;
			(void) find_link(&chip->p_cores, core->c_link.l_id,
			    &ins);
			ins_link(ins, &core->c_link_pchip);
		}
		vc->v_core = core;



		/* now put other linkages in place */
		(void) find_link(&chip->p_vcpus, vc->v_link.l_id, &ins);
		ins_link(ins, &vc->v_link_pchip);
		chip->p_nvcpu++;

		(void) find_link(&core->c_vcpus, vc->v_link.l_id, &ins);
		ins_link(ins, &vc->v_link_core);
		core->c_nvcpu++;
	}

	(void) kstat_close(kc);

	nspec = 0;

	while ((optc = getopt(argc, argv, "pvs")) != EOF) {
		switch (optc) {
		case 's':
			opt_s = 1;
			break;
		case 'p':
			opt_p = 1;
			break;
		case 'v':
			opt_v = 1;
			break;
		default:
			usage(NULL);
		}
	}

	while (optind < argc) {
		long id;
		char *eptr;
		struct link *l;
		id = strtol(argv[optind], &eptr, 10);
		l = find_link(&vcpus, id, NULL);
		if ((*eptr != '\0') || (l == NULL)) {
			(void) fprintf(stderr,
			    _("%s: processor %s: Invalid argument\n"),
			    cmdname, argv[optind]);
			ex = 2;
		} else {
			((struct vcpu *)l->l_ptr)->v_doit = 1;
			((struct vcpu *)l->l_ptr)->v_pchip->p_doit = 1;
			((struct vcpu *)l->l_ptr)->v_core->c_doit = 1;
		}
		nspec++;
		optind++;
	}

	if (opt_s && opt_v) {
		usage(_("options -s and -v are mutually exclusive"));
	}
	if (opt_s && nspec != 1) {
		usage(_("must specify exactly one processor if -s used"));
	}
	if (opt_v && opt_p) {
		print_vp(nspec);
	} else if (opt_s && opt_p) {
		print_ps();
	} else if (opt_p) {
		print_p(nspec);
	} else if (opt_v) {
		print_v(nspec);
	} else if (opt_s) {
		print_s();
	} else {
		print_normal(nspec);
	}

	return (ex);
}
Esempio n. 9
0
int main() {
	int n,looplim = 10000;
	while(cin >> n) {
		vMat all_Mat;
		Mat sec_Mat;
		cout << "=======" << endl;
		cout << n << endl;
		Mat L;
		double start_t = clock();


		double ans = INF;
		double t3 = 0,t4 = 0;
		clock_t c1,c2;

		//step 0
		vd ans_v;
		for(int i = 0 ; i < n ; i++) {
			vd tmpl,x;
			for(int j = 0 ; j < n ; j++) {
				if(i == j) {x.push_back(1);}
				else {x.push_back(0);}
			}
			if(get_f(x) <= ans) {
				ans = get_f(x);
				ans_v = x;
			}
			for(int j = 0 ; j < n ; j++) {
				if(x[j] == 1) {
					tmpl.push_back(get_f(x));
				} else {
					tmpl.push_back(INF);
				}   
			}   

			L.push_back(tmpl);
		}

		int cnt = 0;
		vMat used_Mat;//,all_Mat;
		all_Mat.push_back(L);
		sec_Mat.push_back(get_sec(L));
		multimap<double,Mat> dMatmp;
		set<pvdi> st;
		set<pdi> stf;
		vector<set<pdi> > vst(n);
		set<int> used_idx;
		st.insert(make_pair(get_diag(L),all_Mat.size()-1));
		stf.insert(make_pair(L[0][0],all_Mat.size()-1));
		priority_queue<pair<double,int> , vector<pair<double,int> > , greater<pair<double,int> > > pq;
		//priority_queue<pair<double,int> > pq;
		pq.push(make_pair(get_d(L),all_Mat.size()-1));
		//O(min(loop,local min))
		int max_set_size = 1000000;
		int cut_cnt = 0;
		while(cnt++ < looplim && !pq.empty()) {
			if(pq.size() > 1000000) break;

			if(cnt % 1000 == 0) {
				cout << "cnt:" << cnt << endl;
				cout << "lb:" << pq.top().first << endl;
				cout << "f:" << ans << endl;
				cout << "size:" << pq.size() << endl;
				cout << "cut:" << cut_cnt << endl;
				cout << "time:" << (clock() - start_t)/CLOCKS_PER_SEC << endl;
				cout << "---" << endl;
			} 
			//step 1
			//select l in Lk with the smallest d
			double d = pq.top().first;
			int idx = pq.top().second; 
			pq.pop();
			L = all_Mat[idx];
			//print_Mat(L);
			//print_Mat(L);
			//cout << endl;
			if(used_idx.find(idx) != used_idx.end()){
				continue;
			}
			if(ans - d < eps) {
				break;
			}
			vd xs;
			for(int i = 0 ; i < L.size() ; i++) {
				//caution : division by zero 
				xs.push_back(d/L[i][i]);
			}

			//step 2
			double tmpf = get_f(xs);
			//print_v(xs);
			//cout << get_f(xs) << endl;
			if(tmpf <= ans) {
				ans = tmpf;
				ans_v = xs;
			}
			vd lk;
			for(int i = 0 ; i < xs.size() ; i++) {
				if(xs[i] > zero_boundary) lk.push_back(tmpf/xs[i]);
				else lk.push_back(INF);
			}
			vMat Lm;
			vi idxs = get_lower_idx_s(st,lk);
			//vi idxs = get_lower_idx(st,lk,vst);
			//vi idxs = get_lower_idx_s(st,lk);
			Mat Sec;
			for(int i = 0 ; i < idxs.size() ; i++) {
				if(used_idx.find(idxs[i]) == used_idx.end()){ 
					used_idx.insert(idxs[i]);
					Lm.push_back(all_Mat[idxs[i]]);
					Sec.push_back(sec_Mat[idxs[i]]);
				}
			}
			used_idx.insert(idx);
			//step 4
			//O(L- size * n * n^2)
			vd dlk = lk;
			for(int j = 0 ; j < Lm.size() ; j++) {
				Mat tmpL = Lm[j];
				vd tmplk = lk;
				//print_Mat(tmpL);
				//cout << endl;

				vi idx = get_swap_idx(tmplk,Sec[j]); 
				/*
				   cout << "s:" << endl;
				   for(int i = 0 ; i < idx.size() ; i++) {
				   cout << idx[i] << " ";
				   }
				   cout << endl;
				 */
				for(int i = 0 ; i < idx.size() ; i++) {
					L = tmpL;
					lk = tmplk;
					//print_Mat(L);
					swap(L[idx[i]],lk);
					//cout << "--" << endl;
					//print_v(Sec[j]);
					//cout << "v:" << is_valid_combination(L,Sec[j]) << " " << is_valid_combination(L) << endl;
					//if(get_d(L) > d) {
						all_Mat.push_back(L);
						sec_Mat.push_back(get_sec(L));
						st.insert(make_pair(get_diag(L),all_Mat.size()-1));
						stf.insert(make_pair(L[0][0],all_Mat.size()-1));
						pq.push(make_pair(get_d(L),all_Mat.size()-1));
					//}
					swap(L[idx[i]],lk);
				}
			}

			priority_queue<pair<double,int> , vector<pair<double,int> > , greater<pair<double,int> > > tmp_pq = pq;
			priority_queue<pair<double,int> , vector<pair<double,int> > , greater<pair<double,int> > > nxt_pq;
			int set_size = 0;
			while(!tmp_pq.empty()) {
				set_size++;
				int idx = tmp_pq.top().second;
				if(set_size < max_set_size) nxt_pq.push(tmp_pq.top());
				else {
					st.erase(make_pair(get_diag(all_Mat[idx]),idx));	
				}	
				tmp_pq.pop();
			}
			pq = nxt_pq;

		}
		cout << "cnt:" << cnt << endl;
		cout << "ans:" << ans << endl;
		cout << "ans_v:";
		print_v(ans_v);
	}
	return 0;
}