/****************************************************************************
**  SCALASCA    http://www.scalasca.org/                                   **
*****************************************************************************
**  Copyright (c) 1998-2012                                                **
**  Forschungszentrum Juelich GmbH, Juelich Supercomputing Centre          **
**                                                                         **
**  Copyright (c) 2003-2008                                                **
**  University of Tennessee, Innovative Computing Laboratory               **
**                                                                         **
**  See the file COPYRIGHT in the package base directory for details       **
****************************************************************************/

#include <mpi.h>
#include <stdio.h>
#include <unistd.h>
#include "elg_pform.h"

int main(int argc, char *argv[]) {
  int rank, numranks;
  ELG_HW_TOPOL* top;
  char buf[1024];

  MPI_Init(&argc, &argv);
  MPI_Comm_size(MPI_COMM_WORLD, &numranks);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);

  elg_pform_init();
  top = elg_pform_hw_topol();
  if ( rank==0 ) {
    printf("platform    : %s\n", elg_pform_name());
    printf("nodes x CPUs: %u x %u\n", elg_pform_num_nodes(), elg_pform_num_cpus());
    if ( top ) {
      printf("topology    : %u%c x %u%c x %u%c\n", 
           top->xsize, (top->xperiod ? '*' : ' '),
           top->ysize, (top->yperiod ? '*' : ' '),
           top->zsize, (top->zperiod ? '*' : ' '));
    }
  }
  MPI_Barrier(MPI_COMM_WORLD);

  if ( top ) {
    sprintf(buf, "%s [%lu] R%05d <%5u,%5u,%5u>\n", 
            elg_pform_node_name(), elg_pform_node_id(), rank,
            top->xcoord, top->ycoord, top->zcoord);
  } else {
    sprintf(buf, "%s [%lu] R%05d", elg_pform_node_name(), elg_pform_node_id(),
	    rank);
  }
  puts(buf);

  MPI_Finalize();
  return 0;
}
