38 #if defined(__ALTIVEC__)
46 #include <sys/types.h>
48 #include <sys/select.h>
54 static ssize_t
write_all(
int fd,
const void *data,
size_t len) {
58 res = write(fd,(
const int8_t*)data+sent,len-sent);
71 static ssize_t
read_all(
int fd,
void *buf,
size_t len) {
75 res = read(fd,(int8_t*)buf+recv,len-recv);
88 int main(
int argc,
char * argv[] ){
89 char * matrixFile = NULL, * queryFile = NULL, * dbFile = NULL;
96 #elif defined(__ALTIVEC__)
101 Options options = {-12,-2,DBL_MAX};
102 int qCount=0, dCount=0, qResidues=0, dResidues=0;
103 #ifdef HAVE_SYSCONF_NPROCESSORS
104 int threads = sysconf(_SC_NPROCESSORS_ONLN);
114 for ( i=1; i<argc; i++ ){
115 if (argv[i][0]==
'-'){
116 switch( argv[i][1] ){
127 options.
gapOpen = atoi( argv[++i] );
130 options.
gapExt = atoi( argv[++i] );
133 threads = atoi( argv[++i] );
140 if (matrixFile == NULL)
141 matrixFile = argv[i];
142 else if (queryFile == NULL)
144 else if (dbFile == NULL)
152 if ( matrixFile == NULL || queryFile == NULL || dbFile == NULL ){
153 fprintf( stderr,
"Usage: %s [-h] [-s] [-j num] [-i num] [-e num] [-t num] matrix query db\n", argv[0] );
157 fprintf( stderr,
"Invalid values for gapOpen or gapExt\n");
161 fprintf( stderr,
"Linear gap penalties not allowed\n");
174 int childpipe_read = -1;
175 int childpipe_write = -1;
177 #if defined(__SSE2__)
186 int current_profile_is_byte = 0;
189 #if defined(__ALTIVEC__)
194 pipes_read = malloc(threads*
sizeof(*pipes_read));
195 pipes_write = malloc(threads*
sizeof(*pipes_write));
196 children = malloc(threads*
sizeof(*children));
197 seq_names = malloc(threads*
sizeof(*seq_names));
198 for(i=0;i<threads;++i) {
206 qCount++; qResidues+=queryLen;
210 for(i=0; i<threads; ++i) {
219 if(db == NULL)
break;
221 dCount++; dResidues+=dbLen;
225 perror(
"error during pipe()");
228 pipes_read[i] = fds[0];
229 childpipe_write = fds[1];
233 perror(
"error during pipe()");
236 pipes_write[i] = fds[1];
237 childpipe_read = fds[0];
239 children[i] = fork();
240 if(children[i] < 0) {
241 perror(
"error during fork()");
243 }
else if(children[i] == 0) {
247 for(j=0; j<=i; ++j) {
248 close(pipes_read[j]);
249 close(pipes_write[j]);
260 close(childpipe_read);
261 close(childpipe_write);
263 childpipe_write = -1;
266 sres =
write_all(pipes_write[i],&dbLen,
sizeof(
int));
267 if(sres !=
sizeof(
int)) {
268 perror(
"error during write()");
271 sres =
write_all(pipes_write[i],db,dbLen);
273 perror(
"error during write()");
280 childpipe_write = -1;
289 if(childpipe_read <= 0) {
300 res =
read_all(childpipe_read,&dbLen,
sizeof(
int));
301 if(res !=
sizeof(
int)) {
302 if(res == 0) exit(0);
303 perror(
"error during read()");
306 res =
read_all(childpipe_read,db,dbLen);
308 perror(
"error during read()");
311 dbName = seq_names[child_id];
323 for(i=0; i<threads; ++i) {
324 if(pipes_read[i] > 0) FD_SET(pipes_read[i],&readfds);
325 if(pipes_read[i]>max_fd) max_fd = pipes_read[i];
329 if(max_fd == -1)
break;
332 res = select(max_fd+1, &readfds, NULL, NULL, NULL);
334 perror(
"error during select()");
337 for(i=0; i<threads; ++i) {
338 if(pipes_read[i] > 0 && FD_ISSET(pipes_read[i],&readfds)) {
341 res =
read_all(pipes_read[i],&score,
sizeof(score));
342 if(res !=
sizeof(score)) {
343 perror(
"error during read()");
353 dCount++; dResidues+=dbLen;
357 res =
write_all(pipes_write[i],&dbLen,
sizeof(
int));
358 if(res !=
sizeof(
int)) {
359 perror(
"error during write()");
362 res =
write_all(pipes_write[i],db,dbLen);
364 perror(
"error during write()");
368 close(pipes_write[i]);
369 close(pipes_read[i]);
374 waitpid(children[i],NULL,0);
381 if(db == NULL)
break;
384 for(i=0; i<queryLen; ++i) printf(
"\t%c",query[i]);
388 #if defined(__SSE2__)
392 assert(score >= 250 &&
"score too low");
398 #if defined(__ALTIVEC__)
411 score = alignmentProfileSPE( db, dbLen );
414 current_profile_is_byte = 1;
416 if( score >= DBL_MAX ) {
418 current_profile_is_byte = 0;
423 current_profile_is_byte = 1;
427 if( score >= DBL_MAX ) {
431 #if defined(__ALTIVEC__)
436 #if defined(__ALTIVEC__)
454 if(childpipe_write > 0) {
457 res =
write_all(childpipe_write,&score,
sizeof(score));
458 if(res !=
sizeof(score)) {
459 perror(
"error during write()");
464 printf(
">threshold\t%s x %s\n",dbName,queryName);
466 printf(
"%g\t%s x %s\n",score,dbName,queryName);
475 for(i=0; i<threads; ++i) {
476 if( seq_names[i] != NULL ) {
477 free( seq_names[i] );
482 #if defined(__SSE2__)
493 fprintf(stderr,
"%d[%d] x %d[%d]\n", qCount, qResidues, dCount, dResidues );