Issues with compiling Palabos in Mac OS Maverick

Hi there!

I am very impressed by palabos and I am trying to use it for my research. Unfortunately, I am having troubles in compiling any of the tutorials/ examples. I have a mac and running OSX 10.9.5, with Xcode 6.1.1. When compiling I get the error:

palabos-v1.5r0/src/core/plbTimer.cpp:83:23: error:
use of undeclared identifier ‘CLOCK_REALTIME’
clock_gettime(CLOCK_REALTIME, &ts);
^
Is this a known issue? Anyone can help?

Thanks!

Claudio

Dear Claudio,

Thanks for the bug report. It is strange because I think I had compiled Palabos on OSX 10.9.5, but it doesn’t matter…

Could you please replace the file plbTimer.h by:

[code=cpp]

/* This file is part of the Palabos library.
*

  • Copyright © 2011-2015 FlowKit Sarl
  • Route d’Oron 2
  • 1010 Lausanne, Switzerland
  • E-mail contact: contact@flowkit.com
  • The most recent release of Palabos can be downloaded at
  • http://www.palabos.org/
  • The library Palabos is free software: you can redistribute it and/or
  • modify it under the terms of the GNU Affero General Public License as
  • published by the Free Software Foundation, either version 3 of the
  • License, or (at your option) any later version.
  • The 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 Affero General Public License for more details.
  • You should have received a copy of the GNU Affero General Public License
  • along with this program. If not, see http://www.gnu.org/licenses/.
    */

/** \file

  • A timer class for benchmarking program parts – header file.
    */
    #ifndef PLB_TIMER_H
    #define PLB_TIMER_H

#include

#ifdef PLB_USE_POSIX
#include <unistd.h>
#endif

namespace plb {

namespace global {

/// A cumulative timer for benchmarking program parts and summing up the times.
/** In serial, the C function clock() is used. In parallel, the MPI

  • function is used.
    /
    class PlbTimer {
    public:
    PlbTimer();
    /// Proceed with time measurement.
    void start();
    /// Reset timer to zero and start time measurement.
    void restart();
    /// Interrupt time measurement ( you can still proceed with start() ).
    /
    \return Current cumulative time.
    */
    double stop();
    /// Reset timer to zero.
    void reset();
    /// Get current cumulative time.
    double getTime() const;
    private:
    double cumulativeTime;
    bool isOn;
    #ifdef PLB_MPI_PARALLEL
    double startTime;
    #else
    #if defined PLB_USE_POSIX && defined _POSIX_TIMERS && (_POSIX_TIMERS > 0)
    double startTime;
    #else
    clock_t startClock;
    #endif
    #endif
    friend PlbTimer& timer(std::string nameOfTimer);
    friend PlbTimer& plbTimer(std::string nameOfTimer);
    };

// Global instance of timer objects, for public use.
PlbTimer& timer(std::string nameOfTimer);

// Global instance of timer objects, for internal use.
PlbTimer& plbTimer(std::string nameOfTimer);

/// A cumulative counter for benchmarking program parts and summing up occurrences
/// of events.
class PlbCounter {
public:
PlbCounter();
/// Increment the counter.
plint increment(plint value=1);
/// Reset counter to zero.
void reset();
/// Return current count.
plint getCount() const;
private:
plint count;
friend PlbCounter& counter(std::string nameOfCounter);
friend PlbCounter& plbCounter(std::string nameOfCounter);
};

// Global instance of counter objects, for public use.
PlbCounter& counter(std::string nameOfCounter);

// Global instance of counter objects, for internal use.
PlbCounter& plbCounter(std::string nameOfCounter);

} // namespace global

} // namespace plb

#endif // PLB_TIMER_H




And the file plbTimer.cpp by:

[code=cpp]

/* This file is part of the Palabos library.
 *
 * Copyright (C) 2011-2015 FlowKit Sarl
 * Route d'Oron 2
 * 1010 Lausanne, Switzerland
 * E-mail contact: contact@flowkit.com
 *
 * The most recent release of Palabos can be downloaded at 
 * <http://www.palabos.org/>
 *
 * The library Palabos is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * The 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "parallelism/mpiManager.h"
#include "core/plbTimer.h"
#include <map>

#include <ctime>

#ifdef PLB_USE_POSIX
#include <unistd.h>
#endif

namespace plb {

namespace global {

/* ************** Timer ***************************************** */

PlbTimer::PlbTimer()
    : cumulativeTime(0.),
      isOn(false)
{ }

void PlbTimer::start() {
#ifdef PLB_MPI_PARALLEL
    startTime = mpi().getTime();
#else
#if defined PLB_USE_POSIX && defined _POSIX_TIMERS && (_POSIX_TIMERS > 0)
    timespec ts;
    clock_gettime(CLOCK_REALTIME, &ts);
    startTime = (double) ts.tv_nsec * (double) 1.0e-9;
#else
    startClock = clock();
#endif
#endif
    isOn = true;
}

