4 * Copyright (c) 2008-2012 BGI-Shenzhen <soap at genomics dot org dot cn>.
6 * This file is part of SOAPdenovo.
8 * SOAPdenovo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * SOAPdenovo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with SOAPdenovo. If not, see <http://www.gnu.org/licenses/>.
23 #include "multi_threads.h"
25 #include "build_graph.h"
30 #include "build_preArc.h"
32 void creatThrds ( pthread_t
* threads
, PARAMETER
* paras
)
37 for ( i
= 0; i
< thrd_num_s
; i
++ )
39 if ( ( temp
= pthread_create ( &threads
[i
], NULL
, threadRoutine
, & ( paras
[i
] ) ) ) != 0 )
41 fprintf ( stderr
, "ERROR: create threads failed.\n" );
46 //fprintf(stderr,"%d work threads created.\n",thrd_num_s);
47 fprintf ( stderr
, "%d work threads initialized.\n", thrd_num_s
);
52 void * threadRoutine ( void * para
)
57 prm
= ( PARAMETER
* ) para
;
59 struct hashtable2
* ht
= prm
->ht
;
60 int K_size
= prm
->K_size
;
65 if ( * ( prm
->selfSignal
) == 3 )
67 * ( prm
->selfSignal
) = 0;
70 else if ( * ( prm
->selfSignal
) == 10 )
72 run_process_threaded ( ht
, locks
, K_size
, gap
, read_num
, thrd_num_s
, prm
->threadID
, 1 );
73 * ( prm
->selfSignal
) = 0;
75 else if ( * ( prm
->selfSignal
) == 11 )
77 run_process_threaded ( ht
, locks
, K_size
, gap
, read_num
, thrd_num_s
, prm
->threadID
, 2 );
78 * ( prm
->selfSignal
) = 0;
80 else if ( * ( prm
->selfSignal
) == 12 )
82 for ( int i
= prm
->threadID
; i
< read_num
; i
+= thrd_num_s
)
85 filter_N ( seq_t
[i
], bad_flag
);
87 if ( bad_flag
) {seq_t
[i
].clear(); continue;}
89 process_1read_preArc ( prm
->preArcs
, locks
, prm
->threadID
, prm
->v_ht
, K_size
, prm
->cut_off_len
, seq_t
[i
].c_str() );
92 * ( prm
->selfSignal
) = 0;
99 void thread_wait ( pthread_t
* threads
)
103 for ( i
= 0; i
< thrd_num_s
; i
++ )
104 if ( threads
[i
] != 0 )
105 { pthread_join ( threads
[i
], NULL
); }
108 void sendWorkSignal ( unsigned char SIG
, unsigned char * thrdSignals
)
112 for ( t
= 0; t
< thrd_num_s
; t
++ )
113 { thrdSignals
[t
+ 1] = SIG
; }
119 for ( t
= 0; t
< thrd_num_s
; t
++ )
120 if ( thrdSignals
[t
+ 1] )
123 if ( t
== thrd_num_s
)