static int inline_sequence_test(IC_Env *env) { int i; long al[500]; m_s isi = {4711, {500, 10, al}}, *iso, *isr; for (i = 0; i < 500; i++) al[i]=i; fprintf(stdout, "\n======== m_i_inline_sequence test ======\n\n"); isr = m_i_inline_sequence_test(NULL, &isi, &iso, env); CHECK_EXCEPTION(env); RETURN_IF_OK(cmp_s(&isi, iso) && cmp_s(&isi, isr)); if (!cmp_s(&isi, iso)) { fprintf(stdout, " out parameter error, sent:\n"); print_s(&isi); fprintf(stdout, "got:\n"); print_s(iso); } if (!cmp_s(&isi, isr)) { fprintf(stdout, " result error, sent:\n"); print_s(&isi); fprintf(stdout, "got:\n"); print_s(isr); } CORBA_free(iso); CORBA_free(isr); return -1; }
__attribute__((no_instrument_function)) void not_main(void) { unsigned int ra; serial_init(); print_s("\n\rTesting SD CARD INITIALIZATION\n\r"); sd_init(); // list_root_directory(); FILE *fd; fd = fopen("TORNADO.JPG"); fwrite(fd,"Yaaayie",10); unsigned char *test = (unsigned char*)malloc(sizeof(unsigned char)*6); fread(fd,test,10); print_s("\n\rContents: "); for(int i=0;i<10;i++) print_ch(test[i]); free(test); free(fd); return; }
int main(void) { struct score tmp, *datap; int i, id; LLIST *list; int ret; list = llist_creat(sizeof(struct score)); for (i = 0; i < 7; i++) { tmp.id = i; tmp.math = 100 - i; snprintf(tmp.name, NAMESIZE, "stu%d", i); llist_insert(list, &tmp, LLIST_BACKWARD); } llist_travel(list, print_s); id = 4; ret = llist_fetch(list, &tmp, &id, id_cmp); printf("\n"); if (ret == -1) { printf("Can not find.\n"); } else { print_s(&tmp); } printf("\n"); llist_travel(list, print_s); #if 0 id = 8; llist_delet(list, &id, id_cmp); printf("\n"); llist_travel(list, print_s); id = 2; datap = llist_find(list, &id, id_cmp); if (datap == NULL) { printf("Can not find.\n"); } else { print_s(datap); } #endif llist_save(list, "stu.data"); llist_destroy(list); LLIST *list2 = llist_load("stu.data"); llist_travel(list2, print_s); llist_destroy(list2); return 0; }
int main() { struct score tmp,*datap; int i,id,ret; char name[] = "sstu1"; LLIST *handle; handle = llist_create(sizeof(struct score)); if(handle == NULL) return -1; for(i = 0; i < 6 ;i++) { tmp.id = i; tmp.math = 100-i; snprintf(tmp.name,NAMESIZE,"stu%d",i); llist_insert(handle,&tmp,LLIST_BACKWARD); } llist_travel(handle,print_s); printf("\n\n"); id = 3; ret = llist_fetch(handle,&id,id_cmp,&tmp); if(ret != -1) print_s(&tmp); printf("\n\n"); llist_travel(handle,print_s); llist_destroy(handle); // llist_delete(handle,&id,id_cmp); // llist_travel(handle,print_s); #if 0 // datap = llist_find(handle,&id,id_cmp); datap = llist_find(handle,name,name_cmp); if(datap == NULL) printf("can not find!\n"); else print_s(datap); #endif return 0; }
void print_s(CELLP cp, int mode) { //printf("[print_s: id=%x]", (int)cp->id); if(cp->id != _CELL) { pri_atom(cp, mode); } else { //fprintf(cur_fpo, "[%p]", cp); //pp(cp); fputc('(', cur_fpo); forever{ print_s(cp->car, mode); cp = cp->cdr; if(cp->id != _CELL) { break; } fputc(' ', cur_fpo); //fprintf(cur_fpo, "cdr[%p]", cp); //printf("-cdr-"); //pp(cp); } if(cp != (CELLP)nil) { fprintf(cur_fpo, " . "); pri_atom(cp,mode); } fputc(')', cur_fpo); } }
/* Local initialization */ void f(int x, int y, int z) { struct s loc_s = { x, y }; struct t loc_t = { x, z, y }; print_s("loc_s", loc_s); print_t("loc_t", loc_t); print_s("compound_s", (struct s) { y, x });
int display(char *file, t_max *max, int nbr_line, int nbr_col) { char *tmp; int fd; int i; char test; test = 0; i = 1; if ((fd = open(file, O_RDONLY)) == -1) return (-1); while (read(fd, &test, 1) > 0 && test != '\n') if ((tmp = (char*)malloc(sizeof(char) * (nbr_col + 1))) == NULL) return (-1); tmp[nbr_col++] = 0; while (i <= nbr_line) { if ((read(fd, tmp, nbr_col)) < 0) return (-1); if (i++ <= max->y_max - max->size || i - 1 > max->y_max) write(1, tmp, nbr_col); else print_s(tmp, max, nbr_col); } free(tmp); return (fd); }
static CELLP prin(CELLP args, int mode) { if (args->id != _CELL) { return error(NEA); } dirout(args->cdr); ec; print_s(args->car, mode); return args->car; }
int main() { LLIST *handle; int i ,ret, id = 3; char *name = "person2"; struct person_st tmp, *datap; handle = llist_create(sizeof(struct person_st)); if(handle== NULL) return -1; for(i = 0; i < 6; i++) { tmp.id = i; tmp.age = 20 + i; snprintf(tmp.name,NAMESIZE,"person%d",i); llist_insert(handle,&tmp,LLIST_FORWARD); } llist_travel(handle,print_s); printf("\n\n"); ret = llist_fetch(handle,name,name_cmp,&tmp); if(ret == 0) print_s(&tmp); printf("\n\n"); // llist_delete(handle,&id,id_cmp); // llist_travel(handle,print_s); #if 0 //datap = llist_find(handle,&id,id_cmp); datap = llist_find(handle,name,name_cmp); if(datap == NULL) printf("ca not find!\n"); else print_s(datap); #endif llist_destroy(handle); return 0; }
int main(int argc, char **argv) { int i; HC_DEF_S(s); HC_DEF_S(repr); /* */ for (i=1; i<=100; i++) { s_catc(s, i); } s_repr(repr, s); print_s("[", repr, "]\n"); assert(s_diffz(s, "\x01\x02\x03\x04\x05\x06\x07\x08\t\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcd") == 0); /* */ repr->len = 0; s_reprz(repr, "\x1\x2\x3"); print_s("[", repr, "]\n"); assert(s_diffz(repr, "\\x01\\x02\\x03") == 0); /* */ s_free(repr); s_free(s); return 0; }
void print_s(CELLP cp, int mode) // S式の表示 { if (cp->id != _CELL) { print_atom(cp, mode); } else { fputc('(', cur_fpo); for (;;) { print_s(cp->car, mode); cp = cp->cdr; if (cp->id != _CELL) { break; } fputc(' ', cur_fpo); } if (cp != (CELLP)nil) { fprintf(cur_fpo, " . "); print_atom(cp, mode); } fputc(')', cur_fpo); } }
void warn_S(Warn s, String *a) { print_s(wmsg[s], a); }
int main(int argc, char **argv) { HC_DEF_S(s); s_catz(s, "hello world of possibilities!"); HC_SAFE_CSTR(s); fprintf(stdout, "[%i][%i][%s]\n", s->len, s->a, s->s); s->len = 0; /* truncate string */ s_catn(s, "hi ", 3); fwrite(s->s, s->len, 1, stdout); s_copyc(s, 'f'); s_catz(s, "olk"); s_catc(s, 's'); s_catc(s, '!'); s_catc(s, '\n'); fwrite(s->s, s->len, 1, stdout); s_upper(s); fwrite(s->s, s->len, 1, stdout); s_lower(s); fwrite(s->s, s->len, 1, stdout); s_copyz(s, "aa"); assert(sdiff("aa", "aa") == 0); assert(s_diffz(s, "aa") == 0); assert(s_diffn(s, "aa", slen("aa")) == 0); assert(sdiff("aa", "aaz") < 0); assert(s_diffz(s, "aaz") < 0); assert(s_diffn(s, "aaz", slen("aaz")) < 0); assert(sdiff("aa", "a0z") > 0); assert(s_diffz(s, "a0z") > 0); assert(s_diffn(s, "a0z", slen("a0z")) > 0); assert(sdiff("aa", "0") > 0); assert(s_diffz(s, "0") > 0); assert(s_diffn(s, "0", slen("0")) > 0); assert(sdiff("aa", "0zz") > 0); assert(s_diffz(s, "0zz") > 0); assert(s_diffn(s, "0zz", slen("0zz")) > 0); assert(sdiff("aa", "a") > 0); assert(s_diffz(s, "a") > 0); assert(s_diffn(s, "a", slen("a")) > 0); assert(sdiff("aa", "a0") > 0); assert(s_diffz(s, "a0") > 0); assert(s_diffn(s, "a0", slen("a0")) > 0); s_free(s); /* */ assert(s_cat_u4_hex(s, 0) == 1); assert(s_diffz(s, "0") == 0); print_s("[", s, "]\n"); s->len = 0; assert(s_cat_i4_hex(s, 0) == 1); assert(s_diffz(s, "0") == 0); print_s("[", s, "]\n"); s->len = 0; assert(s_cat_u4_hex(s, 0xffffffff) == 8); assert(s_diffz(s, "ffffffff") == 0); print_s("[", s, "]\n"); s->len = 0; assert(s_cat_i4_hex(s, (int32_t)0xffffffff) == 2); assert(s_diffz(s, "-1") == 0); print_s("[", s, "]\n"); s_free(s); /* */ assert(s_cat_u4_dec(s, 0) == 1); assert(s_diffz(s, "0") == 0); print_s("[", s, "]\n"); s->len = 0; assert(s_cat_i4_dec(s, 0) == 1); assert(s_diffz(s, "0") == 0); print_s("[", s, "]\n"); s->len = 0; assert(s_cat_u4_dec(s, 0xffffffff) == 10); assert(s_diffz(s, "4294967295") == 0); print_s("[", s, "]\n"); s->len = 0; assert(s_cat_i4_dec(s, (int32_t)0xffffffff) == 2); assert(s_diffz(s, "-1") == 0); print_s("[", s, "]\n"); s_free(s); /* */ assert(s_cat_u4_base36(s, 0) == 1); assert(s_diffz(s, "0") == 0); print_s("[", s, "]\n"); s->len = 0; assert(s_cat_i4_base36(s, 0) == 1); assert(s_diffz(s, "0") == 0); print_s("[", s, "]\n"); s->len = 0; assert(s_cat_u4_base36(s, 0xffffffff) == 7); assert(s_diffz(s, "1z141z3") == 0); print_s("[", s, "]\n"); s->len = 0; assert(s_cat_i4_base36(s, (int32_t)0xffffffff) == 2); assert(s_diffz(s, "-1") == 0); print_s("[", s, "]\n"); s_free(s); /* */ { void *out; int putlen; HC_DEF_S(t); s_copyz(s, "hello world of possibilities!"); putlen = s_putlen(s); HC_ALLOC(out, putlen); assert(s_put(s, out) == putlen); assert(s_get(t, out) == putlen); assert(s_diff(s, t) == 0); s->len = 0; s_reprn(s, out, putlen); print_s("[", s, "]\n"); HC_FREE(out); s_free(t); } /* */ s_free(s); return 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); }
CELLP Copy(CELLP cp, int n, int a) { if(cp == (CELLP)nil) { return cp; } else if(ISSYSATOMP((ATOMP)cp)) { return cp; } //旧世代領域に居るやつ“自体”は無視するけど、そこから指されているやつは無視しちゃだめ // 一度処理した旧世代領域にいるやつにはCOPIEDフラグをたてて多重に処理してしまうことを防ぐ // 例 アトムfのfptrに (lambda (x) (... (f (plus x -1)) ...)) がはいっていて、fが旧世代 // 領域にあるとき、fptrのCopyingでふたたびfをCopyすることになる // gbc() の最後に、旧世代領域のすべてのcpflagからCOPIEDフラグを下ろす処理を加えている else if(ISOLDATOMP((ATOMP)cp)) { if(! (cp->cpflag & COPIED)) { cp->cpflag |= COPIED; Copying(&(((ATOMP)cp)->value), n, a); Copying(&(((ATOMP)cp)->plist), n, a); if(((ATOMP)cp)->ftype == _EXPR){ Copying(&(((ATOMP)cp)->fptr), n, a); } } return cp; } else if(ISOLDCELLP(cp)) { //printf("旧世代領域セル(%p)", cp); if(! (cp->cpflag & COPIED)) { //printf("からの深いGC"); cp->cpflag |= COPIED; Copying(&(cp->car), n, a); Copying(&(cp->cdr), n, a); } //printf("\n"); return cp; } else if(ISOLDNUMP((NUMP)cp)) // numberから指されるものはいまのところない { return cp; } else if(ISCELLP(cp) || ISATOMP((ATOMP)cp) || ISNUMP((NUMP)cp)) { if(cp->cpflag & COPIED) { return cp->forwarding; } else { char c = cp->id;//N// switch(c) { case _ATOM: if(a) { ATOMP to; copied_atom++; cp->age++; if(cp->age >= syoushinn_atom) { //promote_atom() はコピー先のアドレスを返す to = promote_atom(); assert(ISOLDATOMP(to)); promoted_atom++; } else { to = freeatomtop++; } cp->forwarding = memcpy(to, cp, sizeof(ATOM)); cp->cpflag |= COPIED; Copying(&(to->value), n, a); Copying(&(to->plist), n, a); if(to->ftype == _EXPR) { Copying(&(to->fptr), n, a); } //コピーした際はコピー先のアドレスを返す return (CELLP)to; } else//N// {//N// Copying(&(((ATOMP)cp)->value), n, a);//N// // printf("p[%d] ", ((ATOMP)cp)->plist); Copying(&(((ATOMP)cp)->plist), n, a);//N// // printf("f[%d] ", ((ATOMP)cp)->fptr); if(((ATOMP)cp)->ftype == _EXPR){ Copying(&(((ATOMP)cp)->fptr), n, a);//N// } return cp; }//N// case _CELL: { CELLP to; copied_cell++; cp->age++; if(cp->age >= syoushinn_cell) { //promoteはコピー先のアドレスを返す // TODO! 上のアトムと同様にpromote_cell() を実装しよう to = promote((CELLP)cp); promoted_cell++; } else { to = freecelltop++; } cp->forwarding = memcpy(to, cp, sizeof(CELL)); cp->cpflag |= COPIED; Copying(&(to->car), n, a); Copying(&(to->cdr), n, a); return to; } case _FIX: //FALL THROUT case _FLT: if(n) { NUMP to; cp->age++; copied_num++; if(cp->age >= syoushinn_num) { //promoteはコピー先のアドレスを返す // TODO! 上のアトムと同様にpromote_num() を実装しよう to = (NUMP)promote(cp); promoted_num++; } else { to = freenumtop++; } cp->forwarding = memcpy(to, cp, sizeof(NUM)); cp->cpflag |= COPIED; return (CELLP)to; } return cp; default://N// return (CELLP)error(ULO);//N// } } } else if(ISTOCELLP(cp)) { if(cp < freecelltop) // すでにコピーしたものであろう { return cp; } else { printf("\nCopyが変なポインタを受け取った(fromcelltop=%p tocelltop=%p freecelltop=%p):", fromcelltop, tocelltop, freecelltop); printf("\nアドレスはこんなの %p\n",cp); print_s(cp, ESCON); //getchar(); return cp; } } else if(ISTOATOMP((ATOMP)cp)) { if((ATOMP)cp < freeatomtop) // すでにコピーしたものであろう { return cp; } else { printf("\nCopyが変なポインタを受け取った:"); print_s(cp, ESCON); //getchar(); return cp; } } else if(ISTONUMP((NUMP)cp)) { if((NUMP)cp < freenumtop) // すでにコピーしたものであろう { return cp; } else { printf("\nCopyが変なポインタを受け取った:"); print_s(cp, ESCON); //getchar(); return cp; } } else { printf("\nCopyが超変なポインタを受け取った:"); print_s(cp, ESCON); //getchar(); return cp; } }
int main(int argc,char *argv[]) { char *s="character string"; print_s(s); return 0; }
static int print_f(void (*printchar_handler)(struct printchar_handler_data *d, int c), struct printchar_handler_data *printchar_data, double r, int width, int precision, unsigned int ops, int base, int with_exp, int is_shortened) { return print_s(printchar_handler, printchar_data, "%f", 0, 0, 0); }
int main(){ int snmax=10; // [2,k] int slmax=5; //[1,k] int secondmax=5; //[5,k] int pointmax=20; //[-k,k] int sn,sl,second,pointX,pointY; int street[100][500][2]={0}; int i,j,k; int m,n,t; int error=0; int temp[2]; int checkresult; int count[100]={0}; int remove=0; j=0; printf("sn:"); scanf("%d",&sn); while(j<sn){ k=0;//street point printf("sl:"); scanf("%d",&sl); while(k<sl){ if (error>=25){ printf("Error: failed to generate valid input for 25 stimultance attempts"); } scanf("%d,%d",&pointX,&pointY); temp[0]=pointX; temp[1]=pointY; //same point printf("same j,k: %d,%d\n",j,k); if(k>0){ if(street[j][k-1][0]==temp[0] && street[j][k-1][1]==temp[1]){ printf("same continue\n"); continue; } } //self printf("self j,k: %d,%d\n",j,k); for(n=0;n<k-1&&k>0;n++){ printf("self: %d,%d,%d,%d \n",street[j][n][1],street[j][n+1][1],street[j][k-1][1],temp[1]); checkresult = check(street[j][n],street[j][n+1],street[j][k-1],temp); if(checkresult == 0){ printf("overlap\n"); error++; break; } } //self wrong no k++ if(n<k-1&&k>0){ printf("self continue\n"); continue; } //other t=0; for(m=0;m<j&&k>0;m++){ printf("other j,k,count[last]: %d,%d,%d\n",j,k,count[j-1]); for(n=0;n<count[t]-1;n++){ printf("other m,n,t,count[t]: %d,%d,%d,%d\n",m,n,t,count[t]); printf("other: %d,%d,%d,%d\n",street[m][n][1],street[m][n+1][1],street[j][k-1][1],temp[1]); checkresult = check(street[m][n],street[m][n+1],street[j][k-1],temp); if(checkresult == 0){ printf("overlap\n"); error++; break; } } if(n<count[t]-1){ break; } t++; } //other wrong no k++ if(m<j&&k>0){ printf("other continue\n"); continue; } street[j][k][0]=pointX; street[j][k][1]=pointY; count[j]++; k++; print_s(street,sn,sl); printf("total end\n"); } j++; } return 0; }
/* While we're working: * compute better solutions for T seconds * send my fit back to the master process. * get a number back. if it's my rank, broadcast my s array to everyone! */ void driver(int rank, int np, data_t D, int n, int k, double p, double tol, long sec, long maxsec) { srand(time(NULL) + rank); int s[n]; gen_starting_set(n, k, s); time_t start = time(0), fullstart = start; double fit = 0, oldfit = 0; int run = 0, stop = 0; double *fits = NULL; if (rank == 0) fits = (double *) malloc(sizeof(double) * np); do { start = time(0); do { int u, v; fit = NEXT_STATE(D, n, s, k, p, &u, &v, run); if (u >= 0) s[u] = 0; if (v >= 0) s[v] = 1; } while(difftime(time(0), start) < sec); //printf("Run %d, rank %d, fit %g\n", run, rank, fit); MPI_Gather(&fit, 1, MPI_DOUBLE, fits, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); int new_rank = 0; /* Master process: find best fit. */ if (rank == 0) { double max = 0; for (int i = 0; i < np; i++) { printf("Run %d, rank %d, fit %g\n", run, i, fits[i]); if (fits[i] > max) { max = fits[i]; new_rank = i; } } if (max - oldfit < tol || (difftime(time(0), fullstart) > maxsec)) { stop = 1; } oldfit = max; } MPI_Bcast(&new_rank, 1, MPI_INT, 0, MPI_COMM_WORLD); /* update s, or send it... */ MPI_Bcast(s, n, MPI_INT, new_rank, MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD); if (rank == new_rank) { printf("Best fit: %f (rank %d)\n", fit, new_rank); print_s(s, n); } run++; MPI_Bcast(&stop, 1, MPI_INT, 0, MPI_COMM_WORLD); } while(!stop); }
static void cpu_desc_summary (struct cpu_desc *cpudesc) { printf ("-= CPU Characteristics =-\n"); print_s("Architecture:", cpu_desc_get_architecture (cpudesc)); int cpu_mode = cpu_desc_get_mode (cpudesc); if (cpu_mode) { char mbuf[32], *p = mbuf; if (cpu_mode & MODE_32BIT) { strcpy (p, "32-bit, "); p += 8; } if (cpu_mode & MODE_64BIT) { strcpy (p, "64-bit, "); p += 8; } *(p - 2) = '\0'; print_s("CPU op-mode(s):", mbuf); } #if !defined(WORDS_BIGENDIAN) print_s("Byte Order:", "Little Endian"); #else print_s("Byte Order:", "Big Endian"); #endif int cpu, ncpus = cpu_desc_get_ncpus (cpudesc); print_d("CPU(s):", ncpus); unsigned int nsockets, ncores, nthreads; get_cputopology_read (&nsockets, &ncores, &nthreads); print_u("Thread(s) per core:", nthreads); print_u("Core(s) per socket:", ncores); print_u("Socket(s):", nsockets); print_s("Vendor ID:", cpu_desc_get_vendor (cpudesc)); print_s("CPU Family:", cpu_desc_get_family (cpudesc)); print_s("Model:", cpu_desc_get_model (cpudesc)); print_s("Model name:", cpu_desc_get_model_name (cpudesc)); for (cpu = 0; cpu < ncpus; cpu++) { printf ("-CPU%d-\n", cpu); bool cpu_hot_pluggable = get_processor_is_hot_pluggable (cpu); int cpu_online = get_processor_is_online (cpu); print_s ("CPU is Hot Pluggable:", cpu_hot_pluggable ? (cpu_online ? "yes (online)" : "yes (offline)") : "no"); unsigned long latency = cpufreq_get_transition_latency (cpu); if (latency) print_s("Maximum Transition Latency:", cpufreq_duration_to_string (latency)); unsigned long freq_kernel = cpufreq_get_freq_kernel (cpu); if (freq_kernel > 0) print_s("Current CPU Frequency:", cpufreq_freq_to_string (freq_kernel)); struct cpufreq_available_frequencies *cpufreqs, *curr; cpufreqs = curr = cpufreq_get_available_freqs (cpu); if (curr) { print_key_s("Available CPU Frequencies:"); while (curr) { printf ("%s ", cpufreq_freq_to_string (cpufreq_get_available_freqs_value (curr))); curr = cpufreq_get_available_freqs_next (curr); } printf ("\n"); cpufreq_available_frequencies_unref(cpufreqs); } unsigned long freq_min, freq_max; if (0 == cpufreq_get_hardware_limits (cpu, &freq_min, &freq_max)) { char *min_s = cpufreq_freq_to_string (freq_min), *max_s = cpufreq_freq_to_string (freq_max); print_range_s("Hardware Limits:", min_s, max_s); free (min_s); free (max_s); } char *freq_governor = cpufreq_get_governor (cpu); if (freq_governor) { print_s ("CPU Freq Current Governor:", freq_governor); free (freq_governor); } char *freq_governors = cpufreq_get_available_governors (cpu); if (freq_governors) { print_s ("CPU Freq Available Governors:", freq_governors); free (freq_governors); } char *freq_driver = cpufreq_get_driver (cpu); if (freq_driver) { print_s ("CPU Freq Driver:", freq_driver); free (freq_driver); } } char *cpu_virtflag = cpu_desc_get_virtualization_flag (cpudesc); if (cpu_virtflag) print_s("Virtualization:", cpu_virtflag); }
static int subform(STR tp, CELLP args) { CELLP tmp = args; STR tps; char c, s, fmt[NAMELEN] = {0}; while (*tp != '\0') { // "~"が出てくるまでは単に出力するだけ for (;; ++tp) { if (*tp == '\0') { return 0; } if (*tp == '~') { break; } if (iskanji(*tp)) { fputc(*tp++ , cur_fpo); } fputc(*tp, cur_fpo); } // 各種指定のチェック tps = tp; if (*(++tp) == '-') { ++tp; } while (isdigit(*tp)) { ++tp; } if (*tp == ',') { ++tp; } while (isdigit(*tp)) { ++tp; } if (*tp == ':') { ++tp; s = 0; } else { s = 1; } if (*tp == '@') { ++tp; c = 1; } else { c = 0; } switch (*tp) { case 'd': case 'x': case 'o': if (s) { // 継続オプションのないときは引数をすすめる tmp = args; args = args->cdr; } if (tmp->id != _CELL) { return (int)error(NEA); } if (tmp->car->id != _FIX) { return (int)error(IAF); } ins_l((STR)fmt, tps, ++tp); fprintf(cur_fpo, fmt, ((NUMP)(tmp->car))->value.fix); break; case 'e': case 'f': case 'g': if (s) { tmp = args; args = args->cdr; } if (tmp->id != _CELL) { return (int)error(IAFL); } if (tmp->car->id != _FLT) { return (int)error(IAFL); } copyform((STR)fmt, tps, ++tp); fprintf(cur_fpo, fmt, ((NUMP)(tmp->car))->value.flt); break; case 'c': if (s) { tmp = args; args = args->cdr; } if (tmp->id != _CELL) { return (int)error(NEA); } if (tmp->car->id != _FIX) { return (int)error(IAF); } copyform((STR)fmt, tps, ++tp); fprintf(cur_fpo, fmt, ((NUMP)(tmp->car))->value.fix); break; case 'a': if (s) { tmp = args; args = args->cdr; } if (tmp->id != _CELL) { return (int)error(NEA); } if (tmp->car->id != _ATOM) { // 引数がシンボルでないときはprincで出力 print_s(tmp->car, ESCOFF); ++tp; } else { // 引数がシンボルのときは、引字名を"%s"出力する copyform((STR)fmt, tps, ++tp); *(fmt + (tp - tps) -1) = 's'; fprintf(cur_fpo, fmt, ((ATOMP)(tmp->car))->name); } break; case 's': if (s) { tmp = args; args = args->cdr; } if (tmp->id != _CELL) { return (int)error(NEA); } print_s(tmp->car, ESCON); ++tp; break; case 'p': if (s) { tmp = args; args = args->cdr; } ++tp; if (tmp->id != _CELL) { return (int)error(NEA); } if (tmp->car->id != _FIX) { break; } if (((NUMP)(tmp->car))->value.fix == 1) { if (c) { fputc('y', cur_fpo); } break; } if (c) { fprintf(cur_fpo, "ies"); } else { fputc('s', cur_fpo); } break; case 'n': fputc('\n', cur_fpo); ++tp; break; case 'r': fputc('\r', cur_fpo); ++tp; break; case 't': fputc('\t', cur_fpo); ++tp; break; case 'b': fputc('\b', cur_fpo); ++tp; break; default: args = tmp; copyform((STR)fmt, ++tps, ++tp); fprintf(cur_fpo, fmt); } } return 0; }