void PlbTimer::restart() {
    reset();
    start();
}

double PlbTimer::stop() {
    cumulativeTime = getTime();
    isOn = false;
    return cumulativeTime;
}

void PlbTimer::reset() {
    cumulativeTime = 0.;
}

double PlbTimer::getTime() const {
    if (isOn) {
#ifdef PLB_MPI_PARALLEL
        return cumulativeTime + mpi().getTime()-startTime;
#else
#if defined PLB_USE_POSIX && defined _POSIX_TIMERS && (_POSIX_TIMERS > 0)
        timespec ts;
        clock_gettime(CLOCK_REALTIME, &ts);
        double endTime = (double) ts.tv_nsec * (double) 1.0e-9;
        return cumulativeTime + endTime-startTime;
#else
        return cumulativeTime + (double)(clock()-startClock)
                              / (double)CLOCKS_PER_SEC;
#endif
#endif
    }
    else {
        return cumulativeTime;
    }
}

PlbTimer& timer(std::string nameOfTimer) {
    static std::map<std::string, PlbTimer> timerCollection;
    return timerCollection[nameOfTimer];
}

PlbTimer& plbTimer(std::string nameOfTimer) {
    static std::map<std::string, PlbTimer> timerCollection;
    PlbTimer& answer=timerCollection[nameOfTimer];
    return answer;
}

/* ************** Timer ***************************************** */

PlbCounter::PlbCounter()
    : count(0)
{ }

plint PlbCounter::increment(plint value) {
    count += value;
    return count;
}

void PlbCounter::reset() {
    count = 0;
}

plint PlbCounter::getCount() const {
    return count;
}

PlbCounter& counter(std::string nameOfCounter) {
    static std::map<std::string, PlbCounter> counterCollection;
    return counterCollection[nameOfCounter];
}

PlbCounter& plbCounter(std::string nameOfCounter) {
    static std::map<std::string, PlbCounter> counterCollection;
    return counterCollection[nameOfCounter];
}

}  // namespace global

}  // namespace plb


and let me know if it works. In case it does we shall include this fix in the next Palabos release.

Thank you very much,
Dimitris

Dear Dimitris,
thank you very much for the quick reply! I have tried but got another error:

g++ -o /Users/***/palabos-v1.5r0/src/core/plbInit.o -c -DPLB_MAC_OS_X -DPLB_USE_POSIX -I/Users/**/palabos-v1.5r0/src -I/Users//palabos-v1.5r0/externalLibraries /Users//palabos-v1.5r0/src/core/plbInit.cpp
/Users/***/palabos-v1.5r0/src/core/plbInit.cpp:41:13: error: no member named ‘plbRandom’ in namespace ‘plb::global’
global::plbRandom().seed(10);

can it be a problem with the compiler? I have tried to reinstall Xcode, but yet no luck. Am I doing something wrong?

Bests

Dear Claudio,

This time I do not understand why you have this error… Look in the file:

src/core/plbInit.cpp

in the beginning, there should be a line:

[code=“cpp”]
#include “core/plbRandom.h”



In my palabos-v1.5r0 this line exists. Can you tell me exactly which code you try to compile. Also, please, give me the version of your g++ compiler.

Thanks a lot,
Dimitris

Hi Dimitris,
yes I have the include in src/core/plbInit.cpp. From previous experience when something like this happens I usually find out that the problem is the compiler:

$ c++ -v
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix
$ g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix
$ llvm-gcc --version
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

I just found out Apple no longer distributes GCC with Xcode. They now use Clang as the default (and only!) compiler on Mac OS X. cc, gcc, and clang (as well as the C++ variants, c++, g++, and clang++) are now all linked to run clang under current versions of Xcode. Can this be the problem?

I appreciate your time and very quick responses.
:slight_smile: Cheers

Hi,

I just compiled several examples from the Palabos distribution on an x86_64-apple-darwin14.1.0 with the same compiler as you. To be on the same page here, can you tell me which specific example in Palabos you try to compile? If it is not too much to ask, can you please post also the Makefile that you use on the command line?

Thanks
Dimitris

Hi Dimitry,
I am compiling the cylinder2D, although the problem is the same with all the cases.

The Makefile is attached. I tried to switch on and off features. I hope I am not doing anything wrong here :stuck_out_tongue:


##########################################################################
## Makefile for the Palabos example program cylinder2d.
##
## The present Makefile is a pure configuration file, in which 
## you can select compilation options. Compilation dependencies
## are managed automatically through the Python library SConstruct.
##
## If you don't have Python, or if compilation doesn't work for other
## reasons, consult the Palabos user's guide for instructions on manual
## compilation.
##########################################################################

# USE: multiple arguments are separated by spaces.
#   For example: projectFiles = file1.cpp file2.cpp
#                optimFlags   = -O -finline-functions

# Leading directory of the Palabos source code
palabosRoot   = ../../..
# Name of source files in current directory to compile and link with Palabos
projectFiles = cylinder2d.cpp

