static int main_loop_program( const char *funcpath, struct text_list *seta, struct text_list *setb ) { int x,i,j,c; char line[1024]; FILE *proc[num_cores]; int xstop = text_list_size(seta); /* for each block sized vertical stripe... */ for(x=0;x<xstop;x+=block_size) { /* for each row in the stripe ... */ for(j=0;j<text_list_size(setb);j++) { /* for each group of num_cores in the stripe... */ for(i=x;i<(x+block_size);i+=num_cores) { /* make sure we don't run past the block width */ int n = MIN(num_cores,x+block_size-i); /* make sure we don't run off the width of the array */ n = MIN(n,xstop-i); /* start one process for each core */ /* if nindex = 2, the real xindex = index_array[0] + i; the real yindex = index_array[1] + j. */ for(c=0;c<n;c++) { if((nindex == 2 && (index_array[0] + i + c) <= (index_array[1] + j)) || //calcuate xindex and yindex of the unit in the original matrix of allpairs_master (is_symmetric == 0 && nindex == 0) || (is_symmetric && (i+c) <= j)) { sprintf(line,"%s %s %s %s\n",funcpath,extra_arguments,text_list_get(seta,i+c),text_list_get(setb,j)); proc[c] = fast_popen(line); if(!proc[c]) { fprintf(stderr,"%s: couldn't execute %s: %s\n",progname,line,strerror(errno)); return 1; } } } /* then finish one process for each core */ for(c=0;c<n;c++) { if((nindex == 2 && (index_array[0] + i + c) <= (index_array[1] + j)) || (is_symmetric == 0 && nindex == 0) || (is_symmetric && (i+c) <= j)) { printf("%s\t%s\t",text_list_get(seta,i+c),text_list_get(setb,j)); int lines = 0; while(fgets(line,sizeof(line),proc[c])) { printf("%s",line); lines++; } if(lines==0) printf("\n"); fast_pclose(proc[c]); } } } } } return 0; }
double estimate_run_time( struct text_list *seta, struct text_list *setb ) { char line[ALLPAIRS_LINE_MAX]; timestamp_t starttime, stoptime; int x,y; fprintf(stderr, "%s: sampling execution time of %s...\n",progname,allpairs_compare_program); starttime = timestamp_get(); for(x=0;x<xstop;x++) { for(y=0;y<ystop;y++) { sprintf(line,"./%s %s %s %s", string_basename(allpairs_compare_program), extra_arguments, text_list_get(seta,x), text_list_get(setb,y) ); FILE *file = fast_popen(line); if(!file) { fprintf(stderr,"%s: couldn't execute %s: %s\n",progname,line,strerror(errno)); exit(1); } while(fgets(line,sizeof(line),file)) { fprintf(stderr,"%s",line); } fast_pclose(file); stoptime = timestamp_get(); if(stoptime-starttime>5000000) break; } if(stoptime-starttime>5000000) break; } double t = (double)(stoptime - starttime) / (x * ystop + y + 1) / 1000000; if(t<0.01) t = 0.01; return t; }