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

📄 cartcomm.cc

📁 MPICH是MPI的重要研究,提供了一系列的接口函数,为并行计算的实现提供了编程环境.
💻 CC
📖 第 1 页 / 共 2 页
字号:
    cdims[i] = -1;    ccoords[i] = -1;    cperiods[i] = -1;  }  if (flags[SKIP_IBM21014])    Done("Skipped (IBM 2.1.0.14)");  else if (flags[SKIP_IBM21015])    Done("Skipped (IBM 2.1.0.15)");  else if (flags[SKIP_IBM21016])    Done("Skipped (IBM 2.1.0.16)");  else if (flags[SKIP_IBM21017])    Done("Skipped (IBM 2.1.0.17)");  else {    clonecomm.Get_topo(ndims, dims, periods, coords);    MPI_Cart_get(ccomm, cndims, cdims, cperiods, ccoords);    for(i = 0; i < ndims; i++) {      if(dims[i] != cdims[i]) {	sprintf(msg, "NODE %d - 28) ERROR in clonecomm.Get_topo, dims[%d] = %d, should be %d", my_rank, i, dims[i], cdims[i]);	Fail(msg);      }      if(periods[i] != cperiods[i]) {	sprintf(msg, "NODE %d - 29) ERROR in clonecomm.Get_topo, periods[%d] = %d, should be %d", my_rank, i, periods[i], cperiods[i]);  	Fail(msg);      }      if(coords[i] != ccoords[i]) {	sprintf(msg, "NODE %d - 30) ERROR in clonecomm.Get_topo, coords[%d] = %d, should be %d", my_rank, i, coords[i], ccoords[i]);  	Fail(msg);      }    }    if (clonecomm != MPI::COMM_NULL && clonecomm != MPI::COMM_WORLD) {      clonecomm.Free();      delete &clonecomm;    }  }  Pass(); // Clone  Pass(); // Non-Periodic Topology  if(comm != MPI::COMM_NULL && comm != MPI::COMM_WORLD)    comm.Free();  if(dupcomm != MPI::COMM_NULL && dupcomm != MPI::COMM_WORLD)    dupcomm.Free();  if(mapcomm != MPI::COMM_NULL && mapcomm != MPI::COMM_WORLD)    mapcomm.Free();  if(shiftcomm != MPI::COMM_NULL && shiftcomm != MPI::COMM_WORLD)    shiftcomm.Free();  if(subcomm != MPI::COMM_NULL && subcomm != MPI::COMM_WORLD)    subcomm.Free();  if(ccomm != MPI_COMM_NULL && ccomm != MPI_COMM_WORLD)    MPI_Comm_free(&ccomm);  if(cshiftcomm != MPI_COMM_NULL && cshiftcomm != MPI_COMM_WORLD)    MPI_Comm_free(&cshiftcomm);  Testing("Periodic Topology");  for(i = 0; i < MAXDIMS; i++) {    cdims[i] = 0;    dims[i] = 0;  }  cdims[0] = 2;  dims[0] = 2;  MPI::Compute_dims(comm_size, 2, dims);  MPI_Dims_create(comm_size, 2, cdims);  dims_save0 = dims[0];  dims_save1 = dims[1];  Testing("Create_cart");  for(i = 0; i < MAXDIMS; i++) {    cperiods[i] = 0;    periods[i] = MPI2CPP_FALSE;  }    comm = MPI::COMM_WORLD.Create_cart(2, dims, periods, MPI2CPP_FALSE);  if(comm == MPI::COMM_NULL) {    sprintf(msg, "NODE %d - 31) Create_cart failed, comm == MPI::COMM_NULL.", my_rank);    Fail(msg);  }    MPI_Cart_create(MPI_COMM_WORLD, 2, cdims, cperiods, 0, &ccomm);  if(ccomm == MPI_COMM_NULL) {    sprintf(msg, "NODE %d - 32) The C version used for comparison was not created properly.", my_rank);    Fail(msg);  }    type = -1;  type = comm.Get_topology();  if(type != MPI::CART) {    sprintf(msg, "NODE %d - 33) ERROR in comm.Get_topology, type = %d, should be %d", my_rank, type, MPI::CART);    Fail(msg);  }  Pass(); // Create_cart    mapcomm = MPI::COMM_WORLD.Create_cart(2, dims, periods, MPI2CPP_FALSE);  shiftcomm = MPI::COMM_WORLD.Create_cart(2, dims, periods, MPI2CPP_FALSE);  MPI_Cart_create(MPI_COMM_WORLD, 2, cdims, cperiods, 0, &cshiftcomm);  Testing("Get_dim");    ndims = -1;  cndims = -1;     ndims = comm.Get_dim();  MPI_Cartdim_get(ccomm, &cndims);  if(ndims != cndims) {    sprintf(msg, "NODE %d - 34) ERROR in comm.Get_dim, ndims = %d, should be %d", my_rank, ndims, cndims);    Fail(msg);  }   Pass(); // Get_dim  Testing("Get_topo");  if (flags[SKIP_IBM21014])    Done("Skipped (IBM 2.1.0.14)");  else if (flags[SKIP_IBM21015])    Done("Skipped (IBM 2.1.0.15)");  else if (flags[SKIP_IBM21016])    Done("Skipped (IBM 2.1.0.16)");  else if (flags[SKIP_IBM21017])    Done("Skipped (IBM 2.1.0.17)");  else {    for(i = 0; i < MAXDIMS; i++) {      dims[i] = -1;      coords[i] = -1;      periods[i] = MPI2CPP_FALSE;      cdims[i] = -1;      ccoords[i] = -1;      cperiods[i] = -1;    }        comm.Get_topo(ndims, dims, periods, coords);    MPI_Cart_get(ccomm, cndims, cdims, cperiods, ccoords);    for(i = 0; i < ndims; i++) {      if(dims[i] != cdims[i]) {	sprintf(msg, "NODE %d - 35) ERROR in comm.Get_topo, dims[%d] = %d, should be %d", my_rank, i, dims[i], cdims[i]);	Fail(msg);      }      if(periods[i] != cperiods[i]) {	sprintf(msg, "NODE %d - 36) ERROR in comm.Get_topo, periods[%d] = %d, should be %d", my_rank, i, periods[i], cperiods[i]);  	Fail(msg);      }      if(coords[i] != ccoords[i]) {	sprintf(msg, "NODE %d - 37) ERROR in comm.Get_topo, coords[%d] = %d, should be %d", my_rank, i, coords[i], ccoords[i]);  	Fail(msg);      }    }    Pass(); // Get_topo  }  Testing("Get_cart_rank");    rank = -1;  rank = comm.Get_cart_rank(coords);  if(rank != my_rank) {    sprintf(msg, "NODE %d - 38) ERROR in comm.Get_cart_rank, rank = %d, should be %d",	    my_rank, rank, my_rank);    Fail(msg);  }  Pass(); // Get_cart_rank  Testing("Get_coords");  for(i = 0; i < MAXDIMS; i++) {    coords[i] = -1;    ccoords[i] = -1;  }  comm.Get_coords(rank, ndims, coords);  MPI_Cart_coords(ccomm, rank, cndims, ccoords);  for(i = 0; i < ndims; i++)    if(coords[i] != ccoords[i]) {       sprintf(msg, "NODE %d - 39) ERROR in comm.Get_coords, coords[%d] = %d, should be %d", my_rank, i, coords[i], ccoords[i]);      Fail(msg);    }  Pass(); // Get_coords  Testing("Shift");  dest = -1;  src = -1;  cdest = -1;  csrc = -1;  shiftcomm.Shift(0, 5, src, dest);  MPI_Cart_shift(cshiftcomm, 0, 5, &csrc, &cdest);  if(src != csrc || dest != cdest) {    sprintf(msg, "NODE %d - 40) ERROR in shiftcomm.Shift, src/dest = %d %d, should be %d %d", my_rank, src, dest, csrc, cdest);    Fail(msg);  }  dest = -1;  src = -1;  cdest = -1;  csrc = -1;  shiftcomm.Shift(0, 1, src, dest);  MPI_Cart_shift(cshiftcomm, 0, 1, &csrc, &cdest);  if(my_rank / 2 < 2 && dest != cdest) {    sprintf(msg, "NODE %d - 41) ERROR in shiftcomm.Shift, dest = %d, should be %d", my_rank, dest, cdest);    Fail(msg);  }    if(my_rank / 2 > 0 && src != csrc) {    sprintf(msg, "NODE %d - 42) ERROR in shiftcomm.Shift, src = %d, should be %d", my_rank, src, csrc);    Fail(msg);  }   dest = -1;  src = -1;  cdest = -1;  csrc = -1;  shiftcomm.Shift(1, -1, src, dest);  MPI_Cart_shift(cshiftcomm, 1, -1, &csrc, &cdest);  if(dest != cdest) {    sprintf(msg, "NODE %d - 43) ERROR in shiftcomm.Shift, dest = %d, should be %d", my_rank, dest, cdest);    Fail(msg);  }   if(src != csrc) {    sprintf(msg, "NODE %d - 44) ERROR in shiftcomm.Shift, src = %d, should be %d", my_rank, src, csrc);    Fail(msg);  }  Pass(); // Shift  Testing("Sub");  remain[0] = MPI2CPP_FALSE;  remain[1] = MPI2CPP_TRUE;  for(i = 2; i < MAXDIMS; i++)    remain[i] = MPI2CPP_FALSE;  subcomm = comm.Sub(remain);  size = subcomm.Get_size();  if(size != dims_save1) {    sprintf(msg, "NODE %d - 47) ERROR in subcomm.Sub, size = %d, should be %d", my_rank, size, dims_save1);    Fail(msg);  }  rank = subcomm.Get_rank();  if(rank != my_rank % dims_save1) {    sprintf(msg, "NODE %d - 48) ERROR in subcomm.Sub, rank = %d, should be %d", my_rank, rank, my_rank % dims_save1);    Fail(msg);  }  if(subcomm != MPI::COMM_NULL)    subcomm.Free();  remain[0] = MPI2CPP_TRUE;  remain[1] = MPI2CPP_FALSE;  subcomm = comm.Sub(remain);  size = subcomm.Get_size();  if(size != dims_save0) {    sprintf(msg, "NODE %d - 53) ERROR in subcomm.Sub, size = %d, should be %d", my_rank, size, dims_save0);    Fail(msg);  }    rank = subcomm.Get_rank();  if(rank != my_rank / dims_save1) {    sprintf(msg, "NODE %d - 54) ERROR in subcomm.Sub, rank = %d, should be %d", my_rank, rank, my_rank / dims_save1);    Fail(msg);  }  Pass(); // Sub  Testing("Map");  for(i = 0; i < MAXDIMS; i++) {    dims[i] = -1;    coords[i] = -1;    periods[i] = MPI2CPP_FALSE;    cdims[i] = -1;    ccoords[i] = -1;    cperiods[i] = -1;  }  if (flags[SKIP_IBM21014])    Done("Skipped (IBM 2.1.0.14)");  else if (flags[SKIP_IBM21015])    Done("Skipped (IBM 2.1.0.15)");  else if (flags[SKIP_IBM21016])    Done("Skipped (IBM 2.1.0.16)");  else if (flags[SKIP_IBM21017])    Done("Skipped (IBM 2.1.0.17)");  else {    mapcomm.Get_topo(ndims, dims, periods, coords);    MPI_Cart_get(ccomm, cndims, cdims, cperiods, ccoords);  }  rank = mapcomm.Map(ndims, dims, periods);  MPI_Cart_map(ccomm, cndims, cdims, cperiods, &crank);  if(rank != crank) {    sprintf(msg, "NODE %d - 55) ERROR in mapcomm.Map, rank = %d, should be %d", my_rank, rank, crank);    Fail(msg);  }  Pass(); // Map  Testing("Dup");  dupcomm = comm.Dup();  for(i = 0; i < MAXDIMS; i++) {    dims[i] = -1;    coords[i] = -1;    periods[i] = MPI2CPP_FALSE;    cdims[i] = -1;    ccoords[i] = -1;    cperiods[i] = -1;  }    if (flags[SKIP_IBM21014])    Done("Skipped (IBM 2.1.0.14)");  else if (flags[SKIP_IBM21015])    Done("Skipped (IBM 2.1.0.15)");  else if (flags[SKIP_IBM21016])    Done("Skipped (IBM 2.1.0.16)");  else if (flags[SKIP_IBM21017])    Done("Skipped (IBM 2.1.0.17)");  else {    dupcomm.Get_topo(ndims, dims, periods, coords);    MPI_Cart_get(ccomm, cndims, cdims, cperiods, ccoords);    for(i = 0; i < ndims; i++) {      if(dims[i] != cdims[i]) {	sprintf(msg, "NODE %d - 55) ERROR in dupcomm.Get_topo, dims[%d] = %d, should be %d", my_rank, i, dims[i], cdims[i]);	Fail(msg);      }      if(periods[i] != cperiods[i]) {	sprintf(msg, "NODE %d - 56) ERROR in dupcomm.Get_topo, periods[%d] = %d, should be %d", my_rank, i, periods[i], cperiods[i]);  	Fail(msg);      }      if(coords[i] != ccoords[i]) {	sprintf(msg, "NODE %d - 57) ERROR in dupcomm.Get_topo, coords[%d] = %d, should be %d", my_rank, i, coords[i], ccoords[i]);  	Fail(msg);      }    }  }  Pass(); // Dup  Testing("Clone");  MPI::Cartcomm& clonecomm2 = (MPI::Cartcomm&) comm.Clone();  for(i = 0; i < MAXDIMS; i++) {    dims[i] = -1;    coords[i] = -1;    periods[i] = MPI2CPP_FALSE;    cdims[i] = -1;    ccoords[i] = -1;    cperiods[i] = -1;  }  if (flags[SKIP_IBM21014])    Done("Skipped (IBM 2.1.0.14)");  else if (flags[SKIP_IBM21015])    Done("Skipped (IBM 2.1.0.15)");  else if (flags[SKIP_IBM21016])    Done("Skipped (IBM 2.1.0.16)");  else if (flags[SKIP_IBM21017])    Done("Skipped (IBM 2.1.0.17)");  else {    clonecomm2.Get_topo(ndims, dims, periods, coords);    MPI_Cart_get(ccomm, cndims, cdims, cperiods, ccoords);    for(i = 0; i < ndims; i++) {      if(dims[i] != cdims[i]) {	sprintf(msg, "NODE %d - 58) ERROR in clonecomm.Get_topo, dims[%d] = %d, should be %d", my_rank, i, dims[i], cdims[i]);	Fail(msg);      }      if(periods[i] != cperiods[i]) {	sprintf(msg, "NODE %d - 59) ERROR in clonecomm.Get_topo, periods[%d] = %d, should be %d", my_rank, i, periods[i], cperiods[i]);  	Fail(msg);      }      if(coords[i] != ccoords[i]) {	sprintf(msg, "NODE %d - 60) ERROR in clonecomm.Get_topo, coords[%d] = %d, should be %d", my_rank, i, coords[i], ccoords[i]);  	Fail(msg);      }    }    if (clonecomm2 != MPI::COMM_NULL && clonecomm2 != MPI::COMM_WORLD) {      clonecomm2.Free();      delete &clonecomm2;    }  }  Pass(); // Clone  Pass(); // Periodic Topology  if(comm != MPI::COMM_NULL && comm != MPI::COMM_WORLD)    comm.Free();  if(dupcomm != MPI::COMM_NULL && dupcomm != MPI::COMM_WORLD)    dupcomm.Free();  if(mapcomm != MPI::COMM_NULL && mapcomm != MPI::COMM_WORLD)    mapcomm.Free();  if(shiftcomm != MPI::COMM_NULL && shiftcomm != MPI::COMM_WORLD)    shiftcomm.Free();  if(subcomm != MPI::COMM_NULL && subcomm != MPI::COMM_WORLD)    subcomm.Free();  if(ccomm != MPI_COMM_NULL && ccomm != MPI_COMM_WORLD)    MPI_Comm_free(&ccomm);  if(cshiftcomm != MPI_COMM_NULL && cshiftcomm != MPI_COMM_WORLD)    MPI_Comm_free(&cshiftcomm);}

⌨️ 快捷键说明

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