Exemplo n.º 1
0
int main(int argc, char* argv[])
{
  MPI_Init(NULL, NULL);

  int rank, ranks;
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &ranks);

  lwgrp_ring lev1_ring, lev2_ring;
  lwgrp_logring lev1_logring, lev2_logring;

  lwgrp_ring world_ring;
  lwgrp_ring_build_from_comm(MPI_COMM_WORLD, &world_ring);

  int bin, bins;
  bins = ranks / 2;
  bin  = rank  / 2;
  lwgrp_ring_split_bin_radix(bins, bin, &world_ring, &lev1_ring);

  bin = -1;
  if (rank % 2 == 0) {
    bin = 0;
  }
  lwgrp_ring_split_bin_scan(1, bin, &world_ring, &lev2_ring);

  lwgrp_logring_build_from_ring(&lev1_ring, &lev1_logring);
  lwgrp_logring_build_from_ring(&lev2_ring, &lev2_logring);

  lwgrp_ring new_lev1_ring, new_lev2_ring;
  lwgrp_logring new_lev1_logring, new_lev2_logring;
  split_bin_2level(
    bins, bin,
    &lev1_ring, &lev1_logring, &lev2_ring, &lev2_logring,
    &new_lev1_ring, &new_lev1_logring, &new_lev2_ring, &new_lev2_logring
  );

  MPI_Finalize();

  return 0;
}
Exemplo n.º 2
0
int main (int argc, char* argv[])
{
  int color, key;
  double start, end;
  MPI_Comm newcomm;

  MPI_Init(&argc, &argv);

  int rank, ranks;
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &ranks);

  int size;
  int* members = (int*) malloc(ranks * sizeof(int));

  lwgrp_ring group;
  lwgrp_ring_build_from_comm(MPI_COMM_WORLD, &group);

  lwgrp_ring group_split;
  lwgrp_ring_split_bin(2, (rank%2), &group, &group_split);

  lwgrp_logring logring;
  lwgrp_logring_build_from_ring(&group, &logring);

  int* inbuf  = (int*) malloc(ranks * sizeof(int));
  int* outbuf = (int*) malloc(ranks * sizeof(int));
  int i;
  for (i = 0; i < ranks; i++) {
    inbuf[i]  = rank * ranks + i;
    outbuf[i] = -1;
  }

  lwgrp_logring_barrier(&group, &logring);

  int bcastbuf = rank;
  lwgrp_logring_bcast(&bcastbuf, 1, MPI_INT, 0, &group, &logring);

  lwgrp_logring_allgather_brucks(&rank, members, 1, MPI_INT, &group, &logring);

  lwgrp_logring_alltoall_brucks(inbuf, outbuf, 1, MPI_INT, &group, &logring);

  int sum = -1;
#if MPI_VERSION >= 2 && MPI_SUBVERSION >= 2
  lwgrp_logring_allreduce(&rank, &sum, 1, MPI_INT, MPI_SUM, &group, &logring);
  lwgrp_logring_scan(&rank, &sum, 1, MPI_INT, MPI_SUM, &group, &logring);
  lwgrp_logring_exscan(&rank, &sum, 1, MPI_INT, MPI_SUM, &group, &logring);
#endif

#if 0
  #if MPI_VERSION >= 2 && MPI_SUBVERSION >= 2
  int myval = rank*2 + 1;
  int allval;
  lwgrp_chain_allreduce(&myval, &allval, 1, MPI_INT, MPI_SUM, &group);
  printf("rank=%d input=%d output=%d\n", rank, myval, allval);
  fflush(stdout);

  int ltr_send =  1;
  int rtl_send = -1;
  int ltr_recv = 100;
  int rtl_recv = 100;
  lwgrp_chain_double_exscan(&ltr_send, &ltr_recv, &rtl_send, &rtl_recv, 1, MPI_INT, MPI_SUM, &group);
  printf("rank=%d ltr_send=%d ltr_recv=%d rtl_send=%d rtl_recv=%d\n",
    rank, ltr_send, ltr_recv, rtl_send, rtl_recv
  );
  fflush(stdout);
  #endif
