Updating CVS with partially ported benchmark. Sequencer.java's run() function is...
[IRC.git] / Robust / src / Benchmarks / SingleTM / genome / java / Genome.java~
1 /*
2 "gene.h"
3 "random.h"
4 "segments.h"
5 "sequencer.h"
6 "thread.h"
7 "timer.h"
8 "tm.h"
9 "vector.h"
10 "bitmap.h"
11
12 */
13
14 public class Genome {
15   long geneLength;
16   long segmentLength;
17   long minNumSegment;
18   long numThread;
19   
20   Genome(String x[]) {
21     parseCmdLine(x);
22   }
23   
24   public static void main(String x[]){
25     
26 /*    TIMER_T start; */
27 /*    TIMER_T stop; */
28
29 /*    GOTO_REAL(); */
30
31     /* Initialization */
32 /*    parseArgs(argc, (char** const)argv); */
33 /*    SIM_GET_NUM_CPU(global_params[PARAM_THREAD]); */
34
35     System.out.print("Creating gene and segments... ");
36     Genome g = new Genome(x);
37
38
39 /*    TM_STARTUP(numThread); */
40 /*    P_MEMORY_STARTUP(numThread); */
41 /*    thread_startup(numThread); */
42
43     Random randomPtr = new Random();
44     random_alloc(randomPtr);
45     random_seed(randomPtr, 0);
46
47     Gene genePtr = new Gene(geneLength);
48     genePtr.create(randomPtr);
49     String gene = genePtr.contents;
50
51     Segments segmentsPtr = new Segments(segmentLength, minNumSegment);
52     assert(segmentsPtr != NULL);
53     segments_create(segmentsPtr, genePtr, randomPtr);
54     sequencer_t* sequencerPtr = sequencer_alloc(geneLength, segmentLength, segmentsPtr);
55     assert(sequencerPtr != NULL);
56
57     puts("done.");
58     printf("Gene length     = %li\n", genePtr->length);
59     printf("Segment length  = %li\n", segmentsPtr->length);
60     printf("Number segments = %li\n", vector_getSize(segmentsPtr->contentsPtr));
61     fflush(stdout);
62
63     /* Benchmark */
64     printf("Sequencing gene... ");
65     fflush(stdout);
66     TIMER_READ(start);
67     GOTO_SIM();
68 #ifdef OTM
69 #pragma omp parallel
70     {
71         sequencer_run(sequencerPtr);
72     }
73 #else
74     thread_start(sequencer_run, (void*)sequencerPtr);
75 #endif
76     GOTO_REAL();
77     TIMER_READ(stop);
78     puts("done.");
79     printf("Time = %lf\n", TIMER_DIFF_SECONDS(start, stop));
80     fflush(stdout);
81
82     /* Check result */
83     {
84         char* sequence = sequencerPtr->sequence;
85         int result = strcmp(gene, sequence);
86         printf("Sequence matches gene: %s\n", (result ? "no" : "yes"));
87         if (result) {
88             printf("gene     = %s\n", gene);
89             printf("sequence = %s\n", sequence);
90         }
91         fflush(stdout);
92         assert(strlen(sequence) >= strlen(gene));
93     }
94
95     /* Clean up */
96     printf("Deallocating memory... ");
97     fflush(stdout);
98     sequencer_free(sequencerPtr);
99     segments_free(segmentsPtr);
100     gene_free(genePtr);
101     random_free(randomPtr);
102     puts("done.");
103     fflush(stdout);
104
105     TM_SHUTDOWN();
106     P_MEMORY_SHUTDOWN();
107
108     GOTO_SIM();
109
110     thread_shutdown();
111
112     MAIN_RETURN(0);
113   }
114   
115   public static void parseCmdLine(String args[]) {
116
117     int i = 0;
118     String arg;
119     while (i < args.length && args[i].startsWith("-")) {
120       arg = args[i++];
121       //check options
122       if(arg.equals("-g")) {
123         if(i < args.length) {
124           geneLength = new Integer(args[i++]).intValue();
125         }
126       } else if(arg.equals("-s")) {
127         if(i < args.length) {
128           segmentLength = new Integer(args[i++]).intValue();
129         }
130       } else if(arg.equals("-n")) {
131         if(i < args.length) {
132           minNumSegment = new Integer(args[i++]).intValue();
133         }
134       } else if(arg.equals("-t")) {
135         if(i < args.length) {
136           numThread = new Integer(args[i++]).intValue();
137         }
138       } 
139     }
140   }
141 }
142
143 public enum param_types {
144     PARAM_GENE    /*= (unsigned char)'g'*/,
145     PARAM_NUMBER  /*= (unsigned char)'n'*/,
146     PARAM_SEGMENT /*= (unsigned char)'s'*/,
147     PARAM_THREAD  /*= (unsigned char)'t',*/
148 }