SetInterestsInfo(unsigned short id, ICQUser *u) : ICQEvent(EVENT_INFO_CHANGED) { m_nId = id; INIT(Interests); }
int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { INIT(RMDIR); PATH; POST; }
int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { INIT(UNLINK); PATH; POST; }
static __init int test_atomic64(void) { long long v0 = 0xaaa31337c001d00dLL; long long v1 = 0xdeadbeefdeafcafeLL; long long v2 = 0xfaceabadf00df001LL; long long onestwos = 0x1111111122222222LL; long long one = 1LL; atomic64_t v = ATOMIC64_INIT(v0); long long r = v0; BUG_ON(v.counter != r); atomic64_set(&v, v1); r = v1; BUG_ON(v.counter != r); BUG_ON(atomic64_read(&v) != r); INIT(v0); atomic64_add(onestwos, &v); r += onestwos; BUG_ON(v.counter != r); INIT(v0); atomic64_add(-one, &v); r += -one; BUG_ON(v.counter != r); INIT(v0); r += onestwos; BUG_ON(atomic64_add_return(onestwos, &v) != r); BUG_ON(v.counter != r); INIT(v0); r += -one; BUG_ON(atomic64_add_return(-one, &v) != r); BUG_ON(v.counter != r); INIT(v0); atomic64_sub(onestwos, &v); r -= onestwos; BUG_ON(v.counter != r); INIT(v0); atomic64_sub(-one, &v); r -= -one; BUG_ON(v.counter != r); INIT(v0); r -= onestwos; BUG_ON(atomic64_sub_return(onestwos, &v) != r); BUG_ON(v.counter != r); INIT(v0); r -= -one; BUG_ON(atomic64_sub_return(-one, &v) != r); BUG_ON(v.counter != r); INIT(v0); atomic64_inc(&v); r += one; BUG_ON(v.counter != r); INIT(v0); r += one; BUG_ON(atomic64_inc_return(&v) != r); BUG_ON(v.counter != r); INIT(v0); atomic64_dec(&v); r -= one; BUG_ON(v.counter != r); INIT(v0); r -= one; BUG_ON(atomic64_dec_return(&v) != r); BUG_ON(v.counter != r); INIT(v0); BUG_ON(atomic64_xchg(&v, v1) != v0); r = v1; BUG_ON(v.counter != r); INIT(v0); BUG_ON(atomic64_cmpxchg(&v, v0, v1) != v0); r = v1; BUG_ON(v.counter != r); INIT(v0); BUG_ON(atomic64_cmpxchg(&v, v2, v1) != v0); BUG_ON(v.counter != r); INIT(v0); BUG_ON(atomic64_add_unless(&v, one, v0)); BUG_ON(v.counter != r); INIT(v0); BUG_ON(!atomic64_add_unless(&v, one, v1)); r += one; BUG_ON(v.counter != r); #if defined(CONFIG_X86) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \ defined(CONFIG_S390) || defined(_ASM_GENERIC_ATOMIC64_H) || defined(CONFIG_ARM) INIT(onestwos); BUG_ON(atomic64_dec_if_positive(&v) != (onestwos - 1)); r -= one; BUG_ON(v.counter != r); INIT(0); BUG_ON(atomic64_dec_if_positive(&v) != -one); BUG_ON(v.counter != r); INIT(-one); BUG_ON(atomic64_dec_if_positive(&v) != (-one - one)); BUG_ON(v.counter != r); #else #warning Please implement atomic64_dec_if_positive for your architecture, and add it to the IF above #endif INIT(onestwos); BUG_ON(!atomic64_inc_not_zero(&v)); r += one; BUG_ON(v.counter != r); INIT(0); BUG_ON(atomic64_inc_not_zero(&v)); BUG_ON(v.counter != r); INIT(-one); BUG_ON(!atomic64_inc_not_zero(&v)); r += one; BUG_ON(v.counter != r); #ifdef CONFIG_X86 printk(KERN_INFO "atomic64 test passed for %s platform %s CX8 and %s SSE\n", #ifdef CONFIG_X86_64 "x86-64", #elif defined(CONFIG_X86_CMPXCHG64) "i586+", #else "i386+", #endif boot_cpu_has(X86_FEATURE_CX8) ? "with" : "without", boot_cpu_has(X86_FEATURE_XMM) ? "with" : "without"); #else printk(KERN_INFO "atomic64 test passed\n"); #endif return 0; }
//! //! Processes input XML file (e.g., instance metadata) into output XML file or string (e.g., for libvirt) //! using XSL-T specification file (e.g., libvirt.xsl) //! //! @param[in] xsltStylesheetPath a string containing the path to the XSLT Stylesheet //! @param[in] inputXmlPath a string containing the path of the input XML document //! @param[in] outputXmlPath a string containing the path of the output XML document //! @param[out] outputXmlBuffer a string that will contain the output XML data if non NULL and non-0 length. //! @param[in] outputXmlBufferSize the length of outputXmlBuffer //! //! @return EUCA_OK on success or proper error code. Known error code returned include EUCA_ERROR and EUCA_IO_ERROR. //! static int apply_xslt_stylesheet(const char *xsltStylesheetPath, const char *inputXmlPath, const char *outputXmlPath, char *outputXmlBuffer, int outputXmlBufferSize) { int err = EUCA_OK; int i = 0; int j = 0; int bytes = 0; int buf_size = 0; char c = '\0'; FILE *fp = NULL; xmlChar *buf = NULL; boolean applied_ok = FALSE; xmlDocPtr doc = NULL; xsltStylesheetPtr cur = NULL; xsltTransformContextPtr ctxt = NULL; xmlDocPtr res = NULL; INIT(); if ((cur = xsltParseStylesheetFile((const xmlChar *)xsltStylesheetPath)) != NULL) { if ((doc = xmlParseFile(inputXmlPath)) != NULL) { ctxt = xsltNewTransformContext(cur, doc); // need context to get result xsltSetCtxtParseOptions(ctxt, 0); //! @todo do we want any XSL-T parsing options? res = xsltApplyStylesheetUser(cur, doc, NULL, NULL, NULL, ctxt); // applies XSLT to XML applied_ok = ((ctxt->state == XSLT_STATE_OK) ? TRUE : FALSE); // errors are communicated via ctxt->state xsltFreeTransformContext(ctxt); if (res && applied_ok) { // save to a file, if path was provied if (outputXmlPath != NULL) { if ((fp = fopen(outputXmlPath, "w")) != NULL) { if ((bytes = xsltSaveResultToFile(fp, res, cur)) == -1) { LOGERROR("failed to save XML document to %s\n", outputXmlPath); err = EUCA_IO_ERROR; } fclose(fp); } else { LOGERROR("failed to create file %s\n", outputXmlPath); err = EUCA_IO_ERROR; } } // convert to an ASCII buffer, if such was provided if (err == EUCA_OK && outputXmlBuffer != NULL && outputXmlBufferSize > 0) { if (xsltSaveResultToString(&buf, &buf_size, res, cur) == 0) { // success if (buf_size < outputXmlBufferSize) { bzero(outputXmlBuffer, outputXmlBufferSize); for (i = 0, j = 0; i < buf_size; i++) { c = ((char)buf[i]); if (c != '\n') // remove newlines outputXmlBuffer[j++] = c; } } else { LOGERROR("XML string buffer is too small (%d > %d)\n", buf_size, outputXmlBufferSize); err = EUCA_ERROR; } xmlFree(buf); } else { LOGERROR("failed to save XML document to a string\n"); err = EUCA_ERROR; } } } else { LOGERROR("failed to apply stylesheet %s to %s\n", xsltStylesheetPath, inputXmlPath); err = EUCA_ERROR; } if (res != NULL) xmlFreeDoc(res); xmlFreeDoc(doc); } else { LOGERROR("failed to parse XML document %s\n", inputXmlPath); err = EUCA_ERROR; } xsltFreeStylesheet(cur); } else { LOGERROR("failed to open and parse XSL-T stylesheet file %s\n", xsltStylesheetPath); err = EUCA_IO_ERROR; } return (err); }
/* * step - map set of states reachable before char to set reachable after */ static states step(struct re_guts *g, sopno start, /* start state within strip */ sopno stop, /* state after stop state within strip */ states bef, /* states reachable before */ wint_t ch, /* character or NONCHAR code */ states aft) /* states already known reachable after */ { cset *cs; sop s; sopno pc; onestate here; /* note, macros know this name */ sopno look; int i; for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) { s = g->strip[pc]; switch (OP(s)) { case OEND: assert(pc == stop-1); break; case OCHAR: /* only characters can match */ assert(!NONCHAR(ch) || ch != OPND(s)); if (ch == OPND(s)) FWD(aft, bef, 1); break; case OBOL: if (ch == BOL || ch == BOLEOL) FWD(aft, bef, 1); break; case OEOL: if (ch == EOL || ch == BOLEOL) FWD(aft, bef, 1); break; case OBOW: if (ch == BOW) FWD(aft, bef, 1); break; case OEOW: if (ch == EOW) FWD(aft, bef, 1); break; case OANY: if (!NONCHAR(ch)) FWD(aft, bef, 1); break; case OANYOF: cs = &g->sets[OPND(s)]; if (!NONCHAR(ch) && CHIN(cs, ch)) FWD(aft, bef, 1); break; case OBACK_: /* ignored here */ case O_BACK: FWD(aft, aft, 1); break; case OPLUS_: /* forward, this is just an empty */ FWD(aft, aft, 1); break; case O_PLUS: /* both forward and back */ FWD(aft, aft, 1); i = ISSETBACK(aft, OPND(s)); BACK(aft, aft, OPND(s)); if (!i && ISSETBACK(aft, OPND(s))) { /* oho, must reconsider loop body */ pc -= OPND(s) + 1; INIT(here, pc); } break; case OQUEST_: /* two branches, both forward */ FWD(aft, aft, 1); FWD(aft, aft, OPND(s)); break; case O_QUEST: /* just an empty */ FWD(aft, aft, 1); break; case OLPAREN: /* not significant here */ case ORPAREN: FWD(aft, aft, 1); break; case OCH_: /* mark the first two branches */ FWD(aft, aft, 1); assert(OP(g->strip[pc+OPND(s)]) == OOR2); FWD(aft, aft, OPND(s)); break; case OOR1: /* done a branch, find the O_CH */ if (ISSTATEIN(aft, here)) { for (look = 1; OP(s = g->strip[pc+look]) != O_CH; look += OPND(s)) assert(OP(s) == OOR2); FWD(aft, aft, look + 1); } break; case OOR2: /* propagate OCH_'s marking */ FWD(aft, aft, 1); if (OP(g->strip[pc+OPND(s)]) != O_CH) { assert(OP(g->strip[pc+OPND(s)]) == OOR2); FWD(aft, aft, OPND(s)); } break; case O_CH: /* just empty */ FWD(aft, aft, 1); break; default: /* ooooops... */ assert(0); break; } } return (aft); }
int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { INIT(FSTAT); req->file = file; POST; }
int main(int argc, char *argv[]) { long portno; int i, con_count=1; time_t t1,t2,t3,t4; char wbuffer[256]; int connlist[1024*65]; int result[1024*65]; struct hostent *server; struct sockaddr_in serv_addr; INIT(); if (argc != 4) { fprintf(stderr,"Usage:\n\t%s hostname port clients\n\n", argv[0]); exit(0); } con_count = atol(argv[3]); if (con_count<1) con_count=1; if (con_count>1024*65) con_count=1024*65; portno = atol(argv[2]); if (portno<1l || portno>0xFFFFl) { fprintf(stderr, "ERROR, invalid port\n"); exit(0); } server = gethostbyname(argv[1]); if (server == NULL) { fprintf(stderr, "ERROR, no such host\n"); exit(0); } memset(&serv_addr, 0, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; memcpy(server->h_addr, &serv_addr.sin_addr.s_addr, server->h_length); serv_addr.sin_port = htons((short)portno); sprintf(wbuffer, "GET / HTTP/1.0\r\n\r\n"); t1 = time(0); for (i=0;i<con_count;i++) { result[i] = connlist[i] = connect_to_server(&serv_addr); } t2 = time(0); for (i=0;i<con_count;i++) { if (result[i]>=0) { result[i] = send_to_server(connlist[i], wbuffer); } } t3 = time(0); for (i=0;i<con_count;i++) { if (result[i]>=0) { result[i] = read_from_server(connlist[i]); } } t4 = time(0); printf("\n"); printf("conn: %.0lf\n", difftime(t2,t1)); printf("write: %.0lf\n", difftime(t3,t2)); printf("read: %.0lf\n", difftime(t4,t3)); for (i=-10;i<1000;i++) { int j,cnt=0; for(j=0;j<con_count;j++) { if (result[j]==i) cnt++; } if (cnt>0) { printf("%5i\t%7u\n", i, cnt); } } return 0; }
static __init void test_atomic64(void) { long long v0 = 0xaaa31337c001d00dLL; long long v1 = 0xdeadbeefdeafcafeLL; long long v2 = 0xfaceabadf00df001LL; long long onestwos = 0x1111111122222222LL; long long one = 1LL; atomic64_t v = ATOMIC64_INIT(v0); long long r = v0; BUG_ON(v.counter != r); atomic64_set(&v, v1); r = v1; BUG_ON(v.counter != r); BUG_ON(atomic64_read(&v) != r); TEST(64, add, +=, onestwos); TEST(64, add, +=, -one); TEST(64, sub, -=, onestwos); TEST(64, sub, -=, -one); TEST(64, or, |=, v1); TEST(64, and, &=, v1); TEST(64, xor, ^=, v1); TEST(64, andnot, &= ~, v1); RETURN_FAMILY_TEST(64, add_return, +=, onestwos); RETURN_FAMILY_TEST(64, add_return, +=, -one); RETURN_FAMILY_TEST(64, sub_return, -=, onestwos); RETURN_FAMILY_TEST(64, sub_return, -=, -one); INIT(v0); atomic64_inc(&v); r += one; BUG_ON(v.counter != r); INIT(v0); atomic64_dec(&v); r -= one; BUG_ON(v.counter != r); INC_RETURN_FAMILY_TEST(64, v0); DEC_RETURN_FAMILY_TEST(64, v0); XCHG_FAMILY_TEST(64, v0, v1); CMPXCHG_FAMILY_TEST(64, v0, v1, v2); INIT(v0); BUG_ON(atomic64_add_unless(&v, one, v0)); BUG_ON(v.counter != r); INIT(v0); BUG_ON(!atomic64_add_unless(&v, one, v1)); r += one; BUG_ON(v.counter != r); #ifdef CONFIG_ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE INIT(onestwos); BUG_ON(atomic64_dec_if_positive(&v) != (onestwos - 1)); r -= one; BUG_ON(v.counter != r); INIT(0); BUG_ON(atomic64_dec_if_positive(&v) != -one); BUG_ON(v.counter != r); INIT(-one); BUG_ON(atomic64_dec_if_positive(&v) != (-one - one)); BUG_ON(v.counter != r); #else #warning Please implement atomic64_dec_if_positive for your architecture and select the above Kconfig symbol #endif INIT(onestwos); BUG_ON(!atomic64_inc_not_zero(&v)); r += one; BUG_ON(v.counter != r); INIT(0); BUG_ON(atomic64_inc_not_zero(&v)); BUG_ON(v.counter != r); INIT(-one); BUG_ON(!atomic64_inc_not_zero(&v)); r += one; BUG_ON(v.counter != r); }
SetAboutInfo(unsigned short id, ICQUser *u) : ICQEvent(EVENT_INFO_CHANGED) { m_nId = id; INIT(About); }
int deliver (FILE *f,unsigned long msglen,char *user) { MAILSTREAM *ds = NIL; char *s,*mailbox,tmp[MAILTMPLEN],path[MAILTMPLEN]; STRING st; struct stat sbuf; /* have a mailbox specifier? */ if ((mailbox = strchr (user,'+')) != NULL) { *mailbox++ = '\0'; /* yes, tie off user name */ if (!*mailbox || !compare_cstring ((unsigned char *) mailbox,"INBOX")) mailbox = NIL; /* user+ and user+INBOX same as user */ } if (!*user) user = myusername (); else if (strcmp (user,myusername ())) return fail ("can't deliver to other user",EX_CANTCREAT); sprintf (tmp,"delivering to %.80s+%.80s",user,mailbox ? mailbox : "INBOX"); mm_dlog (tmp); /* prepare stringstruct */ INIT (&st,file_string,(void *) f,msglen); if (mailbox) { /* non-INBOX name */ switch (mailbox[0]) { /* make sure a valid name */ default: /* other names, try to deliver if not INBOX */ if ((strlen (mailbox) <= NETMAXMBX) && !strstr (mailbox,"..") && !strstr (mailbox,"//") && !strstr (mailbox,"/~") && mailboxfile (path,mailbox) && path[0] && !deliver_safely (NIL,&st,mailbox,path,tmp)) return NIL; case '%': case '*': /* wildcards not valid */ case '/': /* absolute path names not valid */ case '~': /* user names not valid */ sprintf (tmp,"invalid mailbox name %.80s+%.80s",user,mailbox); mm_log (tmp,WARN); break; } mm_dlog ("retrying delivery to INBOX"); SETPOS (&st,0); /* rewind stringstruct just in case */ } /* no -I, resolve "INBOX" into path */ if (mailboxfile (path,mailbox = "INBOX") && !path[0]) { /* clear box, get generic INBOX prototype */ if (!(ds = mail_open (NIL,"INBOX",OP_PROTOTYPE))) fatal ("no INBOX prototype"); /* standard system driver? */ if (!strcmp (ds->dtb->name,"unix") || !strcmp (ds->dtb->name,"mmdf")) { strcpy (path,sysinbox ());/* use system INBOX */ if (!lstat (path,&sbuf)) /* deliver to existing system INBOX */ return deliver_safely (ds,&st,mailbox,path,tmp); } else { /* other driver, try ~/INBOX */ if ((mailboxfile (path,"&&&&&") == path) && (s = strstr (path,"&&&&&")) && strcpy (s,"INBOX") && !lstat (path,&sbuf)){ /* deliver to existing ~/INBOX */ sprintf (tmp,"#driver.%s/INBOX",ds->dtb->name); return deliver_safely (ds,&st,cpystr (tmp),path,tmp); } } /* not dummy, deliver to driver imputed path */ if (strcmp (ds->dtb->name,"dummy")) return (ibxpath (ds,&mailbox,path) && !lstat (path,&sbuf)) ? deliver_safely (ds,&st,mailbox,path,tmp) : fail ("unable to resolve INBOX path",EX_CANTCREAT); /* dummy, empty imputed append path exist? */ if (ibxpath (ds = default_proto (T),&mailbox,path) && !lstat (path,&sbuf) && !sbuf.st_size) return deliver_safely (ds,&st,mailbox,path,tmp); /* impute path that we will create */ if (!ibxpath (ds = default_proto (NIL),&mailbox,path)) return fail ("unable to resolve INBOX",EX_CANTCREAT); } /* black box, must create, get create proto */ else if (lstat (path,&sbuf)) ds = default_proto (NIL); else { /* black box, existing file */ /* empty file, get append prototype */ if (!sbuf.st_size) ds = default_proto (T); /* non-empty, get prototype from its data */ else if (!(ds = mail_open (NIL,"INBOX",OP_PROTOTYPE))) fatal ("no INBOX prototype"); /* error if unknown format */ if (!strcmp (ds->dtb->name,"phile")) return fail ("unknown format INBOX",EX_UNAVAILABLE); /* otherwise can deliver to it */ return deliver_safely (ds,&st,mailbox,path,tmp); } sprintf (tmp,"attempting to create mailbox %.80s path %.80s",mailbox,path); mm_dlog (tmp); /* supplicate to the Evil One */ if (!path_create (ds,path)) return fail ("can't create INBOX",EX_CANTCREAT); sprintf (tmp,"created %.80s",path); mm_dlog (tmp); /* deliver the message */ return deliver_safely (ds,&st,mailbox,path,tmp); }
SetWorkInfo(unsigned short id, ICQUser *u) : ICQEvent(EVENT_INFO_CHANGED) { m_nId = id; INIT(WorkCity); INIT(WorkState); INIT(WorkPhone); INIT(WorkFax); INIT(WorkAddress); INIT(WorkZip); INIT(WorkCountry); INIT(WorkName); INIT(WorkDepartment); INIT(WorkPosition); INIT(Occupation); INIT(WorkHomepage); }
SetMainInfo(unsigned short id, ICQUser *u) : ICQEvent(EVENT_INFO_CHANGED) { m_nId = id; INIT(Nick); INIT(FirstName); INIT(LastName); INIT(EMail); INIT(City); INIT(State); INIT(HomePhone); INIT(HomeFax); INIT(Address); INIT(PrivateCellular); INIT(Zip); INIT(Country); INIT(TimeZone); INIT(HiddenEMail); }
SetMailInfo(unsigned short id, ICQUser *u) : ICQEvent(EVENT_INFO_CHANGED) { m_nId = id; INIT(EMails); }
static void test() { string x,y,xx,yy,tag,mess,en_mess,pri,m; INIT(x); INIT(y); INIT(xx); INIT(yy); INIT(tag); INIT(mess); INIT(en_mess); INIT(pri); INIT(m); mess.len = 10; mess.buf = "helloword"; int res = crypto_ECIES_get_key(&pri,&x,&y); string_printf("p",&pri); string_printf("x",&x); string_printf("y",&y); printf("res :%d\n",res); FILE *fd; fd = fopen("./x","w"); fwrite(x.buf,1,x.len,fd); fd = fopen("./y","w"); fwrite(y.buf,1,y.len,fd); fd = fopen("./p","w"); fwrite(pri.buf,1,pri.len,fd); res = crypto_ECIES_encrypto_message(&mess,&x,&y,&xx,&yy,&en_mess,&tag); // string_malloc(&xx,32); // string_malloc(&yy,32); // string_malloc(&tag,20); // string_malloc(&en_mess,20); //res = ECIES_encrypto_message(mess.buf,mess.len,x.buf,x.len,y.buf,y.len,xx.buf,&xx.len,yy.buf,&yy.len,en_mess.buf,&en_mess.len,tag.buf,&tag.len); string_printf("tag",&tag); string_printf("xx",&xx); string_printf("yy",&yy); string_printf("en_mess",&en_mess); printf("res :%d\n",res); fd = fopen("encrypted_mess","w"); fwrite(en_mess.buf,1,en_mess.len,fd); fd = fopen("xx","w"); fwrite(xx.buf,1,xx.len,fd); fd = fopen("yy","w"); fwrite(yy.buf,1,yy.len,fd); fd = fopen("tag","w"); fwrite(tag.buf,1,tag.len,fd); res = crypto_ECIES_decrypto_message(&en_mess,&xx,&yy,&tag,&pri,&m); //string_malloc(&m,11); //string_printf("m",&m); //res = ECIES_decrypto_message(en_mess.buf,en_mess.len,xx.buf,xx.len,yy.buf,yy.len,tag.buf,tag.len,pri.buf,pri.len,m.buf,&m.len); string_printf("m",&m); printf("%s\n",m.buf); printf("res :%d\n",res); }
int main(void) { check_offloading(); double A[N], B[N], C[N], D[N], E[N]; int fail = 0; INIT(); // ************************** // Series 1: no dist_schedule // ************************** // // Test: #iterations == #teams // ZERO(A); for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target teams distribute num_teams(512) for (int i = 0 ; i < 512 ; i++) { A[i] += C[i]; // += 1 per position } } for (int i = 0 ; i < 512 ; i++) if (A[i] != TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) TRIALS, A[i]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); // // Test: #iterations > #teams // ZERO(A); for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target teams distribute num_teams(256) for (int i = 0 ; i < 500 ; i++) { A[i] += C[i]; // += 1 per position } } for (int i = 0 ; i < 500 ; i++) if (A[i] != TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) TRIALS, A[i]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); // // Test: #iterations < #teams // ZERO(A); for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target teams distribute num_teams(256) for (int i = 0 ; i < 123 ; i++) { A[i] += C[i]; // += 1 per position } } for (int i = 0 ; i < 123 ; i++) if (A[i] != TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) TRIALS, A[i]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); // **************************** // Series 2: with dist_schedule // **************************** // // Test: #iterations == #teams, dist_schedule(1) // ZERO(A); for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target teams distribute dist_schedule(static,1) num_teams(512) for (int i = 0 ; i < 512 ; i++) { A[i] += C[i]; // += 1 per position } } for (int i = 0 ; i < 512 ; i++) if (A[i] != TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) TRIALS, A[i]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); // // Test: #iterations == #teams, dist_schedule(#iterations) // ZERO(A); for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target teams distribute dist_schedule(static,512) num_teams(512) for (int i = 0 ; i < 512 ; i++) { A[i] += C[i]; // += 1 per position } } for (int i = 0 ; i < 512 ; i++) if (A[i] != TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) TRIALS, A[i]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); // // Test: #iterations == #teams, dist_schedule(#iterations/10), variable chunk size // ZERO(A); int ten = 10; int chunkSize = 512/ten; for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target teams distribute dist_schedule(static,chunkSize) num_teams(512) for (int i = 0 ; i < 512 ; i++) { A[i] += C[i]; // += 1 per position } } for (int i = 0 ; i < 512 ; i++) if (A[i] != TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) TRIALS, A[i]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); // // Test: #iterations > #teams, dist_schedule(1) // ZERO(A); for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target teams distribute dist_schedule(static,1) num_teams(256) for (int i = 0 ; i < 500 ; i++) { A[i] += C[i]; // += 1 per position } } for (int i = 0 ; i < 500 ; i++) if (A[i] != TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) TRIALS, A[i]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); // // Test: #iterations > #teams, dist_schedule(#iterations) // ZERO(A); for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target teams distribute dist_schedule(static,500) num_teams(256) for (int i = 0 ; i < 500 ; i++) { A[i] += C[i]; // += 1 per position } } for (int i = 0 ; i < 500 ; i++) if (A[i] != TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) TRIALS, A[i]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); // // Test: #iterations > #teams, dist_schedule(#iterations/10), variable chunk size // ZERO(A); ten = 10; chunkSize = 500/ten; for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target teams distribute dist_schedule(static,chunkSize) num_teams(256) for (int i = 0 ; i < 500 ; i++) { A[i] += C[i]; // += 1 per position } } for (int i = 0 ; i < 500 ; i++) if (A[i] != TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) TRIALS, A[i]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); // // Test: #iterations < #teams, dist_schedule(1) // ZERO(A); for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target teams distribute dist_schedule(static,1) num_teams(256) for (int i = 0 ; i < 123 ; i++) { A[i] += C[i]; // += 1 per position } } for (int i = 0 ; i < 123 ; i++) if (A[i] != TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) TRIALS, A[i]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); // // Test: #iterations < #teams, dist_schedule(#iterations) // ZERO(A); for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target teams distribute dist_schedule(static,123) num_teams(256) for (int i = 0 ; i < 123 ; i++) { A[i] += C[i]; // += 1 per position } } for (int i = 0 ; i < 123 ; i++) if (A[i] != TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) TRIALS, A[i]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); // // Test: #iterations < #teams, dist_schedule(#iterations) // ZERO(A); ten = 10; chunkSize = 123/ten; for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target teams distribute dist_schedule(static,chunkSize) num_teams(256) for (int i = 0 ; i < 123 ; i++) { A[i] += C[i]; // += 1 per position } } for (int i = 0 ; i < 123 ; i++) if (A[i] != TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) TRIALS, A[i]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); // **************************** // Series 3: with ds attributes // **************************** // DS currently failing in the compiler with asserts (bug #T158) #if 0 // // Test: private // ZERO(A); ZERO(B); double p = 2.0, q = 4.0; for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target teams distribute private(p,q) num_teams(256) for(int i = 0 ; i < N ; i++) { p = 2; q = 3; A[i] += p; B[i] += q; } } for(int i = 0 ; i < N ; i++) { if (A[i] != TRIALS*2) { printf("Error at A[%d], h = %lf, d = %lf\n", i, (double) TRIALS*2, A[i]); fail = 1; } if (B[i] != TRIALS*3) { printf("Error at B[%d], h = %lf, d = %lf\n", i, (double) TRIALS*3, B[i]); fail = 1; } } if(fail) printf("Failed\n"); else printf("Succeeded\n"); // // Test: firstprivate // ZERO(A); ZERO(B); p = 2.0, q = 4.0; for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target teams distribute firstprivate(p,q) num_teams(64) for(int i = 0 ; i < 128 ; i++) { // 2 iterations for each team p += 3.0; // p and q are firstprivate to the team, and as such incremented twice (2 iterations per team) q += 7.0; A[i] += p; B[i] += q; } } for(int i = 0 ; i < 128 ; i++) { if (i % 2 == 0) { if (A[i] != (2.0+3.0)*TRIALS) { printf("Error at A[%d], h = %lf, d = %lf\n", i, (double) (2.0+3.0)*TRIALS, A[i]); fail = 1; } if (B[i] != (4.0+7.0)*TRIALS) { printf("Error at B[%d], h = %lf, d = %lf\n", i, (double) (4.0+7.0)*TRIALS, B[i]); fail = 1; } } else { if (A[i] != (2.0+3.0*2)*TRIALS) { printf("Error at A[%d], h = %lf, d = %lf\n", i, (double) (2.0+3.0*2)*TRIALS, A[i]); fail = 1; } if (B[i] != (4.0+7.0*2)*TRIALS) { printf("Error at B[%d], h = %lf, d = %lf\n", i, (double) (4.0+7.0*2)*TRIALS, B[i]); fail = 1; } } } if(fail) printf("Failed\n"); else printf("Succeeded\n"); //#endif // // Test: lastprivate // int lastpriv = -1; // map(tofrom:lastpriv) #pragma omp target teams distribute lastprivate(lastpriv) num_teams(10) for(int i = 0 ; i < omp_get_num_teams() ; i++) lastpriv = omp_get_team_num(); if(lastpriv != 9) { printf("lastpriv value is %d and should have been %d\n", lastpriv, 9); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); // *************************** // Series 4: with parallel for // *************************** // // Test: simple blocking loop // ZERO(A); ZERO(B); int nte = 32; int tl = 64; int blockSize = tl; for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target teams distribute num_teams(nte) thread_limit(tl) for(int j = 0 ; j < 256 ; j += blockSize) { #pragma omp parallel for for(int i = j ; i < j+blockSize; i++) { A[i] += B[i] + C[i]; } } } for(int i = 0 ; i < 256 ; i++) { if (A[i] != TRIALS) { printf("Error at A[%d], h = %lf, d = %lf\n", i, (double) (2.0+3.0)*TRIALS, A[i]); fail = 1; } } if(fail) printf("Failed\n"); else printf("Succeeded\n"); #endif // // Test: blocking loop where upper bound is not a multiple of tl*nte // ZERO(A); ZERO(B); int nte = 32; int tl = 64; int blockSize = tl; for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target teams distribute num_teams(nte) thread_limit(tl) for(int j = 0 ; j < 510 ; j += blockSize) { int ub = (j+blockSize < 510) ? (j+blockSize) : 512; #pragma omp parallel for for(int i = j ; i < ub; i++) { A[i] += B[i] + C[i]; } } } for(int i = 0 ; i < 256 ; i++) { if (A[i] != TRIALS) { printf("Error at A[%d], h = %lf, d = %lf\n", i, (double) (2.0+3.0)*TRIALS, A[i]); fail = 1; } } if(fail) printf("Failed\n"); else printf("Succeeded\n"); // ************************** // Series 5: collapse // ************************** // // Test: 2 loops // double * S = malloc(N*N*sizeof(double)); double * T = malloc(N*N*sizeof(double)); double * U = malloc(N*N*sizeof(double)); for (int i = 0 ; i < N ; i++) for (int j = 0 ; j < N ; j++) { S[i*N+j] = 0.0; T[i*N+j] = 1.0; U[i*N+j] = 2.0; } for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target teams distribute collapse(2) map(tofrom:S[:N*N]), map(to:T[:N*N],U[:N*N]) num_teams(512) for (int i = 0 ; i < N ; i++) for (int j = 0 ; j < N ; j++) S[i*N+j] += T[i*N+j] + U[i*N+j]; // += 3 at each t } for (int i = 0 ; i < N ; i++) for (int j = 0 ; j < N ; j++) if (S[i*N+j] != TRIALS*3.0) { printf("Error at (%d,%d), h = %lf, d = %lf\n", i, j, (double) TRIALS*3.0, S[i*N+j]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); // // Test: 3 loops // int M = N/8; double * V = malloc(M*M*M*sizeof(double)); double * Z = malloc(M*M*M*sizeof(double)); for (int i = 0 ; i < M ; i++) for (int j = 0 ; j < M ; j++) for (int k = 0 ; k < M ; k++) { V[i*M*M+j*M+k] = 2.0; Z[i*M*M+j*M+k] = 3.0; } for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target teams distribute collapse(3) map(tofrom:V[:M*M*M]), map(to:Z[:M*M*M]) num_teams(512) for (int i = 0 ; i < M ; i++) for (int j = 0 ; j < M ; j++) for (int k = 0 ; k < M ; k++) V[i*M*M+j*M+k] += Z[i*M*M+j*M+k]; // += 3 at each t } for (int i = 0 ; i < M ; i++) for (int j = 0 ; j < M ; j++) for (int k = 0 ; k < M ; k++) if (V[i*M*M+j*M+k] != 2.0+TRIALS*3.0) { printf("Error at (%d,%d), h = %lf, d = %lf\n", i, j, (double) TRIALS*3.0, V[i*M*M+j*M+k]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); return 0; }
int main() { HANDLE ht_selfsuspend, ht_exit, ht_window; DWORD tid, res; INIT(); print("creating window\n"); ht_window = CreateThread(NULL, 0, window_func, NULL, 0, &tid); if (ht_window == NULL) { print("Error creating window thread\n"); return -1; } while (!thread_ready) Sleep(20); print("detach_callback start\n"); ht_selfsuspend = CreateThread(NULL, 0, &ThreadProcSelfSuspend, NULL, 0, &tid); if (ht_selfsuspend == NULL) { print("Error creating self-suspend thread\n"); return -1; } /* wait for thread to suspend itself */ res = 0; while (res == 0) { res = SuspendThread(ht_selfsuspend); if (res == 0) { /* Thread might not yet have gotten around to suspending itself */ ResumeThread(ht_selfsuspend); /* short sleep to wait */ Sleep(20); } } do_test(2); print("finished first callback test\n"); action_exit = TRUE; ht_exit = CreateThread(NULL, 0, &ThreadProcDoTest, (void *)2, 0, &tid); if (ht_exit == NULL) { print("Error creating exit thread\n"); return -1; } WaitForSingleObject(ht_exit, INFINITE); CloseHandle(ht_exit); print("finished exit test\n"); action_exit = FALSE; action_detach = TRUE; do_test(2); print("finished detach test\n"); action_detach = FALSE; /* we are now detached */ /* just a little extra work to make sure everything looks ok natively */ do_test(1); print("finished second callback test\n"); /* verify selfsuspended thread detached okay */ ResumeThread(ht_selfsuspend); ResumeThread(ht_selfsuspend); WaitForSingleObject(ht_selfsuspend, INFINITE); CloseHandle(ht_selfsuspend); print("detach_callback done\n"); return 0; }
/*! Main @param argc number of arguments @param argv arguments @return fuse_main()s return value */ int main(int argc, char **argv) { /* return value of fuse_main() */ int ret; /* for signal handling */ struct sigaction sig; /* argument handling */ struct fuse_args args = FUSE_ARGS_INIT(argc, argv); /* file name for database */ char *db_file; /*------------------------* * install signal handler * *------------------------*/ /* set handling function */ sig.sa_handler = sig_handler; /* set (no) flags */ sig.sa_flags = 0; /* don't ignore any signal */ sigemptyset(&sig.sa_mask); /* install signal handler for USR1 and USR2 */ sigaction(SIGUSR1, &sig, NULL); sigaction(SIGUSR2, &sig, NULL); /*------------------* * handle arguments * *------------------*/ if (fuse_opt_parse(&args, &discofs_options, discofs_opts, discofs_opt_proc) == -1) return EXIT_FAILURE; /* after option parsing, remote mount point must be set */ if (!REMOTE_ROOT) { fprintf(stderr, "no remote filesystem given\n"); return EXIT_FAILURE; } /* a mount point for discofs must also be set */ if (!discofs_options.discofs_mp) { fprintf(stderr, "no mount point given\n"); return EXIT_FAILURE; } /* add "use_ino" to display inodes in stat(1)*/ fuse_opt_add_arg(&args, "-ouse_ino"); /*---------------* * set UID / GID * *---------------*/ /* set GID first since permissions might not be sufficient if UID was set beforehand */ if (discofs_options.gid) { VERBOSE("setting gid to %d\n", discofs_options.gid); if (setgid(discofs_options.gid)) { perror("setting gid"); return EXIT_FAILURE; } } if (discofs_options.uid) { VERBOSE("setting uid to %d\n", discofs_options.uid); if (setuid(discofs_options.uid)) { perror("setting uid"); return EXIT_FAILURE; } } /*--------------------* * initialize logging * *--------------------*/ /* if -d is specified, override logging settings */ if (discofs_options.debug) log_init(LOG_DEBUG, NULL); else log_init(discofs_options.loglevel, discofs_options.logfile); /*=========================* * INITIALIZE CACHE AND DB * *=========================*/ /* compute data root if not passed as option */ if (!discofs_options.data_root) discofs_options.data_root = paths_data_root(REMOTE_ROOT); if (!is_dir(discofs_options.data_root)) { if (mkdir_rec(discofs_options.data_root)) FATAL("failed to create data directory %s\n", discofs_options.data_root); } /*----------------------* * initialize cache dir * *----------------------*/ /* set cache dir */ CACHE_ROOT = join_path(discofs_options.data_root, "cache"); /* store length of cache root (to save a few hundred strlen() calls) */ CACHE_ROOT_LEN = strlen(CACHE_ROOT); /* delete cache if "clear" specified */ if (discofs_options.clear) { VERBOSE("deleting cache\n"); rmdir_rec(CACHE_ROOT); } /* create cache root if needed */ if (!is_dir(CACHE_ROOT)) { if (mkdir(CACHE_ROOT, S_IRWXU) != 0) FATAL("failed to create cache directory %s\n", CACHE_ROOT); } /*---------------------* * initialize database * *---------------------*/ /* set db filename */ db_file = join_path(discofs_options.data_root, "db.sqlite"); /* create database file if it doesn't exist */ int fd = open(db_file, (O_RDONLY | O_CREAT), (S_IRUSR | S_IWUSR)); if (fd == -1) { perror(db_file); FATAL("couldn't open or create database file\n"); } close(fd); /* initialize tables etc */ db_init(db_file, discofs_options.clear); /* try to load filesystem features from DB */ if (db_cfg_get_int(CFG_FS_FEATURES, &discofs_options.fs_features)) { /* if loading failed, try to determine them */ if (is_mounted(REMOTE_ROOT) && is_reachable(discofs_options.host)) { if (test_fs_features(&discofs_options.fs_features)) { ERROR("failed to test remote fs features\n"); discofs_options.fs_features = 0; } /* test succeeded, store value for next time */ else db_cfg_set_int(CFG_FS_FEATURES, discofs_options.fs_features); } /* nag and assume that no features available (but don't save that) */ else { ERROR("could not determine remote fs features"); discofs_options.fs_features = 0; } } /*------------------* * initialize stuff * *------------------*/ #define INIT(name) \ if (name ## _init()) \ FATAL("error initializing " #name) INIT(lock); INIT(sync); INIT(job); #undef INIT /*----------------------* * print options to log * *----------------------*/ log_options(LOG_VERBOSE, discofs_options); /*-----------------* * run fuse_main() * *-----------------*/ ret = fuse_main(args.argc, args.argv, &discofs_oper, NULL); /*------* * exit * *------*/ lock_destroy(); sync_destroy(); job_destroy(); /* free arguments */ fuse_opt_free_args(&args); /* close database connection */ db_destroy(); /* end logging */ INFO("exiting\n"); log_destroy(); /* return fuse_main()s return value */ return ret; }
/********************************************************************* * * SEGGER_RTT_TerminalOut * * Function description * Writes a string to the given terminal * without changing the terminal for channel 0. * * Parameters * TerminalId Index of the terminal. * s String to be printed on the terminal. * * Return value * >= 0 - Number of bytes written. * < 0 - Error. * */ int SEGGER_RTT_TerminalOut (char TerminalId, const char* s) { int Status; unsigned FragLen; unsigned Avail; SEGGER_RTT_BUFFER_UP* pRing; // INIT(); // // Validate terminal ID. // if (TerminalId < (char)sizeof(_aTerminalId)) { // We only support a certain number of channels // // Get "to-host" ring buffer. // pRing = &_SEGGER_RTT.aUp[0]; // // Need to be able to change terminal, write data, change back. // Compute the fixed and variable sizes. // FragLen = strlen(s); // // How we output depends upon the mode... // SEGGER_RTT_LOCK(); Avail = _GetAvailWriteSpace(pRing); switch (pRing->Flags & SEGGER_RTT_MODE_MASK) { case SEGGER_RTT_MODE_NO_BLOCK_SKIP: // // If we are in skip mode and there is no space for the whole // of this output, don't bother switching terminals at all. // if (Avail < (FragLen + 4u)) { Status = 0; } else { _PostTerminalSwitch(pRing, TerminalId); Status = (int)_WriteBlocking(pRing, s, FragLen); _PostTerminalSwitch(pRing, _ActiveTerminal); } break; case SEGGER_RTT_MODE_NO_BLOCK_TRIM: // // If we are in trim mode and there is not enough space for everything, // trim the output but always include the terminal switch. If no room // for terminal switch, skip that totally. // if (Avail < 4u) { Status = -1; } else { _PostTerminalSwitch(pRing, TerminalId); Status = (int)_WriteBlocking(pRing, s, (FragLen < (Avail - 4u)) ? FragLen : (Avail - 4u)); _PostTerminalSwitch(pRing, _ActiveTerminal); } break; case SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL: // // If we are in blocking mode, output everything. // _PostTerminalSwitch(pRing, TerminalId); Status = (int)_WriteBlocking(pRing, s, FragLen); _PostTerminalSwitch(pRing, _ActiveTerminal); break; default: Status = -1; break; } // // Finish up. // SEGGER_RTT_UNLOCK(); } else { Status = -1; } return Status; }
int main(void) { INIT(); long int i; int l = 10, r = 5; Object list = List_Create(); Object list2 = List_Create(); Object temp_list; Object front, back; // list2 = (0 1 2 3 4 5 6 ... 148 149) for(i = 0; i < l + r; i++) { List_PushBack(list2, INT_AS_OBJECT(i)); }; // list = (99998 99996 ... 8 6 4 2 0 1 3 5 7 9 ... 99997 99999 ) for(i = 0; i < NODES; i++) { if(i & 1) { List_PushBack(list, INT_AS_OBJECT(i)); } else { List_PushFront(list, INT_AS_OBJECT(i)); }; }; for(front = List_First(list), i = 0; i < NODES / 2; ListIterator_Next(front), i++) { List_AddAfterPosition(list2, INT_AS_OBJECT(l - 1 + i), ListIterator_ThisData(front)); }; for(back = List_Last(list), i = 0; i < NODES / 2; ListIterator_Prev(back), i++) { List_AddAfterPosition(list2, INT_AS_OBJECT(l + NODES / 2 - 1), ListIterator_ThisData(back)); }; front = List_IteratorFromPosition(list2, INT_AS_OBJECT(l)); TEST("Checking for correctness of IteratorFromPosition after AddList{Before|After}", OBJECT_AS_INT(ListIterator_ThisData(front)) == (NODES & (~1)) - ((!(NODES & 1)) * 2)); back = List_IteratorFromPosition(list2, INT_AS_OBJECT(l + NODES - 1)); TEST("Checking for correctness of IteratorFromPosition after AddList{Before|After}", OBJECT_AS_INT(ListIterator_ThisData(back)) == (NODES & (~1)) - 1 + ((NODES & 1) * 2)); temp_list = List_SublistBetweenIterators(list2, front, back); front = List_First(temp_list); back = List_Last(temp_list); for(i = 1; i < NODES / 2; i++) { if(OBJECT_AS_INT(ListIterator_ThisData(front)) != OBJECT_AS_INT(ListIterator_ThisData(back)) + 1) { DEBUG("Got %li and %li.\n", OBJECT_AS_INT(ListIterator_ThisData(front)), OBJECT_AS_INT(ListIterator_ThisData(back))); return 1; }; ListIterator_Next(front); ListIterator_Prev(back); }; Object_Release(list); Object_Release(list2); Object_Release(temp_list); return 0; };
int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { INIT(FSYNC); req->file = file; POST; }
int main(void){ #if CHECK check_offloading(); #endif /* * Default device */ printf("Is%s initial device\n", omp_is_initial_device() ? "" : " not"); printf("Initial device: %d\n", omp_get_initial_device()); omp_set_default_device(1); printf("Default device before task: %d\n", omp_get_default_device()); #pragma omp task { printf("Default device inside task: %d\n", omp_get_default_device()); omp_set_default_device(2); printf("Default device inside task after resetting: %d\n", omp_get_default_device()); } #pragma omp taskwait printf("Default device outside task: %d\n", omp_get_default_device()); // default device can set to whatever, if target fails, it goes to the host const int default_device = 0; omp_set_default_device(default_device); // default device for omp target call MUST be >= 0 and <omp_get_num_devices() or // the initial device. So when there are no devices, it must be the initial device int default_device_omp_target_call = default_device; if (omp_get_num_devices() == 0) { default_device_omp_target_call = omp_get_initial_device(); } #if DEBUG printf("test on machine with %d devices\n", omp_get_num_devices()); #endif /* * Target alloc & target memcpy */ double A[N], B[N], C[N], D[N], E[N]; double *pA, *pB, *pC, *pD, *pE; // map ptrs pA = &A[0]; pB = &B[0]; pC = &C[0]; pD = &D[0]; pE = &E[0]; INIT(); pA = pA - 10; pC = pC - 20; pD = pD - 30; void *device_A = omp_target_alloc(N*sizeof(double), default_device_omp_target_call); void *device_C = omp_target_alloc(N*sizeof(double), default_device_omp_target_call); void *device_D = omp_target_alloc(N*sizeof(double), default_device_omp_target_call); double *dpA = (double *) device_A - 100; double *dpC = (double *) device_C - 200; double *dpD = (double *) device_D - 300; printf("omp_target_alloc %s\n", device_A && device_C && device_D ? "succeeded" : "failed"); omp_target_memcpy(dpC, pC, N*sizeof(double), 200*sizeof(double), 20*sizeof(double), default_device_omp_target_call, omp_get_initial_device()); omp_target_memcpy(dpD, pD, N*sizeof(double), 300*sizeof(double), 30*sizeof(double), default_device_omp_target_call, omp_get_initial_device()); #pragma omp target is_device_ptr(dpA, dpC, dpD) device(default_device) { #pragma omp parallel for schedule(static,1) for (int i = 0; i < 992; i++) dpA[i+100] = dpC[i+200] + dpD[i+300] + 1; } omp_target_memcpy(pA, dpA, N*sizeof(double), 10*sizeof(double), 100*sizeof(double), omp_get_initial_device(), default_device_omp_target_call); int fail = 0; VERIFY(0, N, A[i], (double)(i+2)); if (fail) { printf ("Test omp_target_memcpy: Failed\n"); } else { printf ("Test omp_target_memcpy: Succeeded\n"); } /* * target_is_present and target_associate/disassociate_ptr */ INIT(); if (offloading_disabled()) { // If offloading is disabled just recreate the messages so that this can // also be tested with no device. printf("C is not present, associating it...\n"); printf("omp_target_associate_ptr C %s\n", 1 ? "succeeded" : "failed"); } else if (!omp_target_is_present(C, default_device_omp_target_call)) { printf("C is not present, associating it...\n"); int rc = omp_target_associate_ptr(C, dpC, N*sizeof(double), 200*sizeof(double), default_device_omp_target_call); printf("omp_target_associate_ptr C %s\n", !rc ? "succeeded" : "failed"); } if (offloading_disabled()) { // If offloading is disabled just recreate the messages so that this can // also be tested with no device. printf("D is not present, associating it...\n"); printf("omp_target_associate_ptr D %s\n", 1 ? "succeeded" : "failed"); } else if (!omp_target_is_present(D, default_device_omp_target_call)) { printf("D is not present, associating it...\n"); int rc = omp_target_associate_ptr(D, dpD, N*sizeof(double), 300*sizeof(double), default_device_omp_target_call); printf("omp_target_associate_ptr D %s\n", !rc ? "succeeded" : "failed"); } #pragma omp target data map(from: C, D) device(default_device) { printf("Inside target data: A is%s present\n", (omp_target_is_present(A, default_device_omp_target_call) && !offloading_disabled()) ? "" : " not"); printf("Inside target data: C is%s present\n", omp_target_is_present(C, default_device_omp_target_call) ? "" : " not"); printf("Inside target data: D is%s present\n", omp_target_is_present(D, default_device_omp_target_call) ? "" : " not"); // C and D are mapped "from", so there is no copy from host to device. // If the association was successful, their corresponding device arrays // are already populated from previous omp_target_memcpy with the correct // values and the following target for-loop must yield the correct results. #pragma omp target map(from: A) device(default_device) { #pragma omp parallel for schedule(static,1) for (int i = 0; i < 992; i++) A[i] = C[i] + D[i] + 1; } } if (offloading_disabled()) { printf("C is present, disassociating it...\n"); printf("omp_target_disassociate_ptr C %s\n", 1 ? "succeeded" : "failed"); } else if (omp_target_is_present(C, default_device_omp_target_call)) { printf("C is present, disassociating it...\n"); int rc = omp_target_disassociate_ptr(C, default_device_omp_target_call); printf("omp_target_disassociate_ptr C %s\n", !rc ? "succeeded" : "failed"); } if (offloading_disabled()) { printf("D is present, disassociating it...\n"); printf("omp_target_disassociate_ptr D %s\n", 1 ? "succeeded" : "failed"); } else if (omp_target_is_present(D, default_device_omp_target_call)) { printf("D is present, disassociating it...\n"); int rc = omp_target_disassociate_ptr(D, default_device_omp_target_call); printf("omp_target_disassociate_ptr D %s\n", !rc ? "succeeded" : "failed"); } fail = 0; VERIFY(0, N, A[i], (double)(i+2)); if (fail) { printf ("Test omp_target_associate_ptr: Failed\n"); } else { printf ("Test omp_target_associate_ptr: Succeeded\n"); } omp_target_free(device_A, default_device_omp_target_call); omp_target_free(device_C, default_device_omp_target_call); omp_target_free(device_D, default_device_omp_target_call); return 0; }
//! //! Encodes instance metadata (contained in ncInstance struct) in XML //! and writes it to file instance->xmlFilePath (/path/to/instance/instance.xml) //! That file gets processed through tools/libvirt.xsl (/etc/eucalyptus/libvirt.xsl) //! to produce /path/to/instance/libvirt.xml file that is passed to libvirt create. //! //! @param[in] instance a pointer to the instance to generate XML from //! //! @return EUCA_OK if the operation is successful. Known error code returned include EUCA_ERROR. //! //! @see write_xml_file() //! int gen_instance_xml(const ncInstance * instance) { int ret = EUCA_ERROR; int i = 0; int j = 0; char *path = NULL; char cores_s[10] = ""; char memory_s[10] = ""; char bitness[4] = ""; char root_uuid[64] = ""; char devstr[SMALL_CHAR_BUFFER_SIZE] = ""; xmlNodePtr disk = NULL; xmlDocPtr doc = NULL; xmlNodePtr instanceNode = NULL; xmlNodePtr hypervisor = NULL; xmlNodePtr backing = NULL; xmlNodePtr root = NULL; xmlNodePtr key = NULL; xmlNodePtr os = NULL; xmlNodePtr disks = NULL; xmlNodePtr rootNode = NULL; xmlNodePtr nics = NULL; xmlNodePtr nic = NULL; const virtualBootRecord *vbr = NULL; INIT(); pthread_mutex_lock(&xml_mutex); { doc = xmlNewDoc(BAD_CAST "1.0"); instanceNode = xmlNewNode(NULL, BAD_CAST "instance"); xmlDocSetRootElement(doc, instanceNode); // hypervisor-related specs hypervisor = xmlNewChild(instanceNode, NULL, BAD_CAST "hypervisor", NULL); _ATTRIBUTE(hypervisor, "type", instance->hypervisorType); _ATTRIBUTE(hypervisor, "capability", hypervsorCapabilityTypeNames[instance->hypervisorCapability]); snprintf(bitness, 4, "%d", instance->hypervisorBitness); _ATTRIBUTE(hypervisor, "bitness", bitness); //! backing specification (@todo maybe expand this with device maps or whatnot?) backing = xmlNewChild(instanceNode, NULL, BAD_CAST "backing", NULL); root = xmlNewChild(backing, NULL, BAD_CAST "root", NULL); assert(instance->params.root); _ATTRIBUTE(root, "type", ncResourceTypeName[instance->params.root->type]); _ELEMENT(instanceNode, "name", instance->instanceId); _ELEMENT(instanceNode, "uuid", instance->uuid); _ELEMENT(instanceNode, "reservation", instance->reservationId); _ELEMENT(instanceNode, "user", instance->userId); _ELEMENT(instanceNode, "dnsName", instance->dnsName); _ELEMENT(instanceNode, "privateDnsName", instance->privateDnsName); _ELEMENT(instanceNode, "instancePath", instance->instancePath); if (instance->params.kernel) { path = instance->params.kernel->backingPath; if (path_check(path, "kernel")) goto free; // sanity check _ELEMENT(instanceNode, "kernel", path); } if (instance->params.ramdisk) { path = instance->params.ramdisk->backingPath; if (path_check(path, "ramdisk")) goto free; // sanity check _ELEMENT(instanceNode, "ramdisk", path); } _ELEMENT(instanceNode, "consoleLogPath", instance->consoleFilePath); _ELEMENT(instanceNode, "userData", instance->userData); _ELEMENT(instanceNode, "launchIndex", instance->launchIndex); snprintf(cores_s, sizeof(cores_s), "%d", instance->params.cores); _ELEMENT(instanceNode, "cores", cores_s); snprintf(memory_s, sizeof(memory_s), "%d", instance->params.mem * 1024); _ELEMENT(instanceNode, "memoryKB", memory_s); // SSH-key related key = _NODE(instanceNode, "key"); _ATTRIBUTE(key, "isKeyInjected", _BOOL(instance->do_inject_key)); _ATTRIBUTE(key, "sshKey", instance->keyName); // OS-related specs os = _NODE(instanceNode, "os"); _ATTRIBUTE(os, "platform", instance->platform); _ATTRIBUTE(os, "virtioRoot", _BOOL(config_use_virtio_root)); _ATTRIBUTE(os, "virtioDisk", _BOOL(config_use_virtio_disk)); _ATTRIBUTE(os, "virtioNetwork", _BOOL(config_use_virtio_net)); // disks specification disks = _NODE(instanceNode, "disks"); // the first disk should be the root disk (at least for Windows) for (j = 1; j >= 0; j--) { for (i = 0; ((i < EUCA_MAX_VBRS) && (i < instance->params.virtualBootRecordLen)); i++) { vbr = &(instance->params.virtualBootRecord[i]); // skip empty entries, if any if (vbr == NULL) continue; // do EMI on the first iteration of the outer loop if (j && vbr->type != NC_RESOURCE_IMAGE) continue; // ignore EMI on the second iteration of the outer loop if (!j && vbr->type == NC_RESOURCE_IMAGE) continue; // skip anything without a device on the guest, e.g., kernel and ramdisk if (!strcmp("none", vbr->guestDeviceName)) continue; // for Linux instances on Xen, partitions can be used directly, so disks can be skipped unless booting from EBS if (strstr(instance->platform, "linux") && strstr(instance->hypervisorType, "xen")) { if ((vbr->partitionNumber == 0) && (vbr->type == NC_RESOURCE_IMAGE)) { continue; } } else { // on all other os + hypervisor combinations, disks are used, so partitions must be skipped if (vbr->partitionNumber > 0) { continue; } } disk = _ELEMENT(disks, "diskPath", vbr->backingPath); _ATTRIBUTE(disk, "targetDeviceType", libvirtDevTypeNames[vbr->guestDeviceType]); _ATTRIBUTE(disk, "targetDeviceName", vbr->guestDeviceName); snprintf(devstr, SMALL_CHAR_BUFFER_SIZE, "%s", vbr->guestDeviceName); if (config_use_virtio_root) { devstr[0] = 'v'; _ATTRIBUTE(disk, "targetDeviceNameVirtio", devstr); _ATTRIBUTE(disk, "targetDeviceBusVirtio", "virtio"); } _ATTRIBUTE(disk, "targetDeviceBus", libvirtBusTypeNames[vbr->guestDeviceBus]); _ATTRIBUTE(disk, "sourceType", libvirtSourceTypeNames[vbr->backingType]); if (j) { rootNode = _ELEMENT(disks, "root", NULL); _ATTRIBUTE(rootNode, "device", devstr); if (get_blkid(vbr->backingPath, root_uuid, sizeof(root_uuid)) == 0) { assert(strlen(root_uuid)); _ATTRIBUTE(rootNode, "uuid", root_uuid); } } } if (strlen(instance->floppyFilePath)) { _ELEMENT(disks, "floppyPath", instance->floppyFilePath); } } if (instance->params.nicType != NIC_TYPE_NONE) { // NIC specification nics = _NODE(instanceNode, "nics"); nic = _NODE(nics, "nic"); _ATTRIBUTE(nic, "bridgeDeviceName", instance->params.guestNicDeviceName); _ATTRIBUTE(nic, "mac", instance->ncnet.privateMac); } ret = write_xml_file(doc, instance->instanceId, instance->xmlFilePath, "instance"); free: xmlFreeDoc(doc); } pthread_mutex_unlock(&xml_mutex); return (ret); }
void calc_forces_neb(void) { real dl2=0.0, dr2=0.0, drl=0.0, d2=0.0, f2=0.0, f2max=0.0, drlmax=0.0,df=0.0; real tmp,tmp1,tmp2, cosphi, fphi, src[3], dest[3], *d=pos; real kr,kl; int k, i; int var_k=0; int myimage,maximage; real V_previous, V_actual, V_next; real deltaVmin,deltaVmax; real normdr,normdl,inormd; real Eref,Emax,Emin,delta_E; real ratio_plus,ratio_minus,abs_next,abs_previous ; real k_sum, k_diff,tmpl,tmpr; real tmp_neb_ks[NEB_MAXNREP] INIT(zero100); real felastfact=0.0; myimage = myrank; /* get info about the energies of the different images */ neb_image_energies[ myimage]=tot_pot_energy; MPI_Allreduce(neb_image_energies , neb_epot_im, NEB_MAXNREP, REAL, MPI_SUM, MPI_COMM_WORLD); Emax=-999999999999999; Emin=999999999999999; for(i=0;i<neb_nrep;i++) { if(neb_epot_im[i]>=Emax) { Emax=neb_epot_im[i]; maximage=i; } if(neb_epot_im[i]<=Emin) { Emin=neb_epot_im[i]; } } if(steps == neb_cineb_start) { if(neb_climbing_image > 0) { if(myrank==0) { if( neb_climbing_image == maximage) printf("Starting climbing image = %d (= max_Epot = %lf)\n",neb_climbing_image, Emax); else printf("Starting climbing image = %d \n WARNING: %d != %d with max_Epot = %lf)\n", \ neb_climbing_image,neb_climbing_image,maximage, Emax); } } else { neb_climbing_image = maximage; if(myrank==0) { printf("Starting climbing image, image set to %d (= max_Epot = %lf)\n",maximage, Emax); } } } /* determine variable spring constants (jcp113 p. 9901) */ tmp_neb_ks[myimage]=0; if(myrank != 0 && myrank != neb_nrep-1) { V_previous = neb_epot_im[myimage-1]; V_actual = neb_epot_im[myimage]; V_next = neb_epot_im[myimage+1]; if ( neb_kmax > 0 & neb_kmin >0 && steps > neb_vark_start) { var_k=1; k_sum = neb_kmax + neb_kmin; k_diff = neb_kmax - neb_kmin; delta_E = Emax - Emin; if (delta_E > 1.0e-12) { tmp_neb_ks[myimage] = 0.5 *(k_sum - k_diff * cos(3.141592653589793238*( neb_epot_im[myimage] - Emin )/delta_E )); } } else { tmp_neb_ks[myimage] = neb_k; } } MPI_Allreduce(tmp_neb_ks , neb_ks, NEB_MAXNREP, REAL, MPI_SUM, MPI_COMM_WORLD); /* exchange positions with neighbor replicas */ neb_sendrecv_pos(); /* determine tangent vector and the elastic spring force */ if(myrank != 0 && myrank != neb_nrep-1) { dl2=0.0;d2=0.0;dr2=0.0; kr = 0.5 * (neb_ks[myimage]+neb_ks[myimage+1]); kl = 0.5 * (neb_ks[myimage]+neb_ks[myimage-1]); /* preparation: calculate distance to left and right immage */ for (i=0; i<DIM*natoms; i+=DIM) { vektor dr,dl; real x; dl.x = pos [i ] - pos_l[i ]; dl.y = pos [i+1] - pos_l[i+1]; dl.z = pos [i+2] - pos_l[i+2]; dr.x = pos_r[i ] - pos [i ]; dr.y = pos_r[i+1] - pos [i+1]; dr.z = pos_r[i+2] - pos [i+2]; /* apply periodic boundary conditions */ if (1==pbc_dirs.x) { x = - round( SPROD(dl,tbox_x) ); dl.x += x * box_x.x; dl.y += x * box_x.y; dl.z += x * box_x.z; x = - round( SPROD(dr,tbox_x) ); dr.x += x * box_x.x; dr.y += x * box_x.y; dr.z += x * box_x.z; } if (1==pbc_dirs.y) { x = - round( SPROD(dl,tbox_y) ); dl.x += x * box_y.x; dl.y += x * box_y.y; dl.z += x * box_y.z; x = - round( SPROD(dr,tbox_y) ); dr.x += x * box_y.x; dr.y += x * box_y.y; dr.z += x * box_y.z; } if (1==pbc_dirs.z) { x = - round( SPROD(dl,tbox_z) ); dl.x += x * box_z.x; dl.y += x * box_z.y; dl.z += x * box_z.z; x = - round( SPROD(dr,tbox_z) ); dr.x += x * box_z.x; dr.y += x * box_z.y; dr.z += x * box_z.z; } dRleft[i ] = dl.x; dRleft[i+1] = dl.y; dRleft[i+2] = dl.z; dRright[i ] = dr.x; dRright[i+1] = dr.y; dRright[i+2] = dr.z; } /* computation of the tangent requires 2 steps: determination of the direction and then normalization */ /* here we use only the improved tangent method */ if ( ( V_next > V_actual ) && ( V_actual > V_previous ) ) { for (i=0; i<DIM*natoms; i+=DIM) { tau[i ] = dRright[i ]; tau[i+1] = dRright[i+1]; tau[i+2] = dRright[i+2]; d2 += dRright[i ]*dRright[i ]; d2 += dRright[i+1]*dRright[i+1]; d2 += dRright[i+2]*dRright[i+2]; } tmp=1.0/sqrt(d2); for (i=0; i<DIM*natoms; i+=DIM) { tau[i ] *= tmp; tau[i+1] *= tmp; tau[i+2] *= tmp; if (var_k==1) { felastfact += tau[i ] * ( -kr *dRright[i ] + kl * dRleft[i ]); felastfact += tau[i+1] * ( -kr *dRright[i+1] + kl * dRleft[i+1]); felastfact += tau[i+2] * ( -kr *dRright[i+2] + kl * dRleft[i+2]); } else { felastfact += tau[i ] * ( - dRright[i ] + dRleft[i ]); felastfact += tau[i+1] * ( - dRright[i+1] + dRleft[i+1]); felastfact += tau[i+2] * ( - dRright[i+2] + dRleft[i+2]); } } } else if ( ( V_next < V_actual ) && ( V_actual < V_previous ) ) { for (i=0; i<DIM*natoms; i+=DIM) { tau[i ] = dRleft[i ]; tau[i+1] = dRleft[i+1]; tau[i+2] = dRleft[i+2]; d2 += dRleft[i ]*dRleft[i ]; d2 += dRleft[i+1]*dRleft[i+1]; d2 += dRleft[i+2]*dRleft[i+2]; } tmp=1.0/sqrt(d2); for (i=0; i<DIM*natoms; i+=DIM) { tau[i ] *= tmp; tau[i+1] *= tmp; tau[i+2] *= tmp; if (var_k==1) { felastfact += tau[i ] * ( -kr *dRright[i ] + kl * dRleft[i ]); felastfact += tau[i+1] * ( -kr *dRright[i+1] + kl * dRleft[i+1]); felastfact += tau[i+2] * ( -kr *dRright[i+2] + kl * dRleft[i+2]); } else { felastfact += tau[i ] * ( - dRright[i ] + dRleft[i ]); felastfact += tau[i+1] * ( - dRright[i+1] + dRleft[i+1]); felastfact += tau[i+2] * ( - dRright[i+2] + dRleft[i+2]); } } } else { abs_next = FABS( V_next - V_actual ); abs_previous = FABS( V_previous - V_actual ); deltaVmax = MAX( abs_next, abs_previous ); deltaVmin = MIN( abs_next, abs_previous ); for (i=0; i<DIM*natoms; i+=DIM) { dr2 += dRright[i ]*dRright[i ]; dr2 += dRright[i+1]*dRright[i+1]; dr2 += dRright[i+2]*dRright[i+2]; dl2 += dRleft[i ]*dRleft[i ]; dl2 += dRleft[i+1]*dRleft[i+1]; dl2 += dRleft[i+2]*dRleft[i+2]; } tmpl=1.0/sqrt(dl2); tmpr=1.0/sqrt(dr2); for (i=0; i<DIM*natoms; i+=DIM) { vektor dl, dr; dr.x = dRright[i ]*tmpr; dr.y = dRright[i+1]*tmpr; dr.z = dRright[i+2]*tmpr; dl.x = dRleft[i ]*tmpl; dl.y = dRleft[i+1]*tmpl; dl.z = dRleft[i+2]*tmpl; if (V_next > V_previous ) { tau[i ] = dr.x * deltaVmax + dl.x * deltaVmin ; tau[i+1] = dr.y * deltaVmax + dl.y * deltaVmin; tau[i+2] = dr.z * deltaVmax + dl.z * deltaVmin; } else if ( V_next < V_previous ) { tau[i ] = dr.x * deltaVmin + dl.x * deltaVmax ; tau[i+1] = dr.y * deltaVmin + dl.y * deltaVmax; tau[i+2] = dr.z * deltaVmin + dl.z * deltaVmax; } else { tau[i ] = dr.x + dl.x; tau[i+1] = dr.y + dl.y; tau[i+2] = dr.z + dl.z; } d2 += tau[i ]*tau[i ]; d2 += tau[i+1]*tau[i+1]; d2 += tau[i+2]*tau[i+2]; } tmp=1.0/sqrt(d2); for (i=0; i<DIM*natoms; i+=DIM) { tau[i ] *= tmp; tau[i+1] *= tmp; tau[i+2] *= tmp; if (var_k==1) { felastfact += tau[i ] * ( -kr *dRright[i ] + kl * dRleft[i ]); felastfact += tau[i+1] * ( -kr *dRright[i+1] + kl * dRleft[i+1]); felastfact += tau[i+2] * ( -kr *dRright[i+2] + kl * dRleft[i+2]); } else { felastfact += tau[i ] * ( - dRright[i ] + dRleft[i ]); felastfact += tau[i+1] * ( - dRright[i+1] + dRleft[i+1]); felastfact += tau[i+2] * ( - dRright[i+2] + dRleft[i+2]); } } } /* finally construct the spring force */ for (i=0; i<DIM*natoms; i+=DIM) { if (var_k==1) { f[i ] = - tau[i ] *felastfact; f[i+1] = - tau[i+1] *felastfact; f[i+2] = - tau[i+2] *felastfact; } else { f[i ] = - neb_k * tau[i ] *felastfact; f[i+1] = - neb_k * tau[i+1] *felastfact; f[i+2] = - neb_k * tau[i+2] *felastfact; } } }// end if(myrank != 0 && mrank != neb_nrep-1) /* calculate the neb-force */ if(myrank != 0 && myrank != neb_nrep-1) { // first scalar product of -force and tangent vector tmp = 0.0; for (k=0; k<NCELLS; k++) { cell *p = CELLPTR(k); for (i=0; i<p->n; i++) { int n = NUMMER(p,i); tmp -= tau X(n) * KRAFT(p,i,X); tmp -= tau Y(n) * KRAFT(p,i,Y); tmp -= tau Z(n) * KRAFT(p,i,Z); } } // add tmp times the tangent vector // and the spring force for (k=0; k<NCELLS; k++) { cell *p = CELLPTR(k); for (i=0; i<p->n; i++) { int n = NUMMER(p,i); if(myimage == neb_climbing_image && (steps >= neb_cineb_start)) { KRAFT(p,i,X) += 2.0*tmp * tau X(n); KRAFT(p,i,Y) += 2.0*tmp * tau Y(n); KRAFT(p,i,Z) += 2.0*tmp * tau Z(n); } else { KRAFT(p,i,X) += tmp * tau X(n) + f X(n); KRAFT(p,i,Y) += tmp * tau Y(n) + f Y(n); KRAFT(p,i,Z) += tmp * tau Z(n) + f Z(n); } } } } // if(myrank != 0 && mrank != neb_nrep-1) }
int main(int argc, char *argv[]) { int offs, tid; unsigned long hThread; INIT(); print("testing hook pattern\n"); /* make it executable so that natively it works on NX */ protect_mem(datacode, sizeof(datacode), ALLOW_READ|ALLOW_WRITE|ALLOW_EXEC); protect_mem(datacode2, sizeof(datacode), ALLOW_READ|ALLOW_WRITE|ALLOW_EXEC); /* ensure our same-page test is relevant */ assert((((ptr_int_t)datacode) & ~(PAGE_SIZE -1)) == (((ptr_int_t)&datacode[sizeof(datacode)-1]) & ~(PAGE_SIZE -1))); /****************************************************************************/ /* datacode */ /* we need to set the 1st jmp so we'll match the pattern */ offs = ((ptr_int_t)&image_target + 5/*skip jmp*/) - DATACODE_POST_JMP; /* make direct jmp go to image_target */ *((int *)(&datacode[DATACODE_JMP_OPND_IDX])) = offs; __asm { pusha call offset datacode popa } print("testing non-pattern-match on same page\n"); offs = (ptr_int_t)&maliciousness - DATACODE_POST_2ND_JMP; /* make 2nd direct jmp go to maliciousness */ *((int *)(&datacode[DATACODE_2ND_JMP_OPND_IDX])) = offs; offs = DATACODE_POST_JMP; __asm { pusha call dword ptr offs popa } print("testing non-pattern-match in same region\n"); /* have 2nd instr make direct jmp to maliciousness */ offs = (ptr_int_t)&maliciousness - ((ptr_int_t)datacode + 2/*first instr*/ + 5/*this new jmp*/); datacode[2] = 0xe9; *((int *)(&datacode[3])) = offs; __asm { pusha call offset datacode popa } /* put the code back */ datacode[2] = 0x55; datacode[3] = 0x8b; datacode[4] = 0xec; datacode[5] = 0xe9; offs = ((ptr_int_t)&image_target + 5/*skip jmp*/) - DATACODE_POST_JMP; print("testing hook pattern again\n"); /* make direct jmp go to image_target */ *((int *)(&datacode[DATACODE_JMP_OPND_IDX])) = offs; __asm { pusha call offset datacode popa } print("testing non-pattern-match in same region by another thread\n"); /* now have another thread do the same thing */ hThread = _beginthreadex(NULL, 0, run_func, NULL, 0, &tid); WaitForSingleObject((HANDLE)hThread, INFINITE); print("testing different pattern match in same region\n"); /* now change to have 1st instr make direct jmp to maliciousness */ offs = (ptr_int_t)&maliciousness - ((ptr_int_t)datacode + 5); datacode[0] = 0xe9; *((int *)(&datacode[1])) = offs; __asm { pusha call offset datacode popa } /****************************************************************************/ /* datacode2 */ /* for -detect_mode we may have added datacode2 -- so force removal of it */ protect_mem(datacode2, sizeof(datacode), ALLOW_READ|ALLOW_WRITE); /* but we have to make sure it works on nx */ protect_mem(datacode2, sizeof(datacode), ALLOW_READ|ALLOW_WRITE|ALLOW_EXEC); print("testing pattern match that modifies itself to be a non-match\n"); /* would be allowed w/ last_area 4020 impl but shared->private check deletes * shared area and we end up getting lucky. */ /* MUST be just after change 1st instr of datacode to jmp to maliciousness */ offs = ((ptr_int_t)&image_target2 + 10/*skip length of pre-jmp instrs*/) - ((ptr_int_t)datacode2 + sizeof(datacode2) - 1); /* make direct jmp go to image_target */ *((int *)(&datacode2[sizeof(datacode2)-5])) = offs; /* make the mov modify the jmp to go to the jmp at the start of * datacode (I would put another jmp at end of datacode2 but we'll * just elide and allow!) which will go to maliciousness */ offs = (ptr_int_t)(&datacode) - ((ptr_int_t)datacode2 + sizeof(datacode2) - 1); /* immed comes last */ *((int *)(&datacode2[6])) = offs; /* target of mov comes before immed */ *((int *)(&datacode2[2])) = (ptr_int_t) &datacode2[11]; __asm { pusha call offset datacode2 popa } print("finished\n"); return 0; }
/* macros -- 64-bit */ #define NBITS (48 + _DOFF) #if _D0 == 0 #define INIT(w0) {w0, 0, 0, 0} #define INIT2(w0, w1) {w0, 0, 0, w1} #else /* _DLONG == 0 */ #define INIT(w0) {0, 0, 0, w0} #define INIT2(w0, w1) {w1, 0, 0, w0} #endif /* _DLONG == 0 */ /* static data */ extern /* const */ _Dconst _LDenorm = {INIT2(0, 1)}; extern /* const */ _Dconst _LEps = { INIT((_DBIAS - NBITS - 1) << _DOFF)}; extern /* const */ _Dconst _LInf = {INIT(_DMAX << _DOFF)}; extern /* const */ _Dconst _LNan = {INIT((_DMAX << _DOFF) | (1 << (_DOFF - 1)))}; extern /* const */ _Dconst _LSnan = {INIT2(_DMAX << _DOFF, 1)}; extern /* const */ _Dconst _LRteps = { INIT((_DBIAS - NBITS / 2) << _DOFF)}; #elif _DLONG == 1 /* macros -- 80-bit */ #define NBITS 64 #if _D0 == 0 #define INIT(w0, w1) {w0, w1, 0, 0, 0} #define INIT3(w0, w1, wn) {w0, w1, 0, 0, wn}
int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { INIT(STAT); PATH; POST; }
static void privatekey_signed_cert(pk_algorithm algorithm,string* pri,certificate* issued) { ecdsa_signature* signature; string encode,hashed; string r,s; INIT(encode); INIT(hashed); INIT(r); INIT(s); if( certificate_2_string_for_signed(issued,&encode)) { error(); goto end; } /* if(tobesigned_certificate_2_string(&issued->unsigned_certificate,&encode,issued->version_and_type)){ error(); goto end; } */ if(algorithm == ECDSA_NISTP224_WITH_SHA224) { if(crypto_HASH_224(&encode,&hashed)) { error(); goto end; } if(crypto_ECDSA_224_sign_message(pri,&hashed,&r,&s)) { error(); goto end; } } else if(algorithm == ECDSA_NISTP256_WITH_SHA256) { if(crypto_HASH_256(&encode,&hashed)) { error(); goto end; } if(crypto_ECDSA_256_sign_message(pri,&hashed,&r,&s)) { error(); goto end; } } else { error(); goto end; } signature = &issued->u.signature.u.ecdsa_signature; signature->s.len = s.len; signature->s.buf = (u8*)malloc(s.len); if(signature->s.buf == NULL) { error(); goto end; } memcpy(signature->s.buf,s.buf,s.len); signature->r.type = X_COORDINATE_ONLY; signature->r.x.len = r.len; signature->r.x.buf = (u8*)malloc(r.len); if(signature->r.x.buf == NULL) { error(); goto end; } memcpy(signature->r.x.buf,r.buf,r.len); end: string_free(&encode); string_free(&hashed); string_free(&r); string_free(&s); }
int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { INIT(CLOSE); req->file = file; POST; }
int main(void) { check_offloading(); double A[N], B[N], C[N], D[N], E[N]; int fail = 0; INIT(); // // Test: num_teams and omp_get_team_num() // ZERO(A); int num_teams = omp_is_initial_device() ? HOST_MAX_TEAMS : 512; for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target #pragma omp teams num_teams(num_teams) { A[omp_get_team_num()] += omp_get_team_num(); } } for (int i = 0 ; i < num_teams ; i++) if (A[i] != i*TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) i*TRIALS, A[i]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); // // Test: thread_limit and omp_get_thread_num() // ZERO(A); fail = 0; int num_threads = omp_is_initial_device() ? HOST_MAX_TEAMS : 256; for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target #pragma omp teams num_teams(1) thread_limit(num_threads) #pragma omp parallel { int tid = omp_get_thread_num(); A[tid] += (double) tid; } } for (int i = 0 ; i < num_threads ; i++) if (A[i] != i*TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) i*TRIALS, A[i]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); // // Test: if statement in teams region // ZERO(A); fail = 0; num_teams = omp_is_initial_device() ? HOST_MAX_TEAMS : 512; for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target #pragma omp teams num_teams(num_teams) { if (omp_get_team_num() % 2 == 0) { int teid = omp_get_team_num(); A[teid] += (double) 1; } else { int teid = omp_get_team_num(); A[teid] += (double) 2; } } } for (int i = 0 ; i < num_teams ; i++) { if (i % 2 == 0) { if (A[i] != TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) TRIALS, A[i]); fail = 1; } } else if (A[i] != 2*TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) 2*TRIALS, A[i]); fail = 1; } } if(fail) printf("Failed\n"); else printf("Succeeded\n"); /* // */ /* // Test: num_teams and thread_limit by simulating a distribute pragma */ /* // */ /* ZERO(A); */ /* fail = 0; */ /* for (int t = 0 ; t < TRIALS ; t++) { */ /* #pragma omp target */ /* #pragma omp teams num_teams(2) thread_limit(496) */ /* { */ /* if (omp_get_team_num() == 0) { */ /* #pragma omp parallel */ /* { */ /* A[omp_get_team_num()*496+omp_get_thread_num()] += omp_get_thread_num(); */ /* if(omp_get_thread_num() == 498) printf("teid = %d, tid = %d, accessing %d\n", omp_get_team_num(), omp_get_thread_num(), omp_get_team_num()*496+omp_get_thread_num()); */ /* } */ /* } else { */ /* #pragma omp parallel */ /* { */ /* if(omp_get_thread_num() == 0) */ /* printf("teid = %d, tid = %d: A= %lf\n", omp_get_team_num(), omp_get_thread_num(), A[omp_get_team_num()*496+omp_get_thread_num()]); */ /* A[omp_get_team_num()*496+omp_get_thread_num()] -= omp_get_thread_num(); */ /* if(omp_get_thread_num() == 0) */ /* printf("teid = %d, tid = %d: A= %lf\n", omp_get_team_num(), omp_get_thread_num(), A[omp_get_team_num()*496+omp_get_thread_num()]); */ /* } */ /* } */ /* } */ /* } */ /* for (int i = 0 ; i < 992 ; i++) { */ /* if (i < 496) { */ /* if (A[i] != i*TRIALS) { */ /* printf("Error at %d, h = %lf, d = %lf\n", i, (double) i*TRIALS, A[i]); */ /* fail = 1; */ /* } */ /* } else if(i >= 496) */ /* if (A[i] != -((i-496)*TRIALS)) { */ /* printf("Error at %d, h = %lf, d = %lf\n", i, (double) -((i-496)*TRIALS), A[i]); */ /* fail = 1; */ /* } */ /* } */ /* if(fail) printf("Failed\n"); */ /* else printf("Succeeded\n"); */ // // Test: private // ZERO(A); fail = 0; int a = 10; num_teams = omp_is_initial_device() ? HOST_MAX_TEAMS : 256; for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target #pragma omp teams num_teams(num_teams) private(a) { a = omp_get_team_num(); A[omp_get_team_num()] += a; } } for (int i = 0 ; i < num_teams ; i++) if (A[i] != i*TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) i*TRIALS, A[i]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); ZERO(A); fail = 0; a = 10; num_teams = omp_is_initial_device() ? HOST_MAX_TEAMS : 256; for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target firstprivate(a) #pragma omp teams num_teams(num_teams) firstprivate(a) { a += omp_get_team_num(); A[omp_get_team_num()] += a; } } for (int i = 0 ; i < num_teams ; i++) if (A[i] != 10+i*TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) (10+i*TRIALS), A[i]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); ZERO(A); fail = 0; a = 10; num_teams = omp_is_initial_device() ? HOST_MAX_TEAMS : 256; for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target // a is implicitly captured as a firsptivate #pragma omp teams num_teams(num_teams) firstprivate(a) { a += omp_get_team_num(); A[omp_get_team_num()] += a; } } for (int i = 0 ; i < num_teams ; i++) if (A[i] != 10+i*TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) (10+i*TRIALS), A[i]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); ZERO(A); fail = 0; a = 10; num_teams = omp_is_initial_device() ? HOST_MAX_TEAMS : 256; for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target firstprivate(a) #pragma omp teams num_teams(num_teams) private(a) { a = omp_get_team_num(); A[omp_get_team_num()] += a; } } for (int i = 0 ; i < num_teams ; i++) if (A[i] != i*TRIALS) { printf("Error at %d, h = %lf, d = %lf\n", i, (double) (i*TRIALS), A[i]); fail = 1; } if(fail) printf("Failed\n"); else printf("Succeeded\n"); return 0; }