int main(int argc, char **argv) { int counter = 0; int dim, nth, nbi, nbj, iter; if (3 != argc) usage(argv); nbi = strtol(argv[1], NULL, 0); nbj = strtol(argv[2], NULL, 0); if (nbi <= 0 || nbj <= 0) usage(argv); int niter = 10; for (dim = MINDIM; dim <= MAXDIM; dim *= 2) { nth = nbi * nbj; /* Once to warm up. */ genmatrix(counter++); matmult(nbi, nbj, dim); printf("matrix size: %dx%d = %d (%d bytes) ", dim, dim, dim*dim, dim*dim*(int)sizeof(elt)); printf("blksize %dx%d thr %d itr %d:\n", dim/nbi, dim/nbj, nth, niter); for (iter = 0; iter < niter; iter++) { genmatrix(counter++); uint64_t ts = bench_time(); matmult(nbi, nbj, dim); ts = bench_time() - ts; printf("%lld.%09lld\n", (long long)ts / 1000000000, (long long)ts % 1000000000); } } return 0; }
struct neighbor2d *neighbors2d_hashcpu( uint ncells, int mesh_size, int levmx, int *i, int *j, int *level ) { struct neighbor2d *neigh2d = (struct neighbor2d *)malloc(ncells*sizeof(struct neighbor2d)); int *levtable = (int *)malloc(levmx+1); for (int lev=0; lev<levmx+1; lev++){ levtable[lev] = (int)pow(2,lev); } int jmaxsize = mesh_size*levtable[levmx]; int imaxsize = mesh_size*levtable[levmx]; int **hash = (int **)genmatrix(jmaxsize, imaxsize, sizeof(int)); // Not needed -- for debug //for (int jj = 0; jj<jmaxsize; jj++){ // for (int ii = 0; ii<imaxsize; ii++){ // hash[jj][ii]=-1; // } //} for(int ic=0; ic<ncells; ic++){ int lev = level[ic]; if (lev == levmx) { hash[j[ic]][i[ic]] = ic; } else { for (int jj = j[ic]*levtable[levmx-lev]; jj < (j[ic]+1)*levtable[levmx-lev]; jj++) { for (int ii=i[ic]*levtable[levmx-lev]; ii<(i[ic]+1)*levtable[levmx-lev]; ii++) { hash[jj][ii] = ic; } } } } for (int ic=0; ic<ncells; ic++){ int ii = i[ic]; int jj = j[ic]; int lev = level[ic]; int levmult = levtable[levmx-lev]; neigh2d[ic].left = hash[ jj *levmult ][MAX( ii *levmult-1, 0 )]; neigh2d[ic].right = hash[ jj *levmult ][MIN( (ii+1)*levmult, imaxsize-1)]; neigh2d[ic].bottom = hash[MAX( jj *levmult-1, 0) ][ ii *levmult ]; neigh2d[ic].top = hash[MIN( (jj+1)*levmult, jmaxsize-1)][ ii *levmult ]; } return(neigh2d); }
int main1(int argc, char **argv) { int nbi = 4; int nbj = 4; int nth = nbi * nbj; int dim = 1024; /* Block size = 256x256 */ int i; int niter = 10; uint64_t tt = 0; for (i = 0; i < niter; ++i) { genmatrix(i); uint64_t ts = bench_time(); matmult(nbi, nbj, dim); tt += bench_time() - ts; } tt /= niter; printf("blksize %dx%d thr %d itr %d: %lld.%09lld\n", dim/nbi, dim/nbj, nth, niter, (long long)tt / 1000000000, (long long)tt % 1000000000); return 0; }
int main(int argc, char **argv) { int nth, nbi, nbj, iter; int counter = 0; if (3 != argc) usage(argv); nbi = strtol(argv[1], NULL, 0); nbj = strtol(argv[2], NULL, 0); if (nbi <= 0 || nbj <= 0) usage(argv); nth = nbi * nbj; int niter = 10; for (n = MINDIM; n <= MAXDIM; n *= 2) { printf("matrix size: %dx%d = %d (%d bytes) ", n, n, n*n, n*n*(int)sizeof(mtype)); printf("blksize %dx%d thr %4d itr %d:\n", n/nbi, n/nbj, nth, niter); for (iter = 0; iter < niter; iter++) { genmatrix(counter++); uint64_t ts = bench_time(); plu(nbi, nbj); ts = bench_time() - ts; printf("%lld.%09lld\n", (long long)ts / 1000000000, (long long)ts % 1000000000); #if CHECK_CORRECTNESS matmult(); check(Orig, R); #endif } } return 0; }
static int run(int argc, char **argv) { static const MeCab::Option long_options[] = { { "dicdir", 'd', ".", "DIR", "set DIR as dicdir(default \".\" )" }, { "outdir", 'o', ".", "DIR", "set DIR as output dir" }, { "model", 'm', 0, "FILE", "use FILE as model file" }, { "version", 'v', 0, 0, "show the version and exit" }, { "training-algorithm", 'a', "crf", "(crf|hmm)", "set training algorithm" }, { "default-emission-cost", 'E', "4000", "INT", "set default emission cost for HMM" }, { "default-transition-cost", 'T', "4000", "INT", "set default transition cost for HMM" }, { "help", 'h', 0, 0, "show this help and exit." }, { 0, 0, 0, 0 } }; Param param; if (!param.open(argc, argv, long_options)) { std::cout << param.what() << "\n\n" << COPYRIGHT << "\ntry '--help' for more information." << std::endl; return -1; } if (!param.help_version()) return 0; ContextID cid; DecoderFeatureIndex fi; DictionaryRewriter rewrite; const std::string dicdir = param.get<std::string>("dicdir"); const std::string outdir = param.get<std::string>("outdir"); const std::string model = param.get<std::string>("model"); #define DCONF(file) create_filename(dicdir, std::string(file)).c_str() #define OCONF(file) create_filename(outdir, std::string(file)).c_str() CHECK_DIE(param.load(DCONF(DICRC))) << "no such file or directory: " << DCONF(DICRC); std::string charset; { Dictionary dic; CHECK_DIE(dic.open(DCONF(SYS_DIC_FILE), "r")); charset = dic.charset(); CHECK_DIE(!charset.empty()); } int default_emission_cost = 0; int default_transition_cost = 0; std::string type = param.get<std::string>("training-algorithm"); toLower(&type); if (type == "hmm") { default_emission_cost = param.get<int>("default-emission-cost"); default_transition_cost = param.get<int>("default-transition-cost"); CHECK_DIE(default_transition_cost > 0) << "default transition cost must be > 0"; CHECK_DIE(default_emission_cost > 0) << "default transition cost must be > 0"; param.set("identity-template", 1); } CharProperty property; CHECK_DIE(property.open(param)); property.set_charset(charset.c_str()); const std::string bos = param.get<std::string>("bos-feature"); const int factor = param.get<int>("cost-factor"); std::vector<std::string> dic; enum_csv_dictionaries(dicdir.c_str(), &dic); { CHECK_DIE(dicdir != outdir) << "output directory = dictionary directory! " "Please specify different directory."; CHECK_DIE(!outdir.empty()) << "output directory is empty"; CHECK_DIE(!model.empty()) << "model file is empty"; CHECK_DIE(fi.open(param)) << fi.what(); CHECK_DIE(factor > 0) << "cost factor needs to be positive value"; CHECK_DIE(!bos.empty()) << "bos-feature is empty"; CHECK_DIE(dic.size()) << "no dictionary is found in " << dicdir; CHECK_DIE(rewrite.open(DCONF(REWRITE_FILE))); } gencid_bos(bos, &rewrite, &cid); gencid(DCONF(UNK_DEF_FILE), &rewrite, &cid); for (std::vector<std::string>::const_iterator it = dic.begin(); it != dic.end(); ++it) { gencid(it->c_str(), &rewrite, &cid); } std::cout << "emitting " << OCONF(LEFT_ID_FILE) << "/ " << OCONF(RIGHT_ID_FILE) << std::endl; cid.build(); cid.save(OCONF(LEFT_ID_FILE), OCONF(RIGHT_ID_FILE)); gendic(DCONF(UNK_DEF_FILE), OCONF(UNK_DEF_FILE), property, &rewrite, cid, &fi, true, factor, default_emission_cost); for (std::vector<std::string>::const_iterator it = dic.begin(); it != dic.end(); ++it) { std::string file = *it; remove_pathname(&file); gendic(it->c_str(), OCONF(file.c_str()), property, &rewrite, cid, &fi, false, factor, default_emission_cost); } genmatrix(OCONF(MATRIX_DEF_FILE), cid, &fi, factor, default_transition_cost); copy(DCONF(CHAR_PROPERTY_DEF_FILE), OCONF(CHAR_PROPERTY_DEF_FILE)); copy(DCONF(REWRITE_FILE), OCONF(REWRITE_FILE)); copy(DCONF(DICRC), OCONF(DICRC)); if (type == "crf") copy(DCONF(FEATURE_FILE), OCONF(FEATURE_FILE)); #undef OCONF #undef DCONF std::cout << "\ndone!\n"; return 0; }