|
| 1 | +/* tab:8 |
| 2 | + * |
| 3 | + * ImageU.h - Image Understanding Project |
| 4 | + * |
| 5 | + * |
| 6 | + * "Copyright (c) 1994,1995 The Regents of the University of Maryland. |
| 7 | + * All rights reserved. |
| 8 | + * |
| 9 | + * Permission to use, copy, modify, and distribute this software and its |
| 10 | + * documentation for any purpose, without fee, and without written agreement is |
| 11 | + * hereby granted, provided that the above copyright notice and the following |
| 12 | + * two paragraphs appear in all copies of this software. |
| 13 | + * |
| 14 | + * IN NO EVENT SHALL THE UNIVERSITY OF MARYLAND BE LIABLE TO ANY PARTY FOR |
| 15 | + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT |
| 16 | + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF |
| 17 | + * MARYLAND HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 18 | + * |
| 19 | + * THE UNIVERSITY OF MARYLAND SPECIFICALLY DISCLAIMS ANY WARRANTIES, |
| 20 | + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
| 21 | + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
| 22 | + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF MARYLAND HAS NO OBLIGATION TO |
| 23 | + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." |
| 24 | + * |
| 25 | + * Authors: David A. Bader <dbader@umiacs.umd.edu> |
| 26 | + * Joseph F. Ja'Ja' <joseph@umiacs.umd.edu> |
| 27 | + * Institute for Advanced Computer Studies |
| 28 | + * Department of Electrical Engineering |
| 29 | + * AV Williams Building |
| 30 | + * College Park, MD 20742 |
| 31 | + * |
| 32 | + * Version: 2 |
| 33 | + * Creation Date: October 20, 1994 |
| 34 | + * Filename: ImageU.h |
| 35 | + * History: |
| 36 | + * DAB 2 Sun Dec 4 14:31:30 EST 1994 |
| 37 | + * Added in DO_CCGRYL |
| 38 | + */ |
| 39 | + |
| 40 | +#ifndef _IMAGEU_H |
| 41 | +#define _IMAGEU_H |
| 42 | + |
| 43 | +#include <stdio.h> |
| 44 | +#include <stdlib.h> |
| 45 | +#include <math.h> |
| 46 | +#include <time.h> |
| 47 | +#include <string.h> |
| 48 | +#include <split-c/split-c.h> |
| 49 | + |
| 50 | +#define VER_MAJOR 3 |
| 51 | +#define VER_MINOR 6 |
| 52 | + |
| 53 | +#define _INLINE extern inline |
| 54 | + |
| 55 | +#if (defined (SP1) || defined (SP2)) |
| 56 | +#define malloc(size) sc_malloc_wrapper(size) |
| 57 | +#define free(ptr) sc_free_wrapper(ptr) |
| 58 | +#define realloc(ptr, size) sc_realloc_wrapper(ptr, size) |
| 59 | +#endif |
| 60 | + |
| 61 | +#if (!defined (CM5)) |
| 62 | +#define log2(d) (log(d) / log(2.0)) |
| 63 | +#endif |
| 64 | + |
| 65 | +#ifndef min |
| 66 | +#define min(a,b) ((a)<(b)?(a):(b)) |
| 67 | +#endif |
| 68 | +#ifndef max |
| 69 | +#define max(a,b) ((a)>(b)?(a):(b)) |
| 70 | +#endif |
| 71 | +#ifndef CAT |
| 72 | +#define CAT(a,b) a##b |
| 73 | +#endif |
| 74 | + |
| 75 | +#include "image_print.h" |
| 76 | + |
| 77 | +#define DARPA_IMAGE "IUbench.im" |
| 78 | + |
| 79 | +#define errprnt(msg) { fprintf(stderr,"connComp: %s\n",msg); exit(1); } |
| 80 | + |
| 81 | +#define IMAGE_DEFAULT 1 |
| 82 | + |
| 83 | +#define N_DEFAULT 32 |
| 84 | +#define K_DEFAULT 2 |
| 85 | + |
| 86 | +#define BARSIZE_DEFAULT 5 |
| 87 | + |
| 88 | +#define WATCH_PROC_DEFAULT 32 |
| 89 | + |
| 90 | +FILE *outfile; |
| 91 | + |
| 92 | +int watch_proc, /* Processor to debug */ |
| 93 | + OUTPUT_IMAGE, /* Output Image Status Bits */ |
| 94 | + UNSUPPARAM, /* Parameter for all_unsupported */ |
| 95 | + DO_TEST, /* Test machine specifics */ |
| 96 | + DO_UNSUP, /* Unsupported testing routines */ |
| 97 | + DO_HISTO, /* Do a histogram? */ |
| 98 | + DO_CCBIN, /* Do a binary 8-connected component? */ |
| 99 | + DO_CCBIF, /* Do a binary 4-connected component? */ |
| 100 | + DO_CCGRY, /* Do a grey-level 8-connected component? */ |
| 101 | + DO_CCGRF, /* Do a grey-level 4-connected component? */ |
| 102 | + DO_CCGRYL, /* Do a l-grey-level 8-connected component? */ |
| 103 | + DO_SEGM, /* Do Image Segmentation */ |
| 104 | + DO_GBLUR, /* Do Blur of image */ |
| 105 | + DO_BENCHMARK, /* Perform the benchmark suite? */ |
| 106 | + RESULTS; /* Print verbose results? */ |
| 107 | + |
| 108 | +#define MAXLEN 80 |
| 109 | + |
| 110 | +#define MAX_TIMER 256 |
| 111 | + |
| 112 | +double timer[MAX_TIMER]; |
| 113 | +int timer_cnt; |
| 114 | +char timer_msg[MAX_TIMER][MAXLEN]; |
| 115 | + |
| 116 | +_INLINE void all_init_timer() { |
| 117 | + barrier(); |
| 118 | + timer_cnt = 0; |
| 119 | +} |
| 120 | + |
| 121 | +_INLINE void all_start_timer() { |
| 122 | + barrier(); |
| 123 | + if (timer_cnt >= MAX_TIMER) { |
| 124 | + fprintf(stderr,"ERROR: Ran out of timers.\n"); |
| 125 | + exit(1); |
| 126 | + } |
| 127 | + timer[timer_cnt] = get_seconds(); |
| 128 | +} |
| 129 | + |
| 130 | +_INLINE void all_stop_timer(char* msg) { |
| 131 | + barrier(); |
| 132 | + timer[timer_cnt] = get_seconds() - timer[timer_cnt]; |
| 133 | + strcpy(timer_msg[timer_cnt], msg); |
| 134 | + timer_cnt++; |
| 135 | +} |
| 136 | + |
| 137 | +_INLINE void all_print_timer(FILE* strm) { |
| 138 | + register int i; |
| 139 | + |
| 140 | + on_one{ |
| 141 | + fprintf(strm,"\n"); |
| 142 | + fprintf(strm,"Timers:\n"); |
| 143 | + for (i=0 ; i<timer_cnt ; i++) |
| 144 | + fprintf(strm,"%9.6f for %s\n",timer[i],timer_msg[i]); |
| 145 | + fprintf(strm,"\n"); |
| 146 | + } |
| 147 | +} |
| 148 | + |
| 149 | +_INLINE void all_print_timer_PS(FILE* strm) { |
| 150 | + register int i; |
| 151 | + |
| 152 | + on_one{ |
| 153 | + fprintf(strm,"\n"); |
| 154 | + fprintf(strm,"Prefix-Sums of Timers:\n"); |
| 155 | + for (i=1 ; i<timer_cnt ; i++) |
| 156 | + timer[i] += timer[i-1]; |
| 157 | + for (i=0 ; i<timer_cnt ; i++) |
| 158 | + fprintf(strm,"%9.6f for %s\n",timer[i],timer_msg[i]); |
| 159 | + fprintf(strm,"\n"); |
| 160 | + } |
| 161 | +} |
| 162 | + |
| 163 | +_INLINE int mapRow(int rowsGrid, int colsGrid, int proc_id) { |
| 164 | +/* Return the row of processor proc_id in a rowsGrid x colsGrid |
| 165 | + processor 2d array */ |
| 166 | + return(proc_id / colsGrid); |
| 167 | +} |
| 168 | + |
| 169 | +_INLINE int mapCol(int rowsGrid, int colsGrid, int proc_id) { |
| 170 | +/* Return the column of processor proc_id in a rowsGrid x colsGrid |
| 171 | + processor 2d array */ |
| 172 | + return(proc_id % colsGrid); |
| 173 | +} |
| 174 | + |
| 175 | +_INLINE int mapProc(int rowsGrid, int colsGrid, int aRow, int aCol) { |
| 176 | +/* Return the proc_id of the processor in a rowsGrid x colsGrid |
| 177 | + processor 2d array at location (aRow, aCol) */ |
| 178 | + return(aRow * colsGrid + aCol); |
| 179 | +} |
| 180 | + |
| 181 | +_INLINE void assert_spread_malloc(void *spread spreadPtr) |
| 182 | +/* Check spreadPtr to make sure it is not NULL */ |
| 183 | +{ |
| 184 | + if (spreadPtr == NULL) { |
| 185 | + fprintf(stderr,"ERROR: a SpreadPtr is NULL\n"); |
| 186 | + fflush(stderr); |
| 187 | + exit(1); |
| 188 | + } |
| 189 | +} |
| 190 | + |
| 191 | +_INLINE void assert_malloc(void *ptr) { |
| 192 | + if (ptr==NULL) { |
| 193 | + fprintf(stderr,"ERROR: PE%2d cannot malloc\n",MYPROC); |
| 194 | + fflush(stderr); |
| 195 | + exit(1); |
| 196 | + } |
| 197 | +} |
| 198 | + |
| 199 | +#define MODPROCS(a) ((a) & (PROCS-1)) |
| 200 | +#define DIVPROCS(a) ((a) >> PROCSLOG) |
| 201 | + |
| 202 | +#define WHITE 0 |
| 203 | +#define BLACK 1 |
| 204 | + |
| 205 | +#define NIL -1 |
| 206 | + |
| 207 | +typedef struct edge |
| 208 | +{ |
| 209 | + int a; |
| 210 | + int b; |
| 211 | +} edge_t; |
| 212 | + |
| 213 | +typedef struct elem *ELEMPTR; |
| 214 | + |
| 215 | +typedef struct elem |
| 216 | +{ |
| 217 | + int color; |
| 218 | + int label; |
| 219 | + int pos; |
| 220 | +} elem_t; |
| 221 | + |
| 222 | +typedef struct chPair *CHPAIRPTR; |
| 223 | + |
| 224 | +typedef struct chPair |
| 225 | +{ |
| 226 | + int alpha; |
| 227 | + int beta; |
| 228 | +} chPair_t; |
| 229 | + |
| 230 | +void all_get_image(int v, int w, int q, int r, |
| 231 | + int X[v][w]::[q][r], int k, int); |
| 232 | + |
| 233 | +void all_get_image_file(int v, int w, int q, int r, |
| 234 | + int X[v][w]::[q][r], char*); |
| 235 | + |
| 236 | +#endif |
0 commit comments