?? az_comm.c
字號:
for (hbit = 0; (nprocs >> hbit) != 1; hbit++); nprocs_small = 1 << hbit; if (nprocs_small*2 == nprocs) { nprocs_small *= 2; hbit++; } partner = node ^ nprocs_small; if (node+nprocs_small < nprocs) { /* post receives on the hypercube portion of the machine partition */ if (mdwrap_iread((void *) &val2, sizeof(double), &partner, &type, &request)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_iread failed, message " "type = %d\n", yo, node, type); exit(-1); } } else if (node & nprocs_small) { /* * Send messages from the portion of the machine partition "above" the * largest hypercube to the hypercube portion. */ if (mdwrap_write((void *) &val, sizeof(double), partner, type, &cflag)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_write failed, message " "type = %d\n", yo, node, type); exit(-1); } } if (node+nprocs_small < nprocs) { /* wait to receive the messages */ if (mdwrap_wait((void *) &val2, sizeof(double), &partner, &type, &cflag, &request) != sizeof(double)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_wait failed, message " "type = %d\n", yo, node, type); exit(-1); } /* get max value */ if (val2 > val) val = val2; } /* Now do a binary exchange on nprocs_small nodes. */ if (!(node & nprocs_small)) { for (mask = nprocs_small>>1; mask; mask >>= 1) { partner = node ^ mask; if (mdwrap_iread((void *) &val2, sizeof(double), &partner, &type, &request)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_iread failed, message " "type = %d\n", yo, node, type); exit(-1); } if (mdwrap_write((void *) &val, sizeof(double), partner, type, &cflag)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_write failed, message " "type = %d\n", yo, node, type); exit(-1); } if (mdwrap_wait((void *) &val2, sizeof(double), &partner, &type, &cflag, &request) != sizeof(double)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_wait failed, message " "type = %d\n", yo, node, type); exit(-1); } if (val2 > val) val = val2; } } /* Finally, send message from lower half to upper half. */ partner = node ^ nprocs_small; if (node & nprocs_small) { if (mdwrap_iread((void *) &val, sizeof(double), &partner, &type, &request)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_iread failed, message " "type = %d\n", yo, node, type); exit(-1); } } else if (node+nprocs_small < nprocs ) { if (mdwrap_write((void *) &val, sizeof(double), partner, type, &cflag)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_write failed, message " "type = %d\n", yo, node, type); exit(-1); } } if (node & nprocs_small) { if (mdwrap_wait((void *) &val, sizeof(double), &partner, &type, &cflag, &request) != sizeof(double)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_wait failed, message " "type = %d\n", yo, node, type); exit(-1); } } return val;} /* AZ_gmax_double *//******************************************************************************//******************************************************************************//******************************************************************************/double AZ_gmin_double(double val, int proc_config[])/******************************************************************************* Global min of type double. Author: ======= Return code: double, minimum value across all processors. ============ Parameter list: =============== val: Individual processor value. proc_config: Machine configuration. proc_config[AZ_node] is the node number. proc_config[AZ_N_procs] is the number of processors.*******************************************************************************/{ /* local variables */ int type; /* type of next message */ int partner; /* processor I exchange with */ int mask; /* bit pattern identifying partner */ int hbit; /* largest nonzero bit in nprocs */ int nprocs_small; /* largest power of 2 <= nprocs */ double val2; /* arriving value to add */ int cflag; /* dummy argument for compatability */ int node, nprocs; char *yo = "AZ_gmin_double: "; MPI_AZRequest request; /* Message handle */ /**************************** execution begins ******************************/ node = proc_config[AZ_node]; nprocs = proc_config[AZ_N_procs]; type = AZ_sys_msg_type; AZ_sys_msg_type = (AZ_sys_msg_type+1-AZ_MSG_TYPE) % AZ_NUM_MSGS + AZ_MSG_TYPE; /* Find next lower power of 2. */ for (hbit = 0; (nprocs >> hbit) != 1; hbit++); nprocs_small = 1 << hbit; if (nprocs_small*2 == nprocs) { nprocs_small *= 2; hbit++; } partner = node ^ nprocs_small; if (node+nprocs_small < nprocs) { /* post receives on the hypercube portion of the machine partition */ if (mdwrap_iread((void *) &val2, sizeof(double), &partner, &type, &request)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_iread failed, message " "type = %d\n", yo, node, type); exit(-1); } } else if (node & nprocs_small) { /* * Send messages from the portion of the machine partition "above" the * largest hypercube to the hypercube portion. */ if (mdwrap_write((void *) &val, sizeof(double), partner, type, &cflag)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_write failed, message " "type = %d\n", yo, node, type); exit(-1); } } if (node+nprocs_small < nprocs) { /* wait to receive the messages */ if (mdwrap_wait((void *) &val2, sizeof(double), &partner, &type, &cflag, &request) != sizeof(double)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_wait failed, message " "type = %d\n", yo, node, type); exit(-1); } /* get max value */ if (val2 < val) val = val2; } /* Now do a binary exchange on nprocs_small nodes. */ if (!(node & nprocs_small)) { for (mask = nprocs_small>>1; mask; mask >>= 1) { partner = node ^ mask; if (mdwrap_iread((void *) &val2, sizeof(double), &partner, &type, &request)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_iread failed, message " "type = %d\n", yo, node, type); exit(-1); } if (mdwrap_write((void *) &val, sizeof(double), partner, type, &cflag)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_write failed, message " "type = %d\n", yo, node, type); exit(-1); } if (mdwrap_wait((void *) &val2, sizeof(double), &partner, &type, &cflag, &request) != sizeof(double)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_wait failed, message " "type = %d\n", yo, node, type); exit(-1); } if (val2 < val) val = val2; } } /* Finally, send message from lower half to upper half. */ partner = node ^ nprocs_small; if (node & nprocs_small) { if (mdwrap_iread((void *) &val, sizeof(double), &partner, &type, &request)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_iread failed, message " "type = %d\n", yo, node, type); exit(-1); } } else if (node+nprocs_small < nprocs ) { if (mdwrap_write((void *) &val, sizeof(double), partner, type, &cflag)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_write failed, message " "type = %d\n", yo, node, type); exit(-1); } } if (node & nprocs_small) { if (mdwrap_wait((void *) &val, sizeof(double), &partner, &type, &cflag, &request) != sizeof(double)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_wait failed, message " "type = %d\n", yo, node, type); exit(-1); } } return val;} /* AZ_gmin_double *//******************************************************************************//******************************************************************************//******************************************************************************/int AZ_gmax_int(int val, int proc_config[])/******************************************************************************* Global max of type int. Author: ======= Return code: int, maximum value across all processors. ============ Parameter list: =============== val: Individual processor value. proc_config: Machine configuration. proc_config[AZ_node] is the node number. proc_config[AZ_N_procs] is the number of processors.*******************************************************************************/{ /* local variables */ int type; /* type of next message */ int partner; /* processor I exchange with */ int mask; /* bit pattern identifying partner */ int hbit; /* largest nonzero bit in nprocs */ int nprocs_small; /* largest power of 2 <= nprocs */ int val2; /* arriving value to add */ int cflag; /* dummy argument for compatability */ int node, nprocs; char *yo = "AZ_gmax_int: "; MPI_AZRequest request; /* Message handle */ /**************************** execution begins ******************************/ node = proc_config[AZ_node]; nprocs = proc_config[AZ_N_procs]; type = AZ_sys_msg_type; AZ_sys_msg_type = (AZ_sys_msg_type+1-AZ_MSG_TYPE) % AZ_NUM_MSGS + AZ_MSG_TYPE; /* Find next lower power of 2. */ for (hbit = 0; (nprocs >> hbit) != 1; hbit++); nprocs_small = 1 << hbit; if (nprocs_small*2 == nprocs) { nprocs_small *= 2; hbit++; } partner = node ^ nprocs_small; if (node+nprocs_small < nprocs) { /* post receives on the hypercube portion of the machine partition */ if (mdwrap_iread((void *) &val2, sizeof(int), &partner, &type, &request)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_iread failed, message " "type = %d\n", yo, node, type); exit(-1); } } else if (node & nprocs_small) { /* * Send messages from the portion of the machine partition "above" the * largest hypercube to the hypercube portion. */ if (mdwrap_write((void *) &val, sizeof(int), partner, type, &cflag)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_write failed, message " "type = %d\n", yo, node, type); exit(-1); } } if (node+nprocs_small < nprocs) { /* wait to receive the messages */ if (mdwrap_wait((void *) &val2, sizeof(int), &partner, &type, &cflag, &request) != sizeof(int)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_wait failed, message " "type = %d\n", yo, node, type); exit(-1); } /* get max value */ if (val2 > val) val += val2; } /* Now do a binary exchange on nprocs_small nodes. */ if (!(node & nprocs_small)) { for (mask = nprocs_small>>1; mask; mask >>= 1) { partner = node ^ mask; if (mdwrap_iread((void *) &val2, sizeof(int), &partner, &type, &request)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_iread failed, message " "type = %d\n", yo, node, type); exit(-1); } if (mdwrap_write((void *) &val, sizeof(int), partner, type, &cflag)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_write failed, message " "type = %d\n", yo, node, type); exit(-1); } if (mdwrap_wait((void *) &val2, sizeof(int), &partner, &type, &cflag,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -