/*============================================================================
 * Unit test for fvm_interface.c;
 *============================================================================*/

/*
  This file is part of the "Finite Volume Mesh" library, intended to provide
  finite volume mesh and associated fields I/O and manipulation services.

  Copyright (C) 2006  EDF

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include <stdlib.h>

#include <bft_error.h>
#include <bft_mem.h>
#include <bft_printf.h>

#include "fvm_interface.h"
#include "fvm_parall.h"

int
main (int argc, char *argv[])
{
  fvm_lnum_t n_elements = 20;
  fvm_interface_set_t *ifset = NULL;

#if defined(FVM_HAVE_MPI)

  int ii;
  MPI_Status status;

  int sync = 1;
  int rank = -1, size = 0;

  fvm_gnum_t *global_number = NULL;

  /* Initialization */

  MPI_Init(&argc, &argv);

  fvm_parall_set_mpi_comm(MPI_COMM_WORLD);

  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &size);

  /* Build arbitrary interface */

  n_elements = 20;
  BFT_MALLOC(global_number, n_elements, fvm_gnum_t);

  for (ii = 0; ii < n_elements; ii++) {
    global_number[ii] = (n_elements * 3 / 4) * rank + ii + 1;
  }

  ifset = fvm_interface_set_create(n_elements,
                                   NULL,
                                   global_number);

  BFT_FREE(global_number);

  /* Serialize dump of interfaces */

  if (rank > 0)
    MPI_Recv(&sync, 1, MPI_INT, rank - 1, 0, MPI_COMM_WORLD, &status);

  bft_printf("Interface on rank %d:\n\n", rank);

  fvm_interface_set_dump(ifset);

  if (rank < size - 1)
    MPI_Send(&sync, 1, MPI_INT, rank + 1, 0, MPI_COMM_WORLD);

  /* We are finished */

  ifset = fvm_interface_set_destroy(ifset);

  MPI_Finalize();

#endif

  exit (EXIT_SUCCESS);
}


syntax highlighted by Code2HTML, v. 0.9.1