IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 21329


Ignore:
Timestamp:
Feb 5, 2009, 10:52:05 AM (17 years ago)
Author:
eugene
Message:

modified test to test image subsets

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20090203/psphot/src/psphotTest.c

    r12792 r21329  
    11# include "psphotInternal.h"
    22
    3 void psExit (int status, char *process, char *format, ...) {
     3bool FillImage_Threaded (psThreadJob *job);
    44
    5     va_list ap;
     5bool SetThreads () {
    66
    7     va_start (ap, format);
    8     fprintf (stderr, "exiting %s\n", process);
    9     vfprintf (stderr, format, ap);
    10     va_end (ap);
     7    psThreadTask *task = NULL;
    118
    12     exit (status);
     9    task = psThreadTaskAlloc("FILL_IMAGE", 6);
     10    task->function = &FillImage_Threaded;
     11    psThreadTaskAdd(task);
     12    psFree(task);
     13
     14    return true;
     15}
     16
     17bool FillImage (psImage *image, int xs, int ys, int dx, int dy, int value) {
     18
     19    psRegion region = psRegionSet (xs, xs + dx, ys, ys + dy);
     20    psImage *subset = psImageSubset (image, region);
     21    psImageInit (subset, value);
     22    psFree (subset);
     23    return true;
     24}
     25
     26bool FillImage_Threaded (psThreadJob *job) {
     27   
     28    psImage *image = job->args->data[0];
     29    int xs = PS_SCALAR_VALUE(job->args->data[1],S32);
     30    int ys = PS_SCALAR_VALUE(job->args->data[2],S32);
     31    int dx = PS_SCALAR_VALUE(job->args->data[3],S32);
     32    int dy = PS_SCALAR_VALUE(job->args->data[4],S32);
     33    int value = PS_SCALAR_VALUE(job->args->data[5],S32);
     34
     35    // we want the threads to be likely to interact.  run lots of psImageSubsets
     36    psRegion region = psRegionSet (xs, xs + dx, ys, ys + dy);
     37    for (int i = 0; i < 100; i++) {
     38        psImage *subset = psImageSubset (image, region);
     39        psImageInit (subset, value + i);
     40        psFree (subset);
     41    }
     42    return true;
    1343}
    1444
    1545int main (int argc, char **argv) {
     46
     47    if (argc != 3) {
     48        fprintf (stderr, "USAGE: psphotTest (output.fits) (nThreads)\n");
     49        exit (2);
     50    }
     51
     52    psTraceSetLevel ("psLib.sys.mutex", 3);
     53
     54    int nThreads = atoi (argv[2]);
     55
     56    // create the thread pool with number of desired threads, supplying our thread launcher function
     57    psThreadPoolInit (nThreads);
     58
     59    SetThreads();
     60
     61    psImage *image = psImageAlloc (1000, 1000, PS_TYPE_S32);
     62
     63    for (int ix = 0; ix < 1000; ix += 100) {
     64        for (int iy = 0; iy < 1000; iy += 100) {
     65
     66            // allocate a job -- if threads are not defined, this just runs the job
     67            psThreadJob *job = psThreadJobAlloc ("FILL_IMAGE");
     68
     69            psArrayAdd(job->args, 1, image);
     70            PS_ARRAY_ADD_SCALAR(job->args, ix, PS_TYPE_S32);
     71            PS_ARRAY_ADD_SCALAR(job->args, iy, PS_TYPE_S32);
     72            PS_ARRAY_ADD_SCALAR(job->args, 100, PS_TYPE_S32);
     73            PS_ARRAY_ADD_SCALAR(job->args, 100, PS_TYPE_S32);
     74            PS_ARRAY_ADD_SCALAR(job->args, ix + iy, PS_TYPE_S32);
     75
     76            // FillImage (image, ix, iy, 100, 100, ix + iy);
     77
     78            if (!psThreadJobAddPending(job)) {
     79                fprintf (stderr, "failure to run FillImage(1)");
     80                psFree (job);
     81                exit (1);
     82            }
     83            psFree(job);
     84        }
     85    }
     86
     87
     88    // wait for the threads to finish and manage results
     89    if (!psThreadPoolWait (true)) {
     90        fprintf (stderr, "failure to run FillImage (2)");
     91        exit (1);
     92    }
     93
     94    psFits *fits = psFitsOpen (argv[1], "w");
     95    psFitsWriteImage (fits, NULL, image, 0, NULL);
     96    psFitsClose (fits);
     97
     98    psThreadPoolFinalize ();
     99    psFree(image);
     100
     101    fprintf (stderr, "found %d leaks\n", psMemCheckLeaks (0, NULL, stdout, false));
     102    exit (0);
     103}
     104
     105# if (0)
    16106
    17107    psRegion region = {0,0,0,0};        // a region representing the entire array
     
    39129    psFree (header);
    40130    psFree (image);
    41     exit (0);
    42 }
    43131
     132# endif
    44133
    45134# if (0)
     
    82171
    83172# endif
     173
     174# if (0)
     175
     176void psExit (int status, char *process, char *format, ...) {
     177
     178    va_list ap;
     179
     180    va_start (ap, format);
     181    fprintf (stderr, "exiting %s\n", process);
     182    vfprintf (stderr, format, ap);
     183    va_end (ap);
     184
     185    exit (status);
     186}
     187
     188# endif
Note: See TracChangeset for help on using the changeset viewer.