5 static int treeout = 0;
7 #ifdef enablemultithread
8 typedef struct _jobtable
14 typedef struct _thread_arg
22 pthread_mutex_t *mutex;
25 void *athread( void *arg )
27 thread_arg_t *targ = (thread_arg_t *)arg;
28 int njob = targ->njob;
29 int thread_no = targ->thread_no;
30 float *selfscore = targ->selfscore;
31 double **mtx = targ->mtx;
32 char **seq = targ->seq;
33 Jobtable *jobpospt = targ->jobpospt;
36 float ssi, ssj, bunbo;
40 pthread_mutex_lock( targ->mutex );
46 fprintf( stderr, "%4d/%4d (thread %4d), dndpre\r", i+1, njob, thread_no );
51 pthread_mutex_unlock( targ->mutex );
57 pthread_mutex_unlock( targ->mutex );
62 bunbo = MIN( ssi, ssj );
66 mtx[i][j] = 1.0 - (double)naivepairscore11( seq[i], seq[j], penalty ) / bunbo;
72 void arguments( int argc, char *argv[] )
84 ppenalty = NOTSPECIFIED; //?
85 ppenalty_ex = NOTSPECIFIED; //?
86 poffset = NOTSPECIFIED; //?
87 kimuraR = NOTSPECIFIED;
90 while( --argc > 0 && (*++argv)[0] == '-' )
92 while ( (c = *++argv[0]) )
110 fprintf( stderr, "inputfile = %s\n", inputfile );
114 nthread = atoi( *++argv );
115 fprintf( stderr, "nthread = %d\n", nthread );
125 fprintf( stderr, "options: Check source file !\n" );
130 int main( int argc, char **argv )
140 float ssi, ssj, bunbo;
143 arguments( argc, argv );
144 #ifndef enablemultithread
150 infp = fopen( inputfile, "r" );
153 fprintf( stderr, "Cannot open %s\n", inputfile );
161 PreRead( stdin, &njob, &nlenmax );
167 seq = AllocateCharMtx( njob, nlenmax+1 );
168 name = AllocateCharMtx( njob, B+1 );
169 mtx = AllocateDoubleMtx( njob, njob );
170 selfscore = AllocateFloatVec( njob );
173 FRead( stdin, name, nlen, seq );
175 readData_pointer( infp, name, nlen, seq );
179 constants( njob, seq );
182 for( i=0; i<njob-1; i++ )
184 fprintf( stderr, "%4d/%4d\r", i+1, njob );
185 for( j=i+1; j<njob; j++ )
186 mtx[i][j] = (double)substitution_hosei( seq[i], seq[j] );
187 // fprintf( stderr, "i=%d,j=%d, l=%d &&& %f\n", i, j, nlen[0], mtx[i][j] );
190 for( i=0; i<njob; i++ )
192 selfscore[i] = (float)naivepairscore11( seq[i], seq[i], penalty );
195 #ifdef enablemultithread
201 pthread_mutex_t mutex;
206 targ = calloc( nthread, sizeof( thread_arg_t ) );
207 handle = calloc( nthread, sizeof( pthread_t ) );
208 pthread_mutex_init( &mutex, NULL );
210 for( i=0; i<nthread; i++ )
212 targ[i].thread_no = i;
214 targ[i].selfscore = selfscore;
217 targ[i].jobpospt = &jobpos;
218 targ[i].mutex = &mutex;
220 pthread_create( handle+i, NULL, athread, (void *)(targ+i) );
223 for( i=0; i<nthread; i++ )
225 pthread_join( handle[i], NULL );
227 pthread_mutex_destroy( &mutex );
232 for( i=0; i<njob-1; i++ )
235 fprintf( stderr, "%4d/%4d\r", i+1, njob );
236 for( j=i+1; j<njob; j++ )
239 bunbo = MIN( ssi, ssj );
243 mtx[i][j] = 1.0 - (double)naivepairscore11( seq[i], seq[j], penalty ) / bunbo;
244 // mtx[i][j] = 1.0 - (double)naivepairscore11( seq[i], seq[j], penalty ) / MIN( selfscore[i], selfscore[j] );
245 // fprintf( stderr, "i=%d,j=%d, l=%d### %f, score = %d\n", i, j, nlen[0], mtx[i][j], naivepairscore11( seq[i], seq[j], penalty ) );
252 for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ )
253 fprintf( stdout, "i=%d, j=%d, mtx[][] = %f\n", i, j, mtx[i][j] );
256 fp = fopen( "hat2", "w" );
257 WriteHat2_pointer( fp, njob, name, mtx );
265 topol = AllocateIntCub( njob, 2, njob );
266 len = AllocateDoubleMtx( njob, njob );
267 veryfastsupg_double_outtree( njob, mtx, topol, len );
273 res = system( ALNDIR "/spgsdl < hat2" );