int main(int argc, char *argv[]) { int temp1 = 2; int temp2 = 4; int *m = &temp1; int *n = &temp2; printf("Before: m = %d, n = %d\n", *m, *n); /* exchangeTwoNumber(m, n); */ exchange2(temp1, temp2); printf("After: m = %d, n = %d\n", *m, *n); }
/********************************************************** 主函数 **********************************************************/ void main(void) { P0=0xff; P2=0xff; n=0; num = 0; shift=0x7f; //位码初值 T2CON = 0x00; //设置T2CON寄存器 TH2 = 0xfc; //1ms定时 TL2 = 0x66; ET2 = 1; //启用Timer2中断 EA = 1; //总中断允许 TR2 = 1; //启动定时器2 while(1) { init_data(); while(num<8) { exchange1(); //数据交换 delayms(500); //调整移动速度 num++; //计数值加1 } num = 0; //清计数单元 delayms(1000); //调整停留速度 while(num<8) { exchange2(); //数据交换 delayms(500); //调整移动速度 num++; //计数值加1 } num = 0; //清计数单元 } }
int main (int argc, char **argv) { int r_bufid, info, bytes, msgtag, parent, endofprocess = 0; heur_prob *p = (heur_prob *) calloc(1, sizeof(heur_prob)); parent = receive(p); printf("\nWelcome, I am task %i\n\n", pvm_mytid()); while(!endofprocess){ printf("\nim gonna try to receive at parallel_process.\n"); PVM_FUNC(r_bufid, pvm_recv(-1, -1)); PVM_FUNC(info, pvm_bufinfo(r_bufid, &bytes, &msgtag, &parent)); printf("\nim still in parallel_process\n"); switch(msgtag){ case S_EXCHANGE: exchange(parent, p); break; case S_EXCHANGE2: exchange2(parent, p); break; case S_FARNEAR_INS: farnear_ins(parent, p); break; case S_FARTHEST_INS: farthest_ins(parent, p); break; case S_MST: mst(); break; case S_NEAREST_INS: nearest_ins(parent, p); break; case S_NEAR_CLUSTER: near_cluster(parent, p); break; case S_SAVINGS: savings(parent, p); break; case S_SAVINGS2: savings2(parent, p); break; case S_SAVINGS3: savings3(parent, p); break; case S_SWEEP: sweep(parent, p); break; case S_TSP_FI: tsp_fi(parent, p); break; case S_TSP_FINI: tsp_fini(parent, p); break; case S_TSP_NI: tsp_ni(parent, p); break; case STOP: endofprocess = 1; } } return 0; }