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     segmentsPtr.create(genePtr, randomPtr);
53     sequencer_t* sequencerPtr = sequencer_alloc(geneLength, segmentLength, segmentsPtr);
54     assert(sequencerPtr != NULL);
55
56     puts("done.");
57     printf("Gene length     = %li\n", genePtr->length);
58     printf("Segment length  = %li\n", segmentsPtr->length);
59     printf("Number segments = %li\n", vector_getSize(segmentsPtr->contentsPtr));
60     fflush(stdout);
61
62     /* Benchmark */
63     printf("Sequencing gene... ");
64     fflush(stdout);
65     TIMER_READ(start);
66     GOTO_SIM();
67 #ifdef OTM
68 #pragma omp parallel
69     {
70         sequencer_run(sequencerPtr);
71     }
72 #else
73     thread_start(sequencer_run, (void*)sequencerPtr);
74 #endif
75     GOTO_REAL();
76     TIMER_READ(stop);
77     puts("done.");
78     printf("Time = %lf\n", TIMER_DIFF_SECONDS(start, stop));
79     fflush(stdout);
80
81     /* Check result */
82     {
83         char* sequence = sequencerPtr->sequence;
84         int result = strcmp(gene, sequence);
85         printf("Sequence matches gene: %s\n", (result ? "no" : "yes"));
86         if (result) {
87             printf("gene     = %s\n", gene);
88             printf("sequence = %s\n", sequence);
89         }
90         fflush(stdout);
91         assert(strlen(sequence) >= strlen(gene));
92     }
93
94     /* Clean up */
95     printf("Deallocating memory... ");
96     fflush(stdout);
97     sequencer_free(sequencerPtr);
98     segments_free(segmentsPtr);
99     gene_free(genePtr);
100     random_free(randomPtr);
101     puts("done.");
102     fflush(stdout);
103
104     TM_SHUTDOWN();
105     P_MEMORY_SHUTDOWN();
106
107     GOTO_SIM();
108
109     thread_shutdown();
110
111     MAIN_RETURN(0);
112   }
113   
114   public static void parseCmdLine(String args[]) {
115
116     int i = 0;
117     String arg;
118     while (i < args.length && args[i].startsWith("-")) {
119       arg = args[i++];
120       //check options
121       if(arg.equals("-g")) {
122         if(i < args.length) {
123           geneLength = new Integer(args[i++]).intValue();
124         }
125       } else if(arg.equals("-s")) {
126         if(i < args.length) {
127           segmentLength = new Integer(args[i++]).intValue();
128         }
129       } else if(arg.equals("-n")) {
130         if(i < args.length) {
131           minNumSegment = new Integer(args[i++]).intValue();
132         }
133       } else if(arg.equals("-t")) {
134         if(i < args.length) {
135           numThread = new Integer(args[i++]).intValue();
136         }
137       } 
138     }
139   }
140 }
141
142 public enum param_types {
143     PARAM_GENE    /*= (unsigned char)'g'*/,
144     PARAM_NUMBER  /*= (unsigned char)'n'*/,
145     PARAM_SEGMENT /*= (unsigned char)'s'*/,
146     PARAM_THREAD  /*= (unsigned char)'t',*/
147 }