#endif

  lwgrp_ring_free(&group);
  MPI_Finalize();
  return 0;

  int tag1 = 0;
  int tag2 = 1;

  color = 0;
  key = rank;
  start = MPI_Wtime();
  lwgrp_comm_split_members(MPI_COMM_WORLD, color, key, tag1, tag2, &size, members);
  end = MPI_Wtime();
  print_members(1, rank, size, members);
  if (rank == 0) {
    printf("lwgrp_comm_split_members time %f secs\n", end - start);
  }

#if MPI_VERSION >= 2 && MPI_SUBVERSION >= 2
  start = MPI_Wtime();
  lwgrp_comm_split_create(MPI_COMM_WORLD, color, key, tag1, tag2, &newcomm);
  end = MPI_Wtime();
  print_comm(2, rank, newcomm);
  if (newcomm != MPI_COMM_NULL) {
    MPI_Comm_free(&newcomm);
  }
  if (rank == 0) {
    printf("lwgrp_comm_split_create time %f secs\n", end - start);
  }
#endif

  start = MPI_Wtime();
  MPI_Comm_split(MPI_COMM_WORLD, color, key, &newcomm);
  end = MPI_Wtime();
  if (newcomm != MPI_COMM_NULL) {
    MPI_Comm_free(&newcomm);
  }
  if (rank == 0) {
    printf("MPI_Comm_split time %f secs\n", end - start);
  }



  color = 0;
  key = -rank;
  start = MPI_Wtime();
  lwgrp_comm_split_members(MPI_COMM_WORLD, color, key, tag1, tag2, &size, members);
  end = MPI_Wtime();
  print_members(3, rank, size, members);
  if (rank == 0) {
    printf("lwgrp_comm_split_members time %f secs\n", end - start);
  }

#if MPI_VERSION >= 2 && MPI_SUBVERSION >= 2
  start = MPI_Wtime();
  lwgrp_comm_split_create(MPI_COMM_WORLD, color, key, tag1, tag2, &newcomm);
  end = MPI_Wtime();
  print_comm(4, rank, newcomm);
  if (newcomm != MPI_COMM_NULL) {
    MPI_Comm_free(&newcomm);
  }
  if (rank == 0) {
    printf("lwgrp_comm_split_create time %f secs\n", end - start);
  }
#endif

  start = MPI_Wtime();
  MPI_Comm_split(MPI_COMM_WORLD, color, key, &newcomm);
  end = MPI_Wtime();
  if (newcomm != MPI_COMM_NULL) {
    MPI_Comm_free(&newcomm);
  }
  if (rank == 0) {
    printf("MPI_Comm_split time %f secs\n", end - start);
  }


  color = rank;
  key = -rank;
  start = MPI_Wtime();
  lwgrp_comm_split_members(MPI_COMM_WORLD, color, key, tag1, tag2, &size, members);
  end = MPI_Wtime();
  print_members(5, rank, size, members);
  if (rank == 0) {
    printf("lwgrp_comm_split_members time %f secs\n", end - start);
  }

#if MPI_VERSION >= 2 && MPI_SUBVERSION >= 2
  start = MPI_Wtime();
  lwgrp_comm_split_create(MPI_COMM_WORLD, color, key, tag1, tag2, &newcomm);
  end = MPI_Wtime();
  print_comm(6, rank, newcomm);
  if (newcomm != MPI_COMM_NULL) {
    MPI_Comm_free(&newcomm);
  }
  if (rank == 0) {
    printf("lwgrp_comm_split_create time %f secs\n", end - start);
  }
