[Trilinos-Users] strange problem with epetra's didasko example
Williams, Alan B
william at sandia.gov
Fri May 14 12:10:37 MDT 2010
Since Map is a distributed object, you need to not protect the cout statement with 'if(Comm.MyPID()==0)'. All processors need to execute the cout statement.
Alan
From: trilinos-users-bounces at software.sandia.gov [mailto:trilinos-users-bounces at software.sandia.gov] On Behalf Of Mehmet Salih YILDIRIM
Sent: Friday, May 14, 2010 12:01 PM
To: trilinos-users at software.sandia.gov
Subject: [Trilinos-Users] strange problem with epetra's didasko example
Hi all!
Lately I'd been trying to learn the epetra package and I'd been doing some experiments with didasko examples.
I ran the original epetra example<http://trilinos.sandia.gov/packages/docs/dev/packages/didasko/doc/html/epetra_ex2.html> and everyting seemed to be ok. To better understand what's going on, I changed "cout" parts of the examples and put them insde an if statement as follows:
if (Comm.MyPID() == 0)
cout << Map1;
//..
if (Comm.MyPID() == 0)
cout << Map2;
But when I do these changes and try to run the example, I see that it only prints out this:
[proje at science epetra_2]$ mpirun -np 2 ./epetra2
Epetra::Map
Number of Global Elements = 4
Number of Global Points = 4
Maximum of all GIDs = 3
Minimum of all GIDs = 0
Index Base = 0
Constant Element Size = 1
Number of Local Elements = 2
Number of Local Points = 2
Maximum of my GIDs = 1
Minimum of my GIDs = 0
MyPID Local Index Global Index
0 0 0
and it does not return to command prompt, hangs like this. What happens that I cannot see the output only from process number 0?
The commands which I use to compile and run are as follows:
mpic++ epetra2.cpp -oepetra2 -lepetra -lblas
mpirun -np 2 ./epetra2
All of the code epetra2.cpp (my edited version) is as follows:
//
// Didasko Tutorial Package
// Copyright (2005) Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
// Questions about Didasko? Contact Marzio Sala (marzio.sala _AT_ gmail.com<http://gmail.com>)
//
// ***********************************************************************
// @HEADER
// Definition of Epetra_Map objects
#include "Didasko_ConfigDefs.h"
#if defined(HAVE_DIDASKO_EPETRA)
#include "Epetra_ConfigDefs.h"
#ifdef HAVE_MPI
#include "mpi.h"
#include "Epetra_MpiComm.h"
#else
#include "Epetra_SerialComm.h"
#endif
#include "Epetra_Map.h"
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
MPI_Init(&argc, &argv);
Epetra_MpiComm Comm(MPI_COMM_WORLD);
#else
Epetra_SerialComm Comm;
#endif
// global number of points in the map
int NumGlobalPoint = 4;
// create a map given the global number of points (any positive number)
Epetra_Map Map1(NumGlobalPoint,0,Comm);
// Epetra_Map overloads the << operator
if (Comm.MyPID() == 0)
cout << Map1;
// now create a map given the local number of points
int NumMyPoints = Comm.MyPID();
Epetra_Map Map2(-1,NumMyPoints,0,Comm);
if (Comm.MyPID() == 0)
cout << Map2;
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return(EXIT_SUCCESS);
} /* main */
#else
#include <stdlib.h>
#include <stdio.h>
#ifdef HAVE_MPI
#include "mpi.h"
#endif
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
MPI_Init(&argc, &argv);
#endif
puts("Please configure Didasko with:\n"
"--enable-epetra");
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return 0;
}
#endif
Best regards.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://software.sandia.gov/pipermail/trilinos-users/attachments/20100514/c5679bc9/attachment.html
More information about the Trilinos-Users
mailing list