modified: src1/worker.c
[GalaxyCodeBases.git] / BGI / SOAPdenovo2 / sparsePregraph / multi_threads.cpp
blob5aa755dc072a695ea2b1013818010372152ca290
1 /*
2 * multi_threads.cpp
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"
24 #include "global.h"
25 #include "build_graph.h"
26 #include "stdinc.h"
28 #include <unistd.h>
30 #include "build_preArc.h"
32 void creatThrds ( pthread_t * threads, PARAMETER * paras )
34 unsigned char i;
35 int temp;
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" );
42 exit ( 1 );
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 )
54 PARAMETER * prm;
55 int i;
56 unsigned char id;
57 prm = ( PARAMETER * ) para;
58 id = prm->threadID;
59 struct hashtable2 * ht = prm->ht;
60 int K_size = prm->K_size;
61 int gap = prm->gap;
63 while ( 1 )
65 if ( * ( prm->selfSignal ) == 3 )
67 * ( prm->selfSignal ) = 0;
68 break;
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 )
84 int bad_flag = 0;
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;
95 usleep ( 1 );
99 void thread_wait ( pthread_t * threads )
101 int i;
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 )
110 int t;
112 for ( t = 0; t < thrd_num_s; t++ )
113 { thrdSignals[t + 1] = SIG; }
115 while ( 1 )
117 usleep ( 10 );
119 for ( t = 0; t < thrd_num_s; t++ )
120 if ( thrdSignals[t + 1] )
121 { break; }
123 if ( t == thrd_num_s )
124 { break; }