-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_FPTAS.cpp
667 lines (601 loc) · 20.7 KB
/
main_FPTAS.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
/*Copyright 2013 Brown University, Providence, RI.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose other than its incorporation into a
commercial product is hereby granted without fee, provided that the
above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation, and that the name of Brown University not be used in
advertising or publicity pertaining to distribution of the software
without specific, written prior permission.
BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ANY
PARTICULAR PURPOSE. IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR
ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "table.h"
#include "FPTAS.cpp"
#include "logrank_exact.h"
#include "MC_logrank.h"
#include <string.h>
#include <pthread.h>
#define min(a,b) a<=b?a:b
using namespace std;
typedef struct {
vector<int> *x ;
vector<int> *c ;
double *e;
double *p_value;
matrix_sim *v;
matrix_sim *p;
} pt_data;
//survival times vector
vector<float> survival_times;
//number of iterations for MC estimate
unsigned long long number_iter = 100000;
void *FPTAS1(void* t) {
pt_data *data1 = (pt_data *)t;
FPTAS( *(data1->x), *(data1->c), *(data1->e), *(data1->p_value), *(data1->v), *(data1->p) );
}
void *FPTAS2(void* t) {
pt_data *data1 = (pt_data *)t;
FPTAS_secondSide( *(data1->x), *(data1->c), *(data1->e), *(data1->p_value), *(data1->v), *(data1->p) );
}
//function used to derive permutation sorting for survival times
bool compare_surv_times(float a, float b) {
return (survival_times[a] < survival_times[b]);
}
//RcppExport SEXP R_FPTAS(SEXP table_file, SEXP gene) {
int main (int argc, const char* argv[]) {
//TODO: check if table (with flag -table) is passed in input. If so, run automatically on all genes in the table.
/*FORMAT TABLE:
first line: header - first toke is patientID, second token is survival time, third is censoring info, then geneIDs, everything \t separated
other lines: one entry per patient; patientID is string; survival time is float; censoring is 1 if death, is 0 otherwise; for geneID colums,
is 0 if gene not mutated in the patient and
it is 1 otherwise.
OUTPUT FORMAT:
list of geneIDs and p-values and method used to compute p-value
after -table, pass -p_threshold with threshold p-value for MC method -> if p-value estimated with
MC > p_threshold then use that, otherwise use FPTAS; if not passed by user, use 0.05/num.genes
- requires to estimate number of genes from table first
*/
string tmp = string( "-table" );
if ( argc > 2 and tmp.compare( argv[2] ) == 0 ) {
cout << "RUNNING ON ENTIRE TABLE PASSED IN INPUT" << endl;
//order input params: table_file -table min_freq
//read input file
ifstream intable;
intable.open(argv[1],ifstream::in);
string line;
int line_c = 0;
int num_genes = 0;
int num_patients = 0;
//survival times vector
//vector <float> survival_times;
//censoring vector
vector <int> censoring_tmp;
//geneIDs (same order as in file)
vector <string> geneID;
if (intable.is_open()) {
while ( getline (intable,line) ){
//cout << line << endl;
char * line_char = strdup( line.c_str() );
int tok_counter = 0;
char *p = strtok(line_char, "\t");
while (p) {
//printf ("Token: %s\n", p);
if (line_c == 0 and tok_counter >=3){
num_genes++;
geneID.push_back(string(p));
}
if (line_c > 0 and tok_counter == 1){
survival_times.push_back(atof(p));
}
if (line_c > 0 and tok_counter == 2){
char* pEnd;
censoring_tmp.push_back(atoi(p));
}
tok_counter++;
p = strtok(NULL, "\t");
}
if (line_c > 0){
num_patients++;
}
line_c++;
}
intable.close();
}
cout << "Number of genes: " << num_genes << endl;
cout << "Number of patients: " << num_patients << endl;
//read minimum frequency
int min_freq = atoi( argv[3] );
cout << "Minimum frequency: " << min_freq << endl;
/*
//print content survival_times
for (vector<float>::iterator it = survival_times.begin(); it != survival_times.end(); ++it)
cout << ' ' << *it;
cout << endl;
//print content censoring
for (vector<int>::iterator it = censoring_tmp.begin(); it != censoring_tmp.end(); ++it)
cout << ' ' << *it;
cout << endl;
*/
//gene table
vector< vector<int> > gene_table( num_genes, vector<int>(0) );
line_c = 0;
intable.open(argv[1],ifstream::in);
if (intable.is_open()) {
while ( getline (intable,line) ){
char * line_char = strdup( line.c_str() );
int tok_counter = 0;
char *p = strtok(line_char, "\t");
int gene_index = 0;
while (p) {
if (line_c > 0 and tok_counter >=3){
gene_table[gene_index].push_back(atoi(p));
gene_index++;
}
tok_counter++;
p = strtok(NULL, "\t");
}
line_c++;
}
intable.close();
}
//print content gene_table
/*
for (int i=0; i<num_genes; i++){
for (vector<int>::iterator it = gene_table[i].begin(); it != gene_table[i].end(); ++it)
cout << " " << *it ;
cout << endl;
}
*/
//derive permutation obtained from sorting survival_times
vector<int> permut(survival_times.size(), 0);
for (int i = 0 ; i != permut.size() ; i++) {
permut[i] = i;
}
sort(permut.begin(), permut.end(), compare_surv_times );
/*
for (int i = 0 ; i != permut.size() ; i++) {
cout << permut[i] << endl;
}
*/
//now sort censoring vector using the permutation derived above
vector<int> censoring;
for (int i = 0; i < permut.size(); i++){
censoring.push_back( censoring_tmp[permut[i]] );
}
//print content censoring
/*
cout << "Sorted censoring" << endl;
for (vector<int>::iterator it = censoring.begin(); it != censoring.end(); ++it)
cout << ' ' << *it;
cout << endl;
*/
//find p_threshold: if a p-value estimated using the MC method is < p_threshold, then the exhaustive method or FPTAS are used
//to compute the p-value
double p_threshold;
string tmp = string( "-p_thres" );
int index_p_thres = -1;
for (int i=0; i<argc; i++){
if (tmp.compare(argv[i]) == 0){
index_p_thres = i;
}
}
if (index_p_thres > 0){
p_threshold = atof(argv[index_p_thres+1]);
}
else{
p_threshold = 1.0/double(number_iter);
}
cout << "[p_thresh: " << p_threshold << "]" << endl;
//approximation factor
double e;
tmp = string( "-approx_factor" );
int index_e = -1;
for (int i=0; i<argc; i++){
if (tmp.compare(argv[i]) == 0){
index_e = i;
}
}
if (index_e > 0){
e = atof(argv[index_e+1]);
}
else{
e = 10.0;
}
cout << "[approximation factor: " << e << "]" << endl;
//outfile name
ofstream outf;
tmp = string( "-out_file" );
int index_outf = -1;
for (int i=0; i<argc; i++){
if (tmp.compare(argv[i]) == 0){
index_outf = i;
}
}
if (index_outf > 0){
outf.open(argv[index_outf+1]);
}
else{
outf.open("output_ExaLT.txt");
}
//write header on file
outf << "GENE_ID\tNUM_MUT_SAMPLE\tP_VALUE\tP_VALUE_LEFT\tP_VALUE_RIGHT\tMETHOD" << endl;
//fix number of permutations for MC: depends on p_threshold, but make sure it is not too small
//for each geneID:
double p_value;
double p_value_left;
double p_value_right;
//tables to store info for later lookup
//frequency[i] = mutation frequency for distributions in Vs_1, Prob_1, Vs_2, Prob_2
vector<int> frequency;
//vector of values for first side of FPTAS
vector<matrix_sim> Vs_1;
//vector of probabilities for first side of FPTAS
vector<matrix_sim> Prob_1;
//vector of values for second side of FPTAS
vector<matrix_sim> Vs_2;
//vector of probabilities for second side of FPTAS
vector<matrix_sim> Prob_2;
for (int i=0; i<gene_table.size(); i++){
//number of mutations for current gene
int freq_tmp = 0;
//derive vector of mutations for the gene according to permutation above
vector<int> muts_tmp;
for (int j = 0; j < permut.size(); j++){
muts_tmp.push_back( gene_table[i][permut[j]] );
freq_tmp += gene_table[i][permut[j]];
}
//print content censoring
/*
cout << "Sorted mutations for " << geneID[i] << "(freq=" << freq_tmp << ")" << endl;
for (vector<int>::iterator it = muts_tmp.begin(); it != muts_tmp.end(); ++it)
cout << ' ' << *it;
cout << endl;
*/
//get p-value only if number of mutations is >= min_freq
if ( freq_tmp >= min_freq ){
//run MC to estimate p-value first
double p_value_MC;
double p_value_MC_left;
double p_value_MC_right;
//cout<<"Running quick estimate of the p-value..."<<endl;
string method = string("MC");
MC_estimate( muts_tmp, censoring, p_value_MC, p_value_MC_left, p_value_MC_right, number_iter );
if (p_value_MC == 0.0 ){
double min_pvalue_MC = 1.0/double(number_iter);
//cout <<"the estimated p-value is < "<<min_pvalue_MC<<endl;
p_value = min_pvalue_MC;
p_value_left = min_pvalue_MC;
p_value_right = min_pvalue_MC;
}
else{
/*
cout <<"[The left p-value is estimated to be close to: "<<p_value_MC_left << "]" <<endl;
cout <<"[The right p-value is estimated to be close to: "<<p_value_MC_right << "]" <<endl;
cout<<"The p-value is estimated to be close to: "<<p_value_MC<<endl;
*/
p_value = p_value_MC;
p_value_left = p_value_MC_right;
p_value_right = p_value_MC_left;
}
//if p-value is < p_threshold:
if (p_value_MC <= p_threshold){
//count number of combinations required by exact test
/*
cout <<"number of samples in group 0: "<<muts_tmp.size()-freq_tmp<<endl;
cout <<"number of samples in group 1: "<<freq_tmp<<endl;
*/
unsigned long long ncomb = bcoeff(muts_tmp.size() , freq_tmp);
//IF number combinations > threshold (fixed in code()): run FPTAS ELSE run exhaustive test
if (ncomb <= 10000000){
//cout<<"Computing exact p-value..."<<endl;
method = string("exhaustive");
double p_value_exh;
double p_value_exh_left;
double p_value_exh_right;
exhaustive( muts_tmp, censoring, p_value_exh, p_value_exh_left, p_value_exh_right);
/*
cout <<"p-value (left) = " << p_value_exh_left << endl;
cout <<"p-value (right) = " << p_value_exh_right << endl;
cout<< geneID[i] << " p-value = "<<p_value_exh<<endl;
*/
p_value = p_value_exh;
p_value_left = p_value_exh_left;
p_value_right = p_value_exh_right;
}
else{
method = string("FPTAS");
//check if the FPTAS has been run for this mutation frequency
int index_freq = -1;
for (int k=0; k<frequency.size(); k++){
if ( frequency[k] == freq_tmp ){
index_freq = k;
}
}
if ( index_freq >= 0 ){
//cout << "****** USING LOOK-UP TABLES ******" << endl;
//compute the statistic
double V = 0;
double seen = 0;
for (int j=0;j<num_patients;j++) {
V = V + censoring[j] * ( (double)muts_tmp[j] -(freq_tmp-seen)/((double)num_patients-j));
seen += (double)muts_tmp[j];
}
//cout << "Statistic for first side: " << V << endl;
//now find the p-value
//first side
V=fabs(V);
double max_v_column_n1_index = -DBL_MAX;
double min_v_column_n1_index = DBL_MAX;
vector_max_min(Vs_1[index_freq].get_row(1), &max_v_column_n1_index, &min_v_column_n1_index);
double min_p_column_n1_index, max_p_column_n1_index;
vector_max_min(Prob_1[index_freq].get_row(1), &max_p_column_n1_index, &min_p_column_n1_index);
/*
cout << "Prob_1[index_freq]: " << endl;
Prob_1[index_freq].display();
cout << "Vs_1[index_freq]: " << endl;
Vs_1[index_freq].display();
*/
if ( V>max_v_column_n1_index ) {
p_value_right = 0.0;
}
else if ( V<=min_v_column_n1_index ) {
p_value_right = max_p_column_n1_index;
} else {
int l = intervalBound(Vs_1[index_freq], V, precision);
p_value_right=Prob_1[index_freq].get_element(1,l);
}
//cout << "p_value_right: " << p_value_right << endl;
//second side
V=-fabs(V);
max_v_column_n1_index = -DBL_MAX;
min_v_column_n1_index = DBL_MAX;
vector_max_min(Vs_2[index_freq].get_row(1), &max_v_column_n1_index, &min_v_column_n1_index);
vector_max_min(Prob_2[index_freq].get_row(1), &max_p_column_n1_index, &min_p_column_n1_index);
if ( V>max_v_column_n1_index ) {
//find the minimum p greater than 0
int size = Prob_2[index_freq].get_row(1).size();
//cout << "Size: " << size << endl;
double min_p = DBL_MAX;
for (int ii=0; ii<size; ++ii) {
if ((Prob_2[index_freq].get_element(1,ii+1)<min_p) && (Prob_2[index_freq].get_element(1,ii+1)!=0)){
min_p = Prob_2[index_freq].get_element(1,ii+1);
}
}
p_value_left = min_p;
}
else if ( V<=min_v_column_n1_index ) {
double e1 = 1.0 - pow( 1.0+e, -1.0/((double)num_patients) );
double tmp_dbl = (double)freq_tmp*log( (double)num_patients )/log(1+e1);
int k_max = tmp_dbl - (int)tmp_dbl > 0? (int)tmp_dbl+1 : (int)tmp_dbl; //%maximum number of k
int k_max_index = k_max + 1;
p_value_left = Prob_2[index_freq].get_element(1,k_max_index);
} else {
int l = intervalBound_secondSide(Vs_2[index_freq], V, precision);
//l
p_value_left = Prob_2[index_freq].get_element(1,l);
}
//cout << "p_value_left: " << p_value_left << endl;
//total p_value
p_value = min(p_value_left+p_value_right, 1.0);
//cout << "p-value obtained from table: " << p_value << endl;
}
else {
frequency.push_back( freq_tmp );
matrix_sim v(1,1),p(1,1);
matrix_sim v2(1,1),p2(1,1);
matrix_sim v_tmp = v.get_col_as_row_matrix( freq_tmp+1 );
matrix_sim p_tmp = p.get_col_as_row_matrix( freq_tmp+1 );
double e2 = e;
pt_data data1;
data1.x = &muts_tmp;
data1.c = &censoring;
data1.e = &e;
data1.p_value = &p_value_right;
data1.v = &v;
data1.p = &p;
vector<int> censoring2 = censoring;
vector<int> muts_tmp2 = muts_tmp;
pt_data data2;
data2.x = &muts_tmp2;
data2.c = &censoring2;
data2.e = &e2;
data2.p_value = &p_value_left;
data2.v = &v2;
data2.p = &p2;
//cout << "Obtaining controlled approximation..." << endl;
int rc;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
pthread_t thread_FPTAS1, thread_FPTAS2;
rc = pthread_create(&thread_FPTAS1, &attr, FPTAS1, (void*)&data1);
if (rc) {
fprintf(stderr, "ERROR: return code from pthread_create() is %d\n", rc);
exit(-1);
}
rc = pthread_create(&thread_FPTAS2, &attr, FPTAS2, (void*)&data2);
if (rc) {
fprintf(stderr, "ERROR: return code from pthread_create() is %d\n", rc);
exit(-1);
}
//join the threads
void* status;
for (int i=0; i<2; i++) {
if (i==0) {
rc = pthread_join( thread_FPTAS1, &status);
} else if (i==1) {
rc = pthread_join( thread_FPTAS2, &status);
}
if (rc) {
fprintf(stderr, "return code from pthread_join() is %d\n", rc);
exit(-1);
}
}
v_tmp = data1.v->get_col_as_row_matrix( freq_tmp+1 );
p_tmp = data1.p->get_col_as_row_matrix( freq_tmp+1 );
Vs_1.push_back(v_tmp);
Prob_1.push_back(p_tmp);
v_tmp = data2.v->get_col_as_row_matrix( freq_tmp+1 );
p_tmp = data2.p->get_col_as_row_matrix( freq_tmp+1 );
Vs_2.push_back(v_tmp);
Prob_2.push_back(p_tmp);
p_value_left = *data2.p_value;
p_value_right = *data1.p_value;
p_value = min(p_value_left+p_value_right, 1.0);
}
}
}
//write output on file
outf << geneID[i] << "\t" << freq_tmp << "\t" << p_value << "\t" << p_value_left << "\t" << p_value_right << "\t" << method << endl;
}
}
outf.close();
return 0;
}
//TODO: change output file names (to be passed as parameters)
else{
int line_c = 0;
ifstream infile;
infile.open(argv[1],ifstream::in);
if(!infile.is_open()) {
cerr<<"Error: Can not open data file " << argv[1] <<".\n" <<endl;
cout<<endl;
return -1;
}
string line, instring, cens_string;
while ( getline(infile, line) ) {
if (line_c == 0)
instring=line; //get 1st line
else
cens_string=line; //get 2nd line, as sensor data
line_c += 1;
}
infile.close();
vector <int> x;
int instring_len = instring.length();
unsigned long long n_ones = 0;
for (int i=0; i<instring_len; i++) {
if (instring[i] == '0')
x.push_back(0);
else {
n_ones += 1;
x.push_back(1);
}
}
vector <int> c;
int censtring_len = cens_string.length();
for (int i=0; i<censtring_len; i++) {
if (cens_string[i] == '0')
c.push_back(0);
else {
c.push_back(1);
}
}
vector<int> c2 = c;
vector<int> x2 = x;
double p_value;
double p_value2;
//run exhaustive if the number of combinations is not too large
cout <<"number of samples in group 0: "<<x.size()-n_ones<<endl;
cout <<"number of samples in group 1: "<<n_ones<<endl;
unsigned long long ncomb = bcoeff(x.size() , n_ones);
if (ncomb <= 100000000){
cout<<"Computing exact p-value..."<<endl;
double p_value_exh;
double p_value_exh_left;
double p_value_exh_right;
exhaustive( x, c, p_value_exh, p_value_exh_left, p_value_exh_right);
cout <<"p-value (left) = " << p_value_exh_left << endl;
cout <<"p-value (right) = " << p_value_exh_right << endl;
cout<<"p-value = "<<p_value_exh<<endl;
return 0;
}
//run MC to estimate p-value first
double p_value_MC;
double p_value_MC_left;
double p_value_MC_right;
cout<<"Running quick estimate of the p-value..."<<endl;
MC_estimate( x, c, p_value_MC, p_value_MC_left, p_value_MC_right, number_iter );
if (p_value_MC == 0.0 ){
double min_pvalue_MC = 1.0/double(number_iter);
cout <<"the estimated p-value is < "<<min_pvalue_MC<<endl;
}
else{
cout <<"[The left p-value is estimated to be close to: "<<p_value_MC_left << "]" <<endl;
cout <<"[The right p-value is estimated to be close to: "<<p_value_MC_right << "]" <<endl;
cout<<"the p-value is estimated to be close to: "<<p_value_MC<<endl;
}
//now check if more controlled approximation is needed
char input;
do{
cout << "Do you want a controlled approximation? [Y/N]" << endl;
cin >> input;
} while ( (input != 'Y') && (input != 'N') );
if (input == 'N') {
return 0;
}
else{
cout << "Provide approximation factor (see README)"<<endl;
double e;
cin >> e;
matrix_sim v(1,1),p(1,1);
matrix_sim v2(1,1),p2(1,1);
double e2 = e;
pt_data data1;
data1.x = &x;
data1.c = &c;
data1.e = &e;
data1.p_value = &p_value;
data1.v = &v;
data1.p = &p;
pt_data data2;
data2.x = &x2;
data2.c = &c2;
data2.e = &e2;
data2.p_value = &p_value2;
data2.v = &v2;
data2.p = &p2;
cout << "Obtaining controlled approximation..." << endl;
int rc;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
pthread_t thread_FPTAS1, thread_FPTAS2;
rc = pthread_create(&thread_FPTAS1, &attr, FPTAS1, (void*)&data1);
if (rc) {
fprintf(stderr, "ERROR: return code from pthread_create() is %d\n", rc);
exit(-1);
}
rc = pthread_create(&thread_FPTAS2, &attr, FPTAS2, (void*)&data2);
if (rc) {
fprintf(stderr, "ERROR: return code from pthread_create() is %d\n", rc);
exit(-1);
}
//join the threads
void* status;
for (int i=0; i<2; i++) {
if (i==0) {
rc = pthread_join( thread_FPTAS1, &status);
} else if (i==1) {
rc = pthread_join( thread_FPTAS2, &status);
}
if (rc) {
fprintf(stderr, "return code from pthread_join() is %d\n", rc);
exit(-1);
}
}
cout<<"p-value (left) = "<<p_value<<endl;
cout<<"p-value (right) = "<<p_value2<<endl;
p_value = min(p_value+p_value2, 1);
cout<<"p-value = "<<p_value<<endl;
return 0;
}
}
}