#endif

  start = MPI_Wtime();
  MPI_Comm_split(MPI_COMM_WORLD, color, key, &newcomm);
  end = MPI_Wtime();
  if (newcomm != MPI_COMM_NULL) {
    MPI_Comm_free(&newcomm);
  }
  if (rank == 0) {
    printf("MPI_Comm_split time %f secs\n", end - start);
  }


  color = (rank % 2) ? 0 : MPI_UNDEFINED;
  key = -rank;
  start = MPI_Wtime();
  lwgrp_comm_split_members(MPI_COMM_WORLD, color, key, tag1, tag2, &size, members);
  end = MPI_Wtime();
  print_members(7, rank, size, members);
  if (rank == 0) {
    printf("lwgrp_comm_split_members time %f secs\n", end - start);
  }

#if MPI_VERSION >= 2 && MPI_SUBVERSION >= 2
  start = MPI_Wtime();
  lwgrp_comm_split_create(MPI_COMM_WORLD, color, key, tag1, tag2, &newcomm);
  end = MPI_Wtime();
  print_comm(8, rank, newcomm);
  if (newcomm != MPI_COMM_NULL) {
    MPI_Comm_free(&newcomm);
  }
  if (rank == 0) {
    printf("lwgrp_comm_split_create time %f secs\n", end - start);
  }
#endif

  start = MPI_Wtime();
  MPI_Comm_split(MPI_COMM_WORLD, color, key, &newcomm);
  end = MPI_Wtime();
  if (newcomm != MPI_COMM_NULL) {
    MPI_Comm_free(&newcomm);
  }
  if (rank == 0) {
    printf("MPI_Comm_split time %f secs\n", end - start);
  }


  color = rank % 2;
  key = rank;
  start = MPI_Wtime();
  lwgrp_comm_split_members(MPI_COMM_WORLD, color, key, tag1, tag2, &size, members);
  end = MPI_Wtime();
  print_members(9, rank, size, members);
  if (rank == 0) {
    printf("lwgrp_comm_split_members time %f secs\n", end - start);
  }

#if MPI_VERSION >= 2 && MPI_SUBVERSION >= 2
  start = MPI_Wtime();
  lwgrp_comm_split_create(MPI_COMM_WORLD, color, key, tag1, tag2, &newcomm);
  end = MPI_Wtime();
  print_comm(10, rank, newcomm);
  if (newcomm != MPI_COMM_NULL) {
    MPI_Comm_free(&newcomm);
  }
  if (rank == 0) {
    printf("lwgrp_comm_split_create time %f secs\n", end - start);
  }
#endif

  start = MPI_Wtime();
  MPI_Comm_split(MPI_COMM_WORLD, color, key, &newcomm);
  end = MPI_Wtime();
  if (newcomm != MPI_COMM_NULL) {
    MPI_Comm_free(&newcomm);
  }
  if (rank == 0) {
    printf("MPI_Comm_split time %f secs\n", end - start);
  }


  color = rank / 4;
  key = rank;
  start = MPI_Wtime();
  lwgrp_comm_split_members(MPI_COMM_WORLD, color, key, tag1, tag2, &size, members);
  end = MPI_Wtime();
  print_members(11, rank, size, members);
  if (rank == 0) {
    printf("lwgrp_comm_split_members time %f secs\n", end - start);
  }

#if MPI_VERSION >= 2 && MPI_SUBVERSION >= 2
  start = MPI_Wtime();
  lwgrp_comm_split_create(MPI_COMM_WORLD, color, key, tag1, tag2, &newcomm);
  end = MPI_Wtime();
  print_comm(12, rank, newcomm);
  if (newcomm != MPI_COMM_NULL) {
    MPI_Comm_free(&newcomm);
  }
  if (rank == 0) {
    printf("lwgrp_comm_split_create time %f secs\n", end - start);
  }
#endif

  start = MPI_Wtime();
  MPI_Comm_split(MPI_COMM_WORLD, color, key, &newcomm);
  end = MPI_Wtime();
  if (newcomm != MPI_COMM_NULL) {
    MPI_Comm_free(&newcomm);
  }
  if (rank == 0) {
    printf("MPI_Comm_split time %f secs\n", end - start);
  }


  free(members);

  MPI_Finalize();

  return 0;
}