void sendMessage(int msg[4], int to_rank){ // some ugly switching to accomodate usage of sending messages in one function altogether if(to_rank==-1 && msg){ // send msg to left and right if(msg[1]==-1){ int right = getNextNeighbor(rank, 1); MPI_Send(msg, 4, MPI_INT, right, LEADERTAG, MPI_COMM_WORLD); }else{ int left = getNextNeighbor(rank, -1); MPI_Send(msg, 4, MPI_INT, left, LEADERTAG, MPI_COMM_WORLD); } messages_sent++; }else if (msg){ MPI_Send(msg, 4, MPI_INT, to_rank, LEADERTAG, MPI_COMM_WORLD); messages_sent++; }else if (!msg && to_rank==-1){ int win = 1; int i = 0; for (i=0;i<size;i++){ if (i!=rank){ messages_sent++; MPI_Send(&win,1,MPI_INT,i,WINNERTAG, MPI_COMM_WORLD); } } } }
/* int */ void findAllCircle(Edge **C, int **F, int **remain, int *stack, int *sTop, int nNodes, int sink) { int u = sink; /* 表示当前的顶点 */ /* bool ret = false; */ int *circle, cLen; int *preflow; // 显示每次消去一环所消耗的时间 // struct timeval NC_begin; // struct timeval NC_end; // int NC_count = 0; // double time; circle = (int *)calloc(nNodes+1, sizeof(int)); /* cLen = 0; */ preflow = (int *)malloc(sizeof(int)); /* *preflow = INFINITE; */ labRedo: // 显示消去一环的时间消耗 // gettimeofday(&NC_begin, NULL); for (;;) { while (u != -1) { if (contain(stack, *sTop, u) == -1) { stack[(*sTop)++] = u; u = getFirstNeighbor(remain, nNodes, u); } else { int v = contain(stack, *sTop, u); stack[(*sTop)++] = u; cLen = 0; while (v < *sTop) circle[cLen++] = stack[v++]; /* int i; */ /* for (i = 0; i < cLen; i++) */ /* printf("%d\t", circle[i]); */ /* printf("\n"); */ *preflow = INFINITE; /* 此处将cLen > 4改为cLen > 3 */ if (cLen > 3 && computeWeight(C, F, remain, circle, cLen, preflow) < 0) { /* updateFlow(F, circle, cLen, preflow); */ updateFlowRemain(F, remain, circle, cLen, preflow); *sTop = 0; u = circle[0]; cLen = 0; // 显示消去一环的时间消耗 // NC_count++; // gettimeofday(&NC_end, NULL); // time = (NC_end.tv_sec-NC_begin.tv_sec)*1000000 + NC_end.tv_usec-NC_begin.tv_usec; // printf("%d\t%15.2f\n", NC_count, time); goto labRedo; /* ret = true; */ } break; } } if (*sTop != 0) { int v = stack[--(*sTop)]; if (*sTop != 0) { u = stack[(*sTop)-1]; u = getNextNeighbor(remain, nNodes, u, v); } else goto labelReturn; /* return ret; */ } else goto labelReturn; /* return ret; */ } labelReturn: // 显示消去一环的时间消耗 // gettimeofday(&NC_end, NULL); // time = (NC_end.tv_sec-NC_begin.tv_sec)*1000000 + NC_end.tv_usec-NC_begin.tv_usec; // printf("end\t%15.2f\n", time); free(circle); free(preflow); /* return ret; */ }