📄 az_comm.c
字号:
ptr_recv_list = &x[ data_org[AZ_N_internal] + data_org[AZ_N_border] ]; size = sizeof(double); for (n = 0; n < Num_Neighbors; n++) { num_send = Num_Unknowns_Send_Neighbor[n]; num_recv = Num_Unknowns_Recv_Neighbor[n]; message_send_add[n] = (char *) ptr_send_list; message_recv_add[n] = (char *) ptr_recv_list; message_send_length[n] = size * num_send; message_recv_length[n] = size * num_recv; ptr_send_list += num_send; ptr_recv_list += num_recv; }} /* AZ_gather_mesg_info *//******************************************************************************//******************************************************************************//******************************************************************************/int AZ_gsum_int(int val, int proc_config[])/******************************************************************************* Global integer sum. Author: ======= Return code: int, result of global sum. ============ Parameter list: =============== val: Individual processor value to be summed. 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_gsum_int: "; MPI_AZRequest request; /* Message handle */ /*********************** first executable statment *****************/ 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); } /* sum values */ 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, &request) != sizeof(int)) { (void) fprintf(stderr, "%sERROR on node %d\nmd_wait failed, message " "type = %d\n", yo, node, type); exit(-1); } 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(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 < nprocs ) { 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) { if (mdwrap_wait((void *) &val, 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); } } return val;} /* AZ_gsum_int *//******************************************************************************//******************************************************************************//******************************************************************************/#ifndef PUMA_GSUMD /* Only compile the generic gsum_double function in */ /* if the "optimized" gsum_double for PUMA is not */ /* desired. */double AZ_gsum_double(double val, int proc_config[])/******************************************************************************* Global double sum. Author: ======= Return code: double, result of global sum. ============ Parameter list: =============== val: Individual processor value to be summed. 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_gsum_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); } /* sum values */ 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); } 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_gsum_double */#endif /* ifndef PUMA_GSUMD *//******************************************************************************//******************************************************************************//******************************************************************************/double AZ_gmax_double(double val, int proc_config[])/******************************************************************************* Global max of type double. Author: ======= Return code: double, 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 */ double val2; /* arriving value to add */ int cflag; /* dummy argument for compatability */ int node, nprocs; char *yo = "AZ_gmax_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. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -