Thread: ignore OpenMP in C++ program on machine without it

  1. #1
    Registered User
    Join Date
    Jan 2009

    ignore OpenMP in C++ program on machine without it


    I want to run a C++ program using OpenMP on several machines. Some of them have OpenMP installed and others don't because their GCC is below version 4.2.x which doesn't support OpenMP. .

    How could I make the Makefile of my program know if a machine has no OpenMP and ask g++ to ignore in my code those "#include omp.h", OpenMP directives (like "#pragma omp parallel ...") and/or library functions (like "tid = omp_get_thread_num();") instead of failing compilation? So that I can run my program without multi-threading on those machines without OpenMP?

    Thanks and regards!
    Last edited by lehe; 08-20-2009 at 06:11 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Pre-defined Compiler Macros
    Use the __GNUC__ macros to ID the compiler version, and conditionally compile accordingly.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2004
    You can look into using autoconf and automake which handle these situations for you. This may be a little overkill if you just have a simple application though.
    bit∙hub [bit-huhb] n. A source and destination for information.

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    OpenMP is designed in such a way that if your compiler doesn't support it, it does nothing and the resulting program behaves correctly. Unless you use OpenMP specific functions like omp_get_num_threads();
    Last edited by abachler; 08-20-2009 at 04:05 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c++ program for ATM machine
    By cplus2x in forum C++ Programming
    Replies: 2
    Last Post: 02-06-2008, 04:35 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

Tags for this Thread