⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 az_comm.c

📁 并行解法器,功能强大
💻 C
📖 第 1 页 / 共 5 页
字号:
                       &request) != sizeof(int)) {        (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(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_gmax_int *//******************************************************************************//******************************************************************************//******************************************************************************/double AZ_gavg_double(double val, int proc_config[])/*******************************************************************************  Global average of type double.  Author:  =======  Return code:     double, average 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.*******************************************************************************/{  return (AZ_gsum_double(val, proc_config) / proc_config[AZ_N_procs]);} /* AZ_gavg_double *//******************************************************************************//******************************************************************************//******************************************************************************/int AZ_gmin_int(int val, int proc_config[])/*******************************************************************************  Global min of type int.  Author:  =======  Return code:     int, 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 */  int   val2;             /* arriving value to add */  int   cflag;            /* dummy argument for compatability */  int   node, nprocs;  char *yo = "AZ_gmin_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 min 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,                       &request) != sizeof(int)) {        (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(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_gmin_int *//******************************************************************************//******************************************************************************//******************************************************************************/void AZ_gdot_vec(int N, double dots[], double dots2[], int proc_config[])/*******************************************************************************  Author:  =======  Return code:     void  ============  Parameter list:  ===============  N:               Length of vectors 'dots' and 'dots2'.  dots:            On output, AZ_gdot_vec() produces N global sums. Specifically                   dots[i] (on all processors) = dots[i] (on proc 0) +                                                 dots[i] (on proc 1) +                                                      .                                                      .                                                      .                                                 dots[i] (on proc proc_config[                                                          AZ_N_procs])                   for 0 <= i < N .  dots2:           double precision work vector of length N.  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 */  unsigned int   msg_size;/* length of messages */  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   cflag;            /* dummy argument for compatability */  int   i;                /* loop counter */  int   node, nprocs;  char *yo = "AZ_gdot_vec: ";  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++;  }  msg_size = N * sizeof(double);  partner  = node ^ nprocs_small;  if (node+nprocs_small < nprocs) {    /* post receives on the hypercube portion of the machine partition */    if (mdwrap_iread((void *) dots2, msg_size, &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 *) dots, msg_size, 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 *) dots2, msg_size, &partner, &type, &cflag,                     &request) < msg_size) {      (void) fprintf(stderr, "%sERROR on node %d\nmd_wait failed, message "                     "type = %d\n", yo, node, type);      exit(-1);    }    /* sum values */    for (i = 0; i < N; i++) dots[i] += dots2[i];  }  /* 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 *) dots2, msg_size, &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 *) dots, msg_size, 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 *) dots2, msg_size, &partner, &type, &cflag,                       &request) < msg_size) {        (void) fprintf(stderr, "%sERROR on node %d\nmd_wait failed, message "                       "type = %d\n", yo, node, type);        exit(-1);      }      for (i = 0; i < N; i++) dots[i] += dots2[i];    }  }  /* Finally, send message from lower half to upper half. */  partner = node ^ nprocs_small;  if (node & nprocs_small) {    if (mdwrap_iread((void *) dots, msg_size, &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 *) dots, msg_size, 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 *) dots, msg_size, &partner, &type, &cflag,                     &request) < msg_size) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -