int maingen(int argc, char** argv) { uint8_t logs[256]; uint8_t exps[255]; unsigned int x; unsigned int i; x = 1; for( i = 0; i < 255; ++i ) { exps[i] = x; logs[x] = i; x <<= 1; if( x & 0x100 ) x ^= 0x11d; /* Unset the 8th bit and mix in 0x1d */ } logs[0] = 0; /* can't log(0) so just set it neatly to 0 */ /* The above generation algorithm clearly demonstrates that * logs[exps[i]] == i for 0 <= i <= 254 * exps[logs[i]] == i for 1 <= i <= 255 */ /* Spew out the tables */ fprintf(stdout, "\ /*\n\ * This file is autogenerated by gfshare_maketable.\n\ */\n\ \n\ static uint8_t logs[256] = {\n "); for( i = 0; i < 256; ++i ) { fprintf(stdout, "0x%02x", logs[i]); if( i == 255 ) fprintf(stdout, " };\n"); else if( (i % 8) == 7 ) fprintf(stdout, ",\n "); else fprintf(stdout, ", "); } /* The exp table we output from 0 to 509 because that way when we * do the lagrange interpolation we don't have to be quite so strict * with staying inside the field which makes it quicker */ fprintf(stdout, "\ \n\ static uint8_t exps[510] = {\n "); for( i = 0; i < 510; ++i ) { fprintf(stdout, "0x%02x", exps[i % 255]); /* exps[255]==exps[0] */ if( i == 509 ) fprintf(stdout, " };\n"); else if( (i % 8) == 7) fprintf(stdout, ",\n "); else fprintf(stdout, ", "); } return 0; } void iguana_main(void *arg) { int32_t usessl = 0, ismainnet = 1; struct supernet_info *myinfo; char *tmpstr,*helperargs,*coinargs,helperstr[512]; int32_t i; mycalloc(0,0,0); myinfo = SuperNET_MYINFO(0); FILE *fp; int32_t iter; void ztest(); ztest(); strcpy(myinfo->NXTAPIURL,"http://127.0.0.1:7876/nxt"); for (iter=0; iter<2; iter++) { if ( (fp= fopen(iter == 0 ? "nxtpasswords" : "fimpasswords","rb")) != 0 ) { char line[4096],NXTaddr[64]; int32_t j; uint8_t pubkey[32]; while ( fgets(line,sizeof(line),fp) > 0 ) { j = (int32_t)strlen(line) - 1; line[j] = 0; calc_NXTaddr(NXTaddr,pubkey,(uint8_t *)line,j); printf("FORGING %s (%s)\n",NXTaddr,issue_startForging(myinfo,line)); } fclose(fp); } strcpy(myinfo->NXTAPIURL,"http://127.0.0.1:7886/nxt"); } if ( usessl == 0 ) strcpy(myinfo->NXTAPIURL,"http://127.0.0.1:"); else strcpy(myinfo->NXTAPIURL,"https://127.0.0.1:"); if ( ismainnet != 0 ) strcat(myinfo->NXTAPIURL,"7876/nxt"); else strcat(myinfo->NXTAPIURL,"6876/nxt"); if ( 0 ) { #ifndef _WIN32 signal(SIGINT,sigint_func); signal(SIGILL,sigillegal_func); signal(SIGHUP,sighangup_func); //signal(SIGKILL,sigkill_func); signal(SIGABRT,sigabort_func); signal(SIGQUIT,sigquit_func); signal(SIGCHLD,sigchild_func); signal(SIGALRM,sigalarm_func); signal(SIGCONT,sigcontinue_func); #endif } //iguana_chaingenesis(1,1403138561,0x1e0fffff,8359109,bits256_conv("fd1751cc6963d88feca94c0d01da8883852647a37a0a67ce254d62dd8c9d5b2b")); // BTCD //iguana_chaingenesis(1,1409839200,0x1e0fffff,64881664,bits256_conv("698a93a1cacd495a7a4fb3864ad8d06ed4421dedbc57f9aaad733ea53b1b5828")); // VPN iguana_chaingenesis(1,1317972665,0x1e0ffff0,2084524493,bits256_conv("97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9")); // LTC iguana_initQ(&helperQ,"helperQ"); OS_ensure_directory("help"); OS_ensure_directory("confs"); OS_ensure_directory("DB"), OS_ensure_directory("DB/ECB"); OS_ensure_directory("tmp"); if ( (tmpstr= SuperNET_JSON(myinfo,cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"help\"}"),0)) != 0 ) { if ( (API_json= cJSON_Parse(tmpstr)) != 0 && (API_json= jobj(API_json,"result")) != 0 ) API_json = jobj(API_json,"API"); free(tmpstr); } if ( IGUANA_NUMHELPERS == 0 ) IGUANA_NUMHELPERS = 1; for (i=0; i<IGUANA_NUMHELPERS; i++) { sprintf(helperstr,"{\"name\":\"helper.%d\"}",i); helperargs = clonestr(helperstr); iguana_launch(iguana_coinadd("BTCD"),"iguana_helper",iguana_helper,helperargs,IGUANA_PERMTHREAD); } iguana_launch(iguana_coinadd("BTCD"),"rpcloop",iguana_rpcloop,SuperNET_MYINFO(0),IGUANA_PERMTHREAD); category_init(&MYINFO); if ( (coinargs= SuperNET_keysinit(&MYINFO,arg)) != 0 ) iguana_launch(iguana_coinadd("BTCD"),"iguana_coins",iguana_coins,coinargs,IGUANA_PERMTHREAD); else if ( 1 ) { #ifdef __APPLE__ sleep(1); char *str; strcpy(MYINFO.rpcsymbol,"BTC"); iguana_launchcoin(MYINFO.rpcsymbol,cJSON_Parse("{}")); if ( 1 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":3,\"newcoin\":\"BTC\",\"active\":0}"),0)) != 0 ) { free(str); if ( 1 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":3,\"newcoin\":\"BTCD\",\"active\":0}"),0)) != 0 ) { free(str); if ( 0 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"login\",\"handle\":\"alice\",\"password\":\"alice\",\"passphrase\":\"alice\"}"),0)) != 0 ) { free(str); if ( (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"login\",\"handle\":\"bob\",\"password\":\"bob\",\"passphrase\":\"bob\"}"),0)) != 0 ) free(str); } } } sleep(1); #endif } if ( arg != 0 ) SuperNET_JSON(&MYINFO,cJSON_Parse(arg),0); mainloop(&MYINFO); }
int main(int argc, char *argv[]) { static const int ex_under = FE_UNDERFLOW | FE_INEXACT; /* shorthand */ static const int ex_over = FE_OVERFLOW | FE_INEXACT; long double ldbl_small, ldbl_eps, ldbl_max; printf("1..5\n"); #ifdef __i386__ fpsetprec(FP_PE); #endif /* * We can't use a compile-time constant here because gcc on * FreeBSD/i386 assumes long doubles are truncated to the * double format. */ ldbl_small = ldexpl(1.0, LDBL_MIN_EXP - LDBL_MANT_DIG); ldbl_eps = LDBL_EPSILON; ldbl_max = ldexpl(1.0 - ldbl_eps / 2, LDBL_MAX_EXP); /* * Special cases involving zeroes. */ #define ztest(prec) \ test##prec(copysign##prec(1.0, nextafter##prec(0.0, -0.0)), -1.0, 0); \ test##prec(copysign##prec(1.0, nextafter##prec(-0.0, 0.0)), 1.0, 0); \ test##prec(copysign##prec(1.0, nexttoward##prec(0.0, -0.0)), -1.0, 0);\ test##prec(copysign##prec(1.0, nexttoward##prec(-0.0, 0.0)), 1.0, 0) ztest(); ztest(f); ztest(l); #undef ztest #define stest(next, eps, prec) \ test##prec(next(-0.0, 42.0), eps, ex_under); \ test##prec(next(0.0, -42.0), -eps, ex_under); \ test##prec(next(0.0, INFINITY), eps, ex_under); \ test##prec(next(-0.0, -INFINITY), -eps, ex_under) stest(nextafter, 0x1p-1074, ); stest(nextafterf, 0x1p-149f, f); stest(nextafterl, ldbl_small, l); stest(nexttoward, 0x1p-1074, ); stest(nexttowardf, 0x1p-149f, f); stest(nexttowardl, ldbl_small, l); #undef stest printf("ok 1 - next\n"); /* * `x == y' and NaN tests */ testall(42.0, 42.0, 42.0, 0); testall(-42.0, -42.0, -42.0, 0); testall(INFINITY, INFINITY, INFINITY, 0); testall(-INFINITY, -INFINITY, -INFINITY, 0); testall(NAN, 42.0, NAN, 0); testall(42.0, NAN, NAN, 0); testall(NAN, NAN, NAN, 0); printf("ok 2 - next\n"); /* * Tests where x is an ordinary normalized number */ testboth(1.0, 2.0, 1.0 + DBL_EPSILON, 0, ); testboth(1.0, -INFINITY, 1.0 - DBL_EPSILON/2, 0, ); testboth(1.0, 2.0, 1.0 + FLT_EPSILON, 0, f); testboth(1.0, -INFINITY, 1.0 - FLT_EPSILON/2, 0, f); testboth(1.0, 2.0, 1.0 + ldbl_eps, 0, l); testboth(1.0, -INFINITY, 1.0 - ldbl_eps/2, 0, l); testboth(-1.0, 2.0, -1.0 + DBL_EPSILON/2, 0, ); testboth(-1.0, -INFINITY, -1.0 - DBL_EPSILON, 0, ); testboth(-1.0, 2.0, -1.0 + FLT_EPSILON/2, 0, f); testboth(-1.0, -INFINITY, -1.0 - FLT_EPSILON, 0, f); testboth(-1.0, 2.0, -1.0 + ldbl_eps/2, 0, l); testboth(-1.0, -INFINITY, -1.0 - ldbl_eps, 0, l); /* Cases where nextafter(...) != nexttoward(...) */ test(nexttoward(1.0, 1.0 + ldbl_eps), 1.0 + DBL_EPSILON, 0); testf(nexttowardf(1.0, 1.0 + ldbl_eps), 1.0 + FLT_EPSILON, 0); testl(nexttowardl(1.0, 1.0 + ldbl_eps), 1.0 + ldbl_eps, 0); printf("ok 3 - next\n"); /* * Tests at word boundaries, normalization boundaries, etc. */ testboth(0x1.87654ffffffffp+0, INFINITY, 0x1.87655p+0, 0, ); testboth(0x1.87655p+0, -INFINITY, 0x1.87654ffffffffp+0, 0, ); testboth(0x1.fffffffffffffp+0, INFINITY, 0x1p1, 0, ); testboth(0x1p1, -INFINITY, 0x1.fffffffffffffp+0, 0, ); testboth(0x0.fffffffffffffp-1022, INFINITY, 0x1p-1022, 0, ); testboth(0x1p-1022, -INFINITY, 0x0.fffffffffffffp-1022, ex_under, ); testboth(0x1.fffffep0f, INFINITY, 0x1p1, 0, f); testboth(0x1p1, -INFINITY, 0x1.fffffep0f, 0, f); testboth(0x0.fffffep-126f, INFINITY, 0x1p-126f, 0, f); testboth(0x1p-126f, -INFINITY, 0x0.fffffep-126f, ex_under, f); #if LDBL_MANT_DIG == 53 testboth(0x1.87654ffffffffp+0L, INFINITY, 0x1.87655p+0L, 0, l); testboth(0x1.87655p+0L, -INFINITY, 0x1.87654ffffffffp+0L, 0, l); testboth(0x1.fffffffffffffp+0L, INFINITY, 0x1p1L, 0, l); testboth(0x1p1L, -INFINITY, 0x1.fffffffffffffp+0L, 0, l); testboth(0x0.fffffffffffffp-1022L, INFINITY, 0x1p-1022L, 0, l); testboth(0x1p-1022L, -INFINITY, 0x0.fffffffffffffp-1022L, ex_under, l); #elif LDBL_MANT_DIG == 64 && !defined(__i386) testboth(0x1.87654321fffffffep+0L, INFINITY, 0x1.87654322p+0L, 0, l); testboth(0x1.87654322p+0L, -INFINITY, 0x1.87654321fffffffep+0L, 0, l); testboth(0x1.fffffffffffffffep0L, INFINITY, 0x1p1L, 0, l); testboth(0x1p1L, -INFINITY, 0x1.fffffffffffffffep0L, 0, l); testboth(0x0.fffffffffffffffep-16382L, INFINITY, 0x1p-16382L, 0, l); testboth(0x1p-16382L, -INFINITY, 0x0.fffffffffffffffep-16382L, ex_under, l); #elif LDBL_MANT_DIG == 113 testboth(0x1.876543210987ffffffffffffffffp+0L, INFINITY, 0x1.876543210988p+0, 0, l); testboth(0x1.876543210988p+0L, -INFINITY, 0x1.876543210987ffffffffffffffffp+0L, 0, l); testboth(0x1.ffffffffffffffffffffffffffffp0L, INFINITY, 0x1p1L, 0, l); testboth(0x1p1L, -INFINITY, 0x1.ffffffffffffffffffffffffffffp0L, 0, l); testboth(0x0.ffffffffffffffffffffffffffffp-16382L, INFINITY, 0x1p-16382L, 0, l); testboth(0x1p-16382L, -INFINITY, 0x0.ffffffffffffffffffffffffffffp-16382L, ex_under, l); #endif printf("ok 4 - next\n"); /* * Overflow tests */ test(idd(nextafter(DBL_MAX, INFINITY)), INFINITY, ex_over); test(idd(nextafter(INFINITY, 0.0)), DBL_MAX, 0); test(idd(nexttoward(DBL_MAX, DBL_MAX * 2.0L)), INFINITY, ex_over); #if LDBL_MANT_DIG > 53 test(idd(nexttoward(INFINITY, DBL_MAX * 2.0L)), DBL_MAX, 0); #endif testf(idf(nextafterf(FLT_MAX, INFINITY)), INFINITY, ex_over); testf(idf(nextafterf(INFINITY, 0.0)), FLT_MAX, 0); testf(idf(nexttowardf(FLT_MAX, FLT_MAX * 2.0)), INFINITY, ex_over); testf(idf(nexttowardf(INFINITY, FLT_MAX * 2.0)), FLT_MAX, 0); testboth(ldbl_max, INFINITY, INFINITY, ex_over, l); testboth(INFINITY, 0.0, ldbl_max, 0, l); printf("ok 5 - next\n"); return (0); }
ATF_TC_BODY(Zone, tc) { ztest("%z"); }
int main(int argc, char** argv) { ros::init(argc, argv, "eigen_test"); ros::NodeHandle nh_jntPub; // node handle for joint command publisher // ros::Publisher pub_joint_commands; // // pub_joint_commands = nh_jntPub.advertise<atlas_msgs::AtlasCommand>("/atlas/atlas_command", 1, true); ROS_INFO("test eigen program"); Eigen::Matrix3f A; Eigen::Vector3f b; A << 1,2,3, 4,5,6, 7,8,10; A(1,2)=0; // how to access one element of matrix; start from 0; no warning out of range... b << 3,3,4; std::cout <<"b = "<<b <<std::endl; // column operaton: replace first column of A with vector b: A.col(0)= b; // could copy columns of matrices w/ A.col(0) = B.col(0); std::cout <<"A = "<<A <<std::endl; Eigen::MatrixXd mat1 = Eigen::MatrixXd::Zero(6, 6); //6x6 matrix full of zeros Eigen::MatrixXd mat2 = Eigen::MatrixXd::Identity(6, 6); //6x6 identity matrix std::cout<<mat1<<std::endl; std::cout<<mat2<<std::endl; Eigen::Vector3f xtest = A.colPivHouseholderQr().solve(b); std::cout<<"soln xtest = "<<xtest<<std::endl; Eigen::Vector3f x = A.partialPivLu().solve(b); //dec.solve(b); //A.colPivHouseholderQr().solve(b); std::cout<<"soln x = "<<x<<std::endl; Eigen::Vector3f btest = A*x; std::cout<<"test soln: A*x = " <<btest<<std::endl; //extend to 6x6 test: v = M*z, find z using 2 methods // use double-precision matrices/vectors Eigen::MatrixXd M = Eigen::MatrixXd::Random(6,6); std::cout<<"test 6x6: M = "<<M<<std::endl; Eigen::VectorXd v(6); v << 1,2,3,4,5,6; std::cout<<"v = "<<v<<std::endl; Eigen::VectorXd z(6); Eigen::VectorXd ztest(6); ztest = M.colPivHouseholderQr().solve(v); std::cout<<"soln ztest = "<<ztest<<std::endl; z = M.partialPivLu().solve(v); std::cout<<"soln 6x6: z = "<<z<<std::endl; Eigen::VectorXd vtest(6); vtest = M*z; std::cout<<"test soln: M*z = "<<vtest<<std::endl; // .norm() operator... double relative_error = (M*z - v).norm() / v.norm(); // norm() is L2 norm std::cout << "The relative error is:\n" << relative_error << std::endl; std::cout<<"dot prod, v, z: "<< v.dot(z)<<std::endl; std::cout<<"cross prod, b-cross-x: " << b.cross(x)<<std::endl; return 0; }
int main(int argc, char **argv) { double starttime, endtime; int ntasks, myrank; char name[128]; int namelen; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &myrank); MPI_Comm_size(MPI_COMM_WORLD, &ntasks); MPI_Get_processor_name(name,&namelen); /* Get a few OpenMP parameters. */ int O_P = omp_get_num_procs(); /* get number of OpenMP processors */ int O_T = omp_get_num_threads(); /* get number of OpenMP threads */ int O_ID = omp_get_thread_num(); /* get OpenMP thread ID */ //printf("name:%s M_ID:%d O_ID:%d O_P:%d O_T:%d\n", name,myrank,O_ID,O_P,O_T); FILE *f; char line[LINE_SIZE]; int numlines = 0; exprinfo *exprannot = NULL; char **glines = NULL; f = fopen("gene_list.txt", "r"); while(fgets(line, LINE_SIZE, f)) { glines = (char**)realloc(glines, sizeof(char*)*(numlines+1)); glines[numlines] = strdup(line); char *pch = strtok (line,","); char * gene = pch; pch = strtok (NULL, ","); int chr = atoi(trimwhitespace(pch)); exprannot = (exprinfo*)realloc(exprannot,sizeof(exprinfo)*(numlines+1)); exprannot[numlines].gene = strdup(gene); exprannot[numlines].chr = chr; if (!exprannot) printf("not allcoated\n"); numlines++; } fclose(f); f = fopen("probe_id_mapping.txt", "r"); numlines = 0; free(glines[0]); free(glines); probeinfo *records = NULL; char **lines = NULL; while(fgets(line, LINE_SIZE, f)) { lines = (char**)realloc(lines, sizeof(char*)*(numlines+1)); lines[numlines] = strdup(line); char *pch = strtok (line,","); int probeid = atoi(pch); pch = strtok (NULL, ","); char * gene = pch; pch = strtok (NULL, ","); int chr = atoi(trimwhitespace(pch)); records = (probeinfo*)realloc(records,sizeof(probeinfo)*(numlines+1)); records[numlines].probeid = probeid; records[numlines].chr = chr; records[numlines].gene = strdup(gene); if (!records) printf("not allcoated\n"); numlines++; } free(lines[0]); free(lines); fclose(f); int NUM_GENES = numlines; unsigned long x_nr, x_nc, y_nr, y_nc; double **X = h5_read("x.h5", 1, "/X", &x_nr, &x_nc); double **Y = h5_read("filtered_probes.h5", 1, "/FilteredProbes", &y_nr, &y_nc); //printf("loaded X, num rows = %d, num cols = %d\n", x_nr, x_nc); //printf("loaded Y, num rows = %d, num cols = %d\n", y_nr, y_nc); unsigned long total_mem = (x_nr * y_nc); double **RHO = create2dArray(x_nr, y_nc); int gene, probe, tid, work_completed; work_completed = 0; int BLOCK_SIZE = NUM_ROWS/ntasks; int offset = myrank*BLOCK_SIZE; int STOP_IDX = offset+BLOCK_SIZE; if (NUM_ROWS - STOP_IDX < BLOCK_SIZE) STOP_IDX = NUM_ROWS; // printf("offset = %d, for rank %d, with ntasks = %d, and BLOCK_SIZE = %d, STOP_IDX = %d\n", // offset, myrank, ntasks, BLOCK_SIZE, STOP_IDX); int num_sig_found = 0; starttime = MPI_Wtime(); #pragma omp parallel \ for shared(X, Y, RHO, BLOCK_SIZE, offset, work_completed) \ private(probe,gene, tid) for (gene = offset; gene < STOP_IDX; gene++) { for (probe = 0; probe < NUM_COLS; probe++) { double *x = getrowvec(X, gene, BUFFER_SIZE); double *y = getcolvec(Y, probe, BUFFER_SIZE); double avgx = mean(x, BUFFER_SIZE); double * xcentered = sub(x, avgx, BUFFER_SIZE); double avgy = mean(y, BUFFER_SIZE); double * ycentered = sub(y, avgy, BUFFER_SIZE); double * prod_result = prod(xcentered, ycentered, BUFFER_SIZE); double sum_prod = sum(prod_result, BUFFER_SIZE); double stdX = stddev(x, avgx, BUFFER_SIZE); double stdY = stddev(y, avgy, BUFFER_SIZE); double rho = sum_prod/((BUFFER_SIZE-1)*(stdX*stdY)); RHO[gene][probe] = rho; if (work_completed % 10000 == 0) { tid = omp_get_thread_num(); printf("rank = %d, work = %d, result[%d,%d] from %d = %f\n", myrank, work_completed, gene, probe, tid, rho); } work_completed++; free(x); free(y); free(xcentered); free(ycentered); free(prod_result); } } //printf("********* %d FINISHED **********\n", myrank); //f = fopen("significant.txt", "a"); #pragma omp parallel for shared(RHO,exprannot, records) for (int i = 0; i < NUM_ROWS; i++) { for (int j = 0; j < NUM_COLS; j++) { double zscore = ztest(RHO[i][j],BUFFER_SIZE); /* if (zscore > 5.0) { fprintf(f, "%d,%d,%f,%f,%d,%s,%d,%s\n", i, j, zscore, RHO[i][j], records[j].chr, records[j].gene, exprannot[i].chr,exprannot[i].gene); if (i*j%1000 == 0) printf("%d,%d,%f,%f,%d,%s,%d,%s\n", i, j, zscore, RHO[i][j], records[j].chr, records[j].gene, exprannot[i].chr,exprannot[i].gene); } */ } } //fclose(f); endtime = MPI_Wtime(); free(X[0]); free(X); free(Y[0]); free(Y); printf("rank %d - elapse time - %f\n",myrank, endtime-starttime); //for (int i = 0; i < NUM_ROWS; i++) { //printf("%s,%d\n", exprannot[i].gene, exprannot[i].chr); //} //printf("rank %d FINISHED\n",myrank); //h5_write(RHO, NUM_ROWS, NUM_COLS, "rho_omp.h5", "/rho"); free(RHO[0]); free(exprannot); free(records); free(RHO); MPI_Finalize(); return 0; }