ignore OpenMP in C++ program on machine without it

This is a discussion on ignore OpenMP in C++ program on machine without it within the C++ Programming forums, part of the General Programming Boards category; Hi, I want to run a C++ program using OpenMP on several machines. Some of them have OpenMP installed and ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    159

    ignore OpenMP in C++ program on machine without it

    Hi,

    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    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
    Posts
    3,189
    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.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

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, 03: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, 10: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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21