//******************************************************************* // QBtCompareFileDialog CONSTRUCTOR //******************************************************************* QBtCompareFileDialog::QBtCompareFileDialog( QWidget* const in_parent, const QString& in_fpath1, const QString& in_fpath2 ) : QDialog ( in_parent ) , fpath1_ ( in_fpath1 ) , fpath2_ ( in_fpath2 ) , ifield1_ ( new QBtInfoField ) , ifield2_ ( new QBtInfoField ) , progress_bar_( new QProgressBar ) , cancel_ ( new QPushButton( tr( CANCEL ) ) ) , start_ ( new QPushButton( tr( START ) ) ) , comparator_ ( new QBtFileComparator( this ) ) , is_started_ ( false ) , is_canceled_ ( false ) { setWindowTitle( tr( CAPTION ) ); QGroupBox* const files_gbox = new QGroupBox( tr( FILES ) ); QGridLayout* files_layout = new QGridLayout( files_gbox ); QLabel* const prompt1 = new QLabel( tr( FILE_NR1 ) ); QLabel* const prompt2 = new QLabel( tr( FILE_NR2 ) ); prompt1->setAlignment( Qt::AlignRight ); prompt2->setAlignment( Qt::AlignRight ); files_layout->addWidget( prompt1 , 0, 0 ); files_layout->addWidget( prompt2 , 1, 0 ); files_layout->addWidget( ifield1_, 0, 1 ); files_layout->addWidget( ifield2_, 1, 1 ); QGroupBox* const progress_gbox = new QGroupBox( tr( PROGRESS ) ); QHBoxLayout* const progress_layout = new QHBoxLayout( progress_gbox ); progress_layout->addWidget( progress_bar_ ); QHBoxLayout* const btn_layout = new QHBoxLayout; btn_layout->addStretch( 100 ); btn_layout->addWidget( cancel_ ); btn_layout->addWidget( start_ ); QVBoxLayout* const main_layout = new QVBoxLayout; main_layout->addWidget( files_gbox ); main_layout->addWidget( progress_gbox ); main_layout->addLayout( btn_layout ); setLayout( main_layout ); connect( cancel_ , SIGNAL( clicked() ), this , SLOT ( cancel() ) ); connect( start_ , SIGNAL( clicked() ), this , SLOT ( start() ) ); connect( comparator_, SIGNAL( init_progress( qint64 ) ), this , SLOT ( init_progress( qint64 ) ) ); connect( comparator_, SIGNAL( progress( qint64 ) ), this , SLOT ( progress( qint64 ) ) ); }
//******************************************************************* // compare PUBLIC //******************************************************************* qint32 QBtFileComparator::compare( const QString& in_fname1, const QString& in_fname2 ) { qint32 retval = IO_ERROR; char buffer1[ BUFFER_SIZE ] = { 0 }; char buffer2[ BUFFER_SIZE ] = { 0 }; QFile in1( in_fname1 ); QFile in2( in_fname2 ); emit init_progress( in1.size() ); if( in1.size() != in2.size() ) { emit progress( in1.size() ); return NOT_EQUAL; } qint64 total = qint64(); if( in1.open( QIODevice::ReadOnly ) ) { if( in2.open( QIODevice::ReadOnly ) ) { while( loop_ && !in1.atEnd() && !in2.atEnd() ) { const quint32 n1 = in1.read( buffer1, BUFFER_SIZE ); const quint32 n2 = in2.read( buffer2, BUFFER_SIZE ); retval = ( n1 == n2 ) ? memcmp( buffer1, buffer2, n1 ) : NOT_EQUAL; if( EQUAL != retval ) break; total += n1; emit progress( total ); } in2.close(); } in1.close(); } return retval; }
static void adhoc_init_progress(int total, const char *text) { char buf[32]; load_background(WP_LOGO); video_copy_rect(work_frame, draw_frame, &full_rect, &full_rect); small_icon(6, 3, UI_COLOR(UI_PAL_TITLE), ICON_SYSTEM); sprintf(buf, "AdHoc - %s", game_name); uifont_print(32, 5, UI_COLOR(UI_PAL_TITLE), buf); video_copy_rect(draw_frame, work_frame, &full_rect, &full_rect); init_progress(total, text); }
int main( int argc, char *argv[] ) { config conf; setup_config(&conf, argc, argv); init_progress(conf.progress_width, conf.nsteps, conf.progress_disabled); TYPE dx = 20.f; TYPE dt = 0.002f; // compute the pitch for perfect coalescing size_t dimx = conf.nx + 2*conf.radius; size_t dimy = conf.ny + 2*conf.radius; size_t nbytes = dimx * dimy * sizeof(TYPE); if (conf.verbose) { printf("x = %zu, y = %zu\n", dimx, dimy); printf("nsteps = %d\n", conf.nsteps); printf("radius = %d\n", conf.radius); } TYPE c_coeff[NUM_COEFF]; TYPE *curr = (TYPE *)malloc(nbytes); TYPE *next = (TYPE *)malloc(nbytes); TYPE *vsq = (TYPE *)malloc(nbytes); if (curr == NULL || next == NULL || vsq == NULL) { fprintf(stderr, "Allocations failed\n"); return 1; } config_sources(&conf.srcs, &conf.nsrcs, conf.nx, conf.ny, conf.nsteps); TYPE **srcs = sample_sources(conf.srcs, conf.nsrcs, conf.nsteps, dt); init_data(curr, next, vsq, c_coeff, dimx, dimy, dx, dt); double start = seconds(); for (int step = 0; step < conf.nsteps; step++) { for (int src = 0; src < conf.nsrcs; src++) { if (conf.srcs[src].t > step) continue; int src_offset = POINT_OFFSET(conf.srcs[src].x, conf.srcs[src].y, dimx, conf.radius); curr[src_offset] = srcs[src][step]; } fwd(next, curr, vsq, c_coeff, conf.nx, conf.ny, dimx, dimy, conf.radius); TYPE *tmp = next; next = curr; curr = tmp; update_progress(step + 1); } double elapsed_s = seconds() - start; finish_progress(); float point_rate = (float)conf.nx * conf.ny / (elapsed_s / conf.nsteps); fprintf(stderr, "iso_r4_2x: %8.10f s total, %8.10f s/step, %8.2f Mcells/s/step\n", elapsed_s, elapsed_s / conf.nsteps, point_rate / 1000000.f); if (conf.save_text) { save_text(curr, dimx, dimy, conf.ny, conf.nx, "snap.text", conf.radius); } free(curr); free(next); free(vsq); for (int i = 0; i < conf.nsrcs; i++) { free(srcs[i]); } free(srcs); return 0; }
int l1_logreg_train(dmatrix *X, double *b, double lambda, train_opts to, double *initial_x, double *initial_t, double *sol, int *total_ntiter, int *total_pcgiter) { /* problem data */ problem_data_t prob; variables_t vars; dmatrix *matX1; /* matX1 = diag(b)*X_std */ dmatrix *matX2; /* matX2 = X_std.^2 (only for pcg) */ double *ac, *ar; double *avg_x, *std_x; int m, n, ntiter, pcgiter, status; double pobj, dobj, gap; double t, s, maxAnu; double *g, *h, *z, *expz, *expmz; double *x, *v, *w, *u; double *dx, *dv, *dw, *du; double *gv, *gw, *gu, *gx; double *d1, *d2, *Aw; /* pcg variables */ pcg_status_t pcgstat; adata_t adata; mdata_t mdata; double *precond; /* temporary variables */ double *tm1, *tn1, *tn2, *tn3, *tn4, *tx1; /* temporary variables for dense case (cholesky) */ dmatrix *B; /* m x n (or m x n) */ dmatrix *BB; /* n x n (or m x m) */ char format_buf[PRINT_BUF_SIZE]; #if INTERNAL_PLOT dmatrix *internal_plot; dmat_new_dense(&internal_plot, 3, MAX_NT_ITER); memset(internal_plot->val,0,sizeof(double)*3*MAX_NT_ITER); /* row 1: cum_nt_iter, row 2: cum_pcg_iter, row 3: duality gap */ #endif p2func_progress print_progress = NULL; /* * INITIALIZATION */ s = 1.0; pobj = DBL_MAX; dobj = -DBL_MAX; pcgiter = 0; matX1 = NULL; matX2 = NULL; init_pcg_status(&pcgstat); dmat_duplicate(X, &matX1); dmat_copy(X, matX1); m = matX1->m; n = matX1->n; if (to.sflag == TRUE) { /* standardize_data not only standardizes the data, but also multiplies diag(b). */ standardize_data(matX1, b, &avg_x, &std_x, &ac, &ar); } else { /* matX1 = diag(b)*X */ dmat_diagscale(matX1, b, FALSE, NULL, TRUE); avg_x = std_x = ac = ar = NULL; } if (matX1->nz >= 0) /* only for pcg */ { dmat_elemAA(matX1, &matX2); } else { matX2 = NULL; } set_problem_data(&prob, matX1, matX2, ac, ar, b, lambda, avg_x, std_x); create_variables(&vars, m, n); get_variables(&vars, &x, &v, &w, &u, &dx, &dv, &dw, &du, &gx, &gv, &gw, &gu, &g, &h, &z, &expz, &expmz, &d1, &d2, &Aw); allocate_temporaries(m, n, (matX1->nz >= 0), &tm1, &tn1, &tn2, &tn3, &tn4, &tx1, &precond, &B, &BB); if (initial_x == NULL) { dmat_vset(1, 0.0, v); dmat_vset(n, 0.0, w); dmat_vset(n, 1.0, u); dmat_vset(n+n+1, 0, dx); t = min(max(1.0, 1.0 / lambda), 2.0 * n / ABSTOL); } else { dmat_vcopy(n+n+1, initial_x, x); dmat_vset(n+n+1, 0, dx); t = *initial_t; } set_adata(&adata, matX1, ac, ar, b, h, d1, d2); set_mdata(&mdata, m, n, precond); /* select printing function and format according to verbose level and method type (pcg/direct) */ if (to.verbose_level>=2) init_progress((matX1->nz >= 0), to.verbose_level, format_buf, &print_progress); /*** MAIN LOOP ************************************************************/ for (ntiter = 0; ntiter < MAX_NT_ITER; ntiter++) { /* * Sets v as the optimal value of the intercept. */ dmat_yAmpqx(matX1, ac, ar, w, Aw); optimize_intercept(v, z, expz, expmz, tm1, b, Aw, m); /* * Constructs dual feasible point nu. */ fprimes(m, expz, expmz, g, h); /* partially computes the gradient of phi. the rest part of the gradient will be completed while computing the search direction. */ gv[0] = dmat_dot(m, b, g); /* gv = b'*g */ dmat_yAmpqTx(matX1, ac, ar, g, gw); /* gw = A'*g */ dmat_waxpby(m, -1, g, 0, NULL, tm1); /* nu = -g */ maxAnu = dmat_norminf(n, gw); /* max(A'*nu) */ if (maxAnu > lambda) dmat_waxpby(m, lambda / maxAnu, tm1, 0.0, NULL, tm1); /* * Evaluates duality gap. */ pobj = logistic_loss2(m,z,expz,expmz)/m + lambda*dmat_norm1(n,w); dobj = max(nentropy(m, tm1) / m, dobj); gap = pobj - dobj; #if INTERNAL_PLOT internal_plot->val[0*MAX_NT_ITER+ntiter] = (double)ntiter; internal_plot->val[1*MAX_NT_ITER+ntiter] = (double)pcgiter; internal_plot->val[2*MAX_NT_ITER+ntiter] = gap; #endif if (to.verbose_level>=2) { (*print_progress)(format_buf, ntiter, gap, pobj, dobj, s, t, pcgstat.flag, pcgstat.relres, pcgstat.iter); } /* * Quits if gap < tolerance. */ if (gap < to.tolerance ) /***********************************************/ { if (sol != NULL) { /* trim solution */ int i; double lambda_threshold; lambda_threshold = to.ktolerance*lambda; sol[0] = x[0]; for (i = 0; i < n; i++) { sol[i+1] = (fabs(gw[i])>lambda_threshold)? x[i+1] : 0.0; } /* if standardized, sol = coeff/std */ if (to.sflag == TRUE && to.cflag == FALSE) { dmat_elemdivi(n, sol+1, std_x, sol+1); sol[0] -= dmat_dot(n, avg_x, sol+1); } } if (initial_x != NULL) { dmat_vcopy(n+n+1, x, initial_x); *initial_t = t; } if (total_pcgiter) *total_pcgiter = pcgiter; if (total_ntiter ) *total_ntiter = ntiter; /* free memory */ free_variables(&vars); free_temporaries(tm1, tn1, tn2, tn3, tn4, tx1, precond, B, BB); free_problem_data(&prob); #if INTERNAL_PLOT write_mm_matrix("internal_plot",internal_plot,"",TYPE_G); #endif return STATUS_SOLUTION_FOUND; } /********************************************************************/ /* * Updates t */ if (s >= 0.5) { t = max(min(2.0 * n * MU / gap, MU * t), t); } else if (s < 1e-5) { t = 1.1*t; } /* * Computes search direction. */ if (matX1->nz >= 0) { /* pcg */ compute_searchdir_pcg(&prob, &vars, t, s, gap, &pcgstat, &adata, &mdata, precond, tm1, tn1, tx1); pcgiter += pcgstat.iter; } else { /* direct */ if (n > m) { /* direct method for n > m, SMW */ compute_searchdir_chol_fat(&prob, &vars, t, B, BB, tm1, tn1, tn2, tn3, tn4); } else { /* direct method for n <= m */ compute_searchdir_chol_thin(&prob, &vars, t, B, BB, tm1, tn1, tn2); } } /* * Backtracking linesearch & update x = (v,w,u) and z. */ s = backtracking_linesearch(&prob, &vars, t, tm1, tx1); if (s < 0) break; /* BLS error */ } /*** END OF MAIN LOOP *****************************************************/ /* Abnormal termination */ if (s < 0) { status = STATUS_MAX_LS_ITER_EXCEEDED; } else /* if (ntiter == MAX_NT_ITER) */ { status = STATUS_MAX_NT_ITER_EXCEEDED; } if (sol != NULL) { /* trim solution */ int i; double lambda_threshold; lambda_threshold = to.ktolerance*lambda; sol[0] = x[0]; for (i = 0; i < n; i++) { sol[i+1] = (fabs(gw[i])>lambda_threshold)? x[i+1] : 0.0; } /* if standardized, sol = coeff/std */ if (to.sflag == TRUE && to.cflag == FALSE) { dmat_elemdivi(n, sol+1, std_x, sol+1); sol[0] -= dmat_dot(n, avg_x, sol+1); } } if (initial_x != NULL) { dmat_vcopy(n+n+1, x, initial_x); *initial_t = t; } if (total_pcgiter) *total_pcgiter = pcgiter; if (total_ntiter ) *total_ntiter = ntiter; /* free memory */ free_variables(&vars); free_temporaries(tm1, tn1, tn2, tn3, tn4, tx1, precond, B, BB); free_problem_data(&prob); #if INTERNAL_PLOT write_mm_matrix("internal_plot",internal_plot,"",TYPE_G); #endif return status; }
static void cmd_put(int argc, char **argv) { struct utoppy_writefile uw; struct utoppy_dirent ud; struct stat st; char dstbuf[FILENAME_MAX]; char *src; void *buf; ssize_t rv; size_t l; int ch, turbo_mode = 0, reput = 0, progbar = 0; FILE *ifp; optind = 1; optreset = 1; while ((ch = getopt(argc, argv, "prt")) != -1) { switch (ch) { case 'p': progbar = 1; break; case 'r': reput = 1; break; case 't': turbo_mode = 1; break; default: put_usage: errx(EX_USAGE, "usage: put [-prt] <local-pathname> " "<toppy-pathname>"); } } argc -= optind; argv += optind; if (argc != 2) goto put_usage; src = argv[0]; uw.uw_path = argv[1]; if (stat(src, &st) < 0) err(EX_OSERR, "%s", src); if (!S_ISREG(st.st_mode)) errx(EX_DATAERR, "'%s' is not a regular file", src); uw.uw_size = st.st_size; uw.uw_mtime = st.st_mtime; uw.uw_offset = 0; if (find_toppy_dirent(uw.uw_path, &ud)) { if (ud.ud_type == UTOPPY_DIRENT_DIRECTORY) { snprintf(dstbuf, sizeof(dstbuf), "%s/%s", uw.uw_path, basename(src)); uw.uw_path = dstbuf; } else if (ud.ud_type != UTOPPY_DIRENT_FILE) errx(EX_DATAERR, "'%s' is not a regular file.", uw.uw_path); else if (reput) { if (ud.ud_size > uw.uw_size) errx(EX_DATAERR, "'%s' is already larger than " "'%s'", uw.uw_path, src); uw.uw_size -= ud.ud_size; uw.uw_offset = ud.ud_size; } } if ((buf = malloc(TOPPY_IO_SIZE)) == NULL) err(EX_OSERR, "malloc(TOPPY_IO_SIZE)"); if ((ifp = fopen(src, "r")) == NULL) err(EX_OSERR, "fopen(%s)", src); if (ioctl(toppy_fd, UTOPPYIOTURBO, &turbo_mode) < 0) err(EX_OSERR, "ioctl(UTOPPYIOTURBO, %d)", turbo_mode); if (ioctl(toppy_fd, UTOPPYIOWRITEFILE, &uw) < 0) err(EX_OSERR, "ioctl(UTOPPYIOWRITEFILE, %s)", uw.uw_path); if (progbar) init_progress(stdout, src, st.st_size, uw.uw_offset); if (progbar) progressmeter(-1); while ((l = fread(buf, 1, TOPPY_IO_SIZE, ifp)) > 0) { rv = write(toppy_fd, buf, l); if ((size_t)rv != l) { fclose(ifp); if (progbar) progressmeter(1); err(EX_OSERR, "write(TOPPY: %s)", uw.uw_path); } bytes += l; } if (progbar) progressmeter(1); if (ferror(ifp)) err(EX_OSERR, "fread(%s)", src); fclose(ifp); free(buf); }
static void cmd_get(int argc, char **argv) { struct utoppy_readfile ur; struct utoppy_dirent ud; struct stat st; char *dst, dstbuf[FILENAME_MAX]; uint8_t *buf; ssize_t l; size_t rv; int ch, turbo_mode = 0, reget = 0, progbar = 0; FILE *ofp, *to; optind = 1; optreset = 1; while ((ch = getopt(argc, argv, "prt")) != -1) { switch (ch) { case 'p': progbar = 1; break; case 'r': reget = 1; break; case 't': turbo_mode = 1; break; default: get_usage: errx(EX_USAGE, "usage: get [-prt] <toppy-pathname> " "[file | directory]"); } } argc -= optind; argv += optind; if (argc == 1) dst = basename(argv[0]); else if (argc == 2) { dst = argv[1]; if (stat(dst, &st) == 0 && S_ISDIR(st.st_mode)) { snprintf(dstbuf, sizeof(dstbuf), "%s/%s", dst, basename(argv[0])); dst = dstbuf; } } else goto get_usage; ur.ur_path = argv[0]; ur.ur_offset = 0; if ((buf = malloc(TOPPY_IO_SIZE)) == NULL) err(EX_OSERR, "malloc(TOPPY_IO_SIZE)"); if (strcmp(dst, "-") == 0) { ofp = stdout; to = stderr; if (reget) warnx("Ignoring -r option in combination with stdout"); } else { to = stdout; if (reget) { if (stat(dst, &st) < 0) { if (errno != ENOENT) err(EX_OSERR, "stat(%s)", dst); } else if (!S_ISREG(st.st_mode)) errx(EX_DATAERR, "-r only works with regular " "files"); else ur.ur_offset = st.st_size; } if ((ofp = fopen(dst, reget ? "a" : "w")) == NULL) err(EX_OSERR, "fopen(%s)", dst); } if (progbar) { if (find_toppy_dirent(ur.ur_path, &ud) == 0) ud.ud_size = 0; init_progress(to, dst, ud.ud_size, ur.ur_offset); } if (ioctl(toppy_fd, UTOPPYIOTURBO, &turbo_mode) < 0) err(EX_OSERR, "ioctl(UTOPPYIOTURBO, %d)", turbo_mode); if (ioctl(toppy_fd, UTOPPYIOREADFILE, &ur) < 0) err(EX_OSERR, "ioctl(UTOPPYIOREADFILE, %s)", ur.ur_path); if (progbar) progressmeter(-1); for (;;) { while ((l = read(toppy_fd, buf, TOPPY_IO_SIZE)) < 0 && errno == EINTR) ; if (l <= 0) break; rv = fwrite(buf, 1, l, ofp); if (rv != (size_t)l) { if (ofp != stdout) fclose(ofp); progressmeter(1); err(EX_OSERR, "fwrite(%s)", dst); } bytes += l; } if (progbar) progressmeter(1); if (ofp != stdout) fclose(ofp); if (l < 0) err(EX_OSERR, "read(TOPPY: ur.ur_path)"); free(buf); }
int terrain_filter( float *data, // input/output: array of data to process (row-major order) double detail, // input: "detail" exponent to be applied int nrows, // input: number of rows in data array int ncols, // input: number of columns in data array double xdim, // input: spacing between pixel columns (in degrees or meters) double ydim, // input: spacing between pixel rows (in degrees or meters) enum Terrain_Coord_Type coord_type, // input: coordinate type for xdim & ydim (degrees or meters) double center_lat, // input: latitude in degrees at center of data array // (ignored if coord_type == TERRAIN_METERS) const struct Terrain_Progress_Callback *progress // optional callback functor for status; NULL for none // enum Terrain_Reg registration // feature not yet implemented ) // Computes operator (-Laplacian)^(detail/2) applied to data array. // Returns 0 on success, nonzero if an error occurred (see enum Terrain_Filter_Errors). // Mean of data array is always (approximately) zero on output. // On input, vertical units (data array values) should be in meters. { enum Terrain_Reg registration = TERRAIN_REG_CELL; int num_threads = 1; // number of threads used to parallelize the three DCT loops // approximate relative amount of time spent in each step // (actual times vary with data array size, memory size, and DCT algorithms chosen): const float step_times[6] = { 0.5, 2.0/num_threads, 1.0, 4.0/num_threads, 1.0, 2.0/num_threads }; const int total_steps = sizeof( step_times ) / sizeof( *step_times ); struct Terrain_Progress_Info progress_info = init_progress( progress, step_times, total_steps ); struct Transpose_Progress_Callback sub_progress = { relay_progress, &progress_info }; const double steepness = 2.0; int error; int type_fwd, type_bwd; int i, j; float *ptr; float data_min, data_max; double normalizer; double xres, yres; double xscale, yscale; double xsize, ysize; struct Terrain_Operator_Info info; // Determine pixel dimensions: if (coord_type == TERRAIN_DEGREES) { geographic_scale( center_lat, &xsize, &ysize ); // convert degrees to meters (approximately) xres = xdim * xsize; yres = ydim * ysize; } else { xres = xdim; yres = ydim; } xscale = fabs( 1.0 / xres ); yscale = fabs( 1.0 / yres ); switch (registration) { case TERRAIN_REG_GRID: type_fwd = 1; type_bwd = 1; break; case TERRAIN_REG_CELL: type_fwd = 2; type_bwd = 3; break; default: return TERRAIN_FILTER_INVALID_PARAM; } if (progress && report_progress( &progress_info )) { return TERRAIN_FILTER_CANCELED; } data_min = data[0]; data_max = data[0]; for (i=0, ptr=data; i<nrows; ++i, ptr+=ncols) { //float *ptr = data + (LONG)i * (LONG)ncols; for (j=0; j<ncols; ++j) { if (ptr[j] < data_min) { data_min = ptr[j]; } else if (ptr[j] > data_max) { data_max = ptr[j]; } } } normalizer = pow( 2.0 / (data_max - data_min), 1.0 - detail ); normalizer *= pow( steepness, -detail ); for (i=0, ptr=data; i<nrows; ++i, ptr+=ncols) { //float *ptr = data + (LONG)i * (LONG)ncols; for (j=0; j<ncols; ++j) { ptr[j] *= normalizer; } } error = setup_operator( detail, ncols, nrows, xscale, yscale, registration, &info ); if (error) { return error; } set_progress( &progress_info, 1 ); if (progress && report_progress( &progress_info )) { return TERRAIN_FILTER_CANCELED; } // CONCURRENCY NOTE: The iterations of the loop below will be // independent and can be executed in parallel, if each thread has // its own dct_plan with separate calls to setup_dcts() and cleanup_dcts(). { struct Dct_Plan dct_plan = setup_dcts( type_fwd, ncols ); if (!dct_plan.dct_buffer) { return TERRAIN_FILTER_MALLOC_ERROR; } for (i=0; i<nrows-1; i+=2) { float *ptr = data + (LONG)i * (LONG)ncols; two_dcts( ptr, ncols, &dct_plan ); if (progress && update_progress( &progress_info, i+2, nrows )) { return TERRAIN_FILTER_CANCELED; } } if (nrows & 1) { float *ptr = data + (LONG)(nrows - 1) * (LONG)ncols; single_dct( ptr, ncols, &dct_plan ); } cleanup_dcts( &dct_plan ); } set_progress( &progress_info, 2 ); if (progress && report_progress( &progress_info )) { return TERRAIN_FILTER_CANCELED; } error = transpose_inplace( data, nrows, ncols, progress ? &sub_progress : NULL ); if (error) { if (error > 0) { return TERRAIN_FILTER_MALLOC_ERROR; } else { return TERRAIN_FILTER_CANCELED; } } set_progress( &progress_info, 3 ); if (progress && report_progress( &progress_info )) { return TERRAIN_FILTER_CANCELED; } // CONCURRENCY NOTE: The iterations of the loop below will be // independent and can be executed in parallel, if each thread has // its own fwd_plan and bwd_plan with separate calls to setup_dcts() // and cleanup_dcts(). { struct Dct_Plan fwd_plan = setup_dcts( type_fwd, nrows ); struct Dct_Plan bwd_plan = setup_dcts( type_bwd, nrows ); if (!fwd_plan.dct_buffer || !bwd_plan.dct_buffer) { return TERRAIN_FILTER_MALLOC_ERROR; } for (i=0; i<ncols-1; i+=2) { float *ptr = data + (LONG)i * (LONG)nrows; two_dcts( ptr, nrows, &fwd_plan ); apply_operator( data, i, nrows, info ); apply_operator( data, i+1, nrows, info ); two_dcts( ptr, nrows, &bwd_plan ); if (progress && update_progress( &progress_info, i+2, ncols )) { return TERRAIN_FILTER_CANCELED; } } if (ncols & 1) { float *ptr = data + (LONG)(ncols - 1) * (LONG)nrows; single_dct( ptr, nrows, &fwd_plan ); apply_operator( data, ncols-1, nrows, info ); single_dct( ptr, nrows, &bwd_plan ); } cleanup_dcts( &bwd_plan ); cleanup_dcts( &fwd_plan ); } if (flt_isnan( data[0] )) { return TERRAIN_FILTER_NULL_VALUES; } set_progress( &progress_info, 4 ); if (progress && report_progress( &progress_info )) { return TERRAIN_FILTER_CANCELED; } error = transpose_inplace( data, ncols, nrows, progress ? &sub_progress : NULL ); if (error) { if (error > 0) { return TERRAIN_FILTER_MALLOC_ERROR; } else { return TERRAIN_FILTER_CANCELED; } } set_progress( &progress_info, 5 ); if (progress && report_progress( &progress_info )) { return TERRAIN_FILTER_CANCELED; } // CONCURRENCY NOTE: The iterations of the loop below will be // independent and can be executed in parallel, if each thread has // its own dct_plan with separate calls to setup_dcts() and cleanup_dcts(). { struct Dct_Plan dct_plan = setup_dcts( type_bwd, ncols ); if (!dct_plan.dct_buffer) { return TERRAIN_FILTER_MALLOC_ERROR; } for (i=0; i<nrows-1; i+=2) { float *ptr = data + (LONG)i * (LONG)ncols; two_dcts( ptr, ncols, &dct_plan ); if (progress && update_progress( &progress_info, i+2, nrows )) { return TERRAIN_FILTER_CANCELED; } } if (nrows & 1) { float *ptr = data + (LONG)(nrows - 1) * (LONG)ncols; single_dct( ptr, ncols, &dct_plan ); } cleanup_dcts( &dct_plan ); } cleanup_operator( info ); set_progress( &progress_info, 6 ); if (progress) { // report final progress; ignore any cancel request at this point report_progress( &progress_info ); } return TERRAIN_FILTER_SUCCESS; }
int state_save(int slot) { SceUID fd = -1; pspTime nowtime; char path[MAX_PATH]; char error_mes[128]; char buf[128]; #if (EMU_SYSTEM == NCDZ) UINT8 *inbuf, *outbuf; unsigned long insize, outsize; #else #ifndef ADHOC UINT8 *state_buffer_base; #endif UINT32 size; #endif sprintf(path, "%sstate/%s.sv%d", launchDir, game_name, slot); sceIoRemove(path); sprintf(buf, TEXT(STATE_SAVING), game_name, slot); init_progress(6, buf); sceRtcGetCurrentClockLocalTime(&nowtime); if ((fd = sceIoOpen(path, PSP_O_WRONLY|PSP_O_CREAT, 0777)) >= 0) #if (EMU_SYSTEM == NCDZ) { if ((inbuf = memalign(MEM_ALIGN, STATE_BUFFER_SIZE)) == NULL) { strcpy(error_mes, TEXT(COULD_NOT_ALLOCATE_STATE_BUFFER)); goto error; } memset(inbuf, 0, STATE_BUFFER_SIZE); state_buffer = inbuf; state_save_byte(current_version_str, 8); state_save_byte(&nowtime, 16); update_progress(); save_thumbnail(); update_progress(); sceIoWrite(fd, inbuf, (UINT32)state_buffer - (UINT32)inbuf); update_progress(); memset(inbuf, 0, STATE_BUFFER_SIZE); state_buffer = inbuf; state_save_memory(); state_save_m68000(); state_save_z80(); state_save_input(); state_save_timer(); state_save_driver(); state_save_video(); state_save_ym2610(); state_save_cdda(); state_save_cdrom(); update_progress(); insize = (UINT32)state_buffer - (UINT32)inbuf; outsize = insize * 1.1 + 12; if ((outbuf = memalign(MEM_ALIGN, outsize)) == NULL) { strcpy(error_mes, TEXT(COULD_NOT_ALLOCATE_STATE_BUFFER)); free(inbuf); goto error; } memset(outbuf, 0, outsize); if (compress(outbuf, &outsize, inbuf, insize) != Z_OK) { strcpy(error_mes, TEXT(COULD_NOT_COMPRESS_STATE_DATA)); free(inbuf); free(outbuf); goto error; } free(inbuf); update_progress(); sceIoWrite(fd, &outsize, 4); sceIoWrite(fd, outbuf, outsize); sceIoClose(fd); free(outbuf); update_progress(); show_progress(buf); return 1; } #else { #ifdef ADHOC state_buffer = state_buffer_base; #else #if (EMU_SYSTEM == CPS1 || (EMU_SYSTEM == CPS2 && defined(PSP_SLIM))) state_buffer = state_buffer_base = memalign(MEM_ALIGN, STATE_BUFFER_SIZE); #else state_buffer = state_buffer_base = cache_alloc_state_buffer(STATE_BUFFER_SIZE); #endif if (!state_buffer) { strcpy(error_mes, TEXT(COULD_NOT_ALLOCATE_STATE_BUFFER)); goto error; } #endif memset(state_buffer, 0, STATE_BUFFER_SIZE); update_progress(); state_save_byte(current_version_str, 8); state_save_byte(&nowtime, 16); update_progress(); save_thumbnail(); update_progress(); state_save_memory(); state_save_m68000(); state_save_z80(); state_save_input(); state_save_timer(); state_save_driver(); state_save_video(); #if (EMU_SYSTEM == CPS1) state_save_coin(); switch (machine_driver_type) { case MACHINE_qsound: state_save_qsound(); state_save_eeprom(); break; case MACHINE_pang3: state_save_eeprom(); default: state_save_ym2151(); break; } #elif (EMU_SYSTEM == CPS2) state_save_coin(); state_save_qsound(); state_save_eeprom(); #elif (EMU_SYSTEM == MVS) state_save_ym2610(); state_save_pd4990a(); #endif update_progress(); size = (UINT32)state_buffer - (UINT32)state_buffer_base; sceIoWrite(fd, state_buffer_base, size); sceIoClose(fd); update_progress(); #ifndef ADHOC #if (EMU_SYSTEM == CPS1 || (EMU_SYSTEM == CPS2 && defined(PSP_SLIM))) free(state_buffer_base); #else cache_free_state_buffer(STATE_BUFFER_SIZE); #endif #endif update_progress(); show_progress(buf); return 1; } #endif else {
void *recv_thrd(void *arg) /* server for client */ { int sock_fd, index; int rec_bytes, left; Client *cli_ptr = NULL; char *ptr = NULL; char filename[128], res[128]; int total_bytes; FILE *fp = NULL; cli_ptr = (Client *)arg; sock_fd = cli_ptr->con_fd; printf("thread nick: %s\nthread fd: %d\n", cli_ptr->nick, cli_ptr->con_fd); while ((rec_bytes = recv(sock_fd, buf, sizeof(buf), 0)) > 0) { ptr = strstr(buf, "\r\n\r\n"); index = ptr - buf; strncpy(res, buf, index); res[index] = '\0'; get_filename(res, filename); total_bytes = get_file_length(res); printf("please enter the folder to save \"%s\" (eg:\"./to/\"):", filename); //scanf("%s", res); printf("服务器默认存放在: \"./to/\" 下\r\n"); strcpy(res, "./to/"); index = strlen(res); if (res[index - 1] != '/') { strcat(res, "/"); } else { strcat(res, filename); } if ((fp = fopen(filename, "r")) != NULL) { puts("error, file exist!"); fclose(fp); return NULL; } printf("filename = %s\r\n", filename); fp = fopen(filename, "a+"); left = rec_bytes - (ptr - buf + 4); fwrite(ptr + 4, left, 1, fp); fflush(fp); fclose(fp); total_bytes -= left; /* initial progress bar */ init_progress(&bar, total_bytes + left); update_progress(&bar, left); display_image(&bar); save_file(sock_fd, filename, total_bytes); printf("file %s saved, bytes = %d\r\n", filename, total_bytes + left); } close(sock_fd); remove_client(sock_fd); printf("a client(%d) quit!\n", cli_ptr->con_fd); pthread_exit(NULL); }