# Set optimization flags on/off
optimize     = true
# Set debug mode and debug flags on/off
debug        = false
# Set profiling flags on/off
profile      = false
# Set MPI-parallel mode on/off (parallelism in cluster-like environment)
MPIparallel  = false
# Set SMP-parallel mode on/off (shared-memory parallelism)
SMPparallel  = false
# Decide whether to include calls to the POSIX API. On non-POSIX systems,
#   including Windows, this flag must be false, unless a POSIX environment is
#   emulated (such as with Cygwin).
usePOSIX     = false

# Path to external libraries (other than Palabos)
libraryPaths =
# Path to inlude directories (other than Palabos)
includePaths =
# Dynamic and static libraries (other than Palabos)
libraries    =

# Compiler to use without MPI parallelism
serialCXX    = g++
# Compiler to use with MPI parallelism
parallelCXX  = mpicxx
# General compiler flags (e.g. -Wall to turn on all warnings on g++)
compileFlags = -DPLB_MAC_OS_X
# General linker flags (don't put library includes into this flag)
linkFlags    =
# Compiler flags to use when optimization mode is on
optimFlags   = -O3
# Compiler flags to use when debug mode is on
debugFlags   = -g
# Compiler flags to use when profile mode is on
profileFlags = -pg


##########################################################################
# All code below this line is just about forwarding the options
# to SConstruct. It is recommended not to modify anything there.
##########################################################################

SCons     = $(palabosRoot)/scons/scons.py -j 2 -f $(palabosRoot)/SConstruct

SConsArgs = palabosRoot=$(palabosRoot) \
            projectFiles="$(projectFiles)" \
            optimize=$(optimize) \
            debug=$(debug) \
            profile=$(profile) \
            MPIparallel=$(MPIparallel) \
            SMPparallel=$(SMPparallel) \
            usePOSIX=$(usePOSIX) \
            serialCXX=$(serialCXX) \
            parallelCXX=$(parallelCXX) \
            compileFlags="$(compileFlags)" \
            linkFlags="$(linkFlags)" \
            optimFlags="$(optimFlags)" \
            debugFlags="$(debugFlags)" \
	    profileFlags="$(profileFlags)" \
	    libraryPaths="$(libraryPaths)" \
	    includePaths="$(includePaths)" \
	    libraries="$(libraries)"

compile:
	python $(SCons) $(SConsArgs)

clean:
	python $(SCons) -c $(SConsArgs)
	/bin/rm -vf `find $(palabosRoot) -name '*~'`


python …/…/…/scons/scons.py -j 2 -f …/…/…/SConstruct palabosRoot=…/…/… projectFiles=“cylinder2d.cpp” optimize=true debug=false profile=false MPIparallel=false SMPparallel=false usePOSIX=false serialCXX=g++ parallelCXX=mpicxx compileFlags="-DPLB_MAC_OS_X" linkFlags="" optimFlags="-O3" debugFlags="-g" profileFlags="-pg" libraryPaths="" includePaths="" libraries=""
scons: Reading SConscript files …
scons: done reading SConscript files.
scons: Building targets …
g++ -o cylinder2d.o -c -DPLB_MAC_OS_X -O3 -I/Users/**/palabos-v1.5r0/src -I/Users//palabos-v1.5r0/externalLibraries cylinder2d.cpp
g++ -o /Users/
/palabos-v1.5r0/src/algorithm/basicAlgorithms.o -c -DPLB_MAC_OS_X -O3 -I/Users/**/palabos-v1.5r0/src -I/Users//palabos-v1.5r0/externalLibraries /Users//palabos-v1.5r0/src/algorithm/basicAlgorithms.cpp

It seems like it can compile most of the routines until it finds the errors:

/Users/***/palabos-v1.5r0/src/core/plbInit.cpp:41:13: error: no member named ‘plbRandom’ in namespace ‘plb::global’
global::plbRandom().seed(10);
~~~~~~~~^
/Users/***/palabos-v1.5r0/src/core/plbInit.cpp:41:28: error: expected ‘(’ for function-style cast or type construction
global::plbRandom().seed(10);
~~~~~^
/Users/***/palabos-v1.5r0/src/core/plbInit.cpp:41:30: error: expected expression
global::plbRandom().seed(10);
^
/Users/***/palabos-v1.5r0/src/core/plbInit.cpp:42:13: error: no member named ‘plbRandom’ in namespace ‘plb::global’
global::plbRandom().seed(10);

am I missing something ?

bump

Replacing the plbTimer.h and plbTimer,cpp file by the ones shown above works for me. While compiling, I see a few warnings but the compilation is successful. (OSX 10.10.5, i.e. Yosemite on a Macbook Pro of 2011)

(by the way, successful with the laters version, i.e. 1.5r1)

upgrading to v1.5r1 and replacing plbTimer.h and plbTimer.ccp worked for me as well. Thanks Dimitris

Yes, I confirm that is working for me as well

Thanks