NS 3 with openmp.

240 views
Skip to first unread message

sandesh d s

unread,
Feb 17, 2016, 1:49:14 PM2/17/16
to ns-3-users
I am new to NS3.

I am trying to use #pragma of openmp in very first program.
I couldn't solve the problem.

I have spent maximum time in this to solve problem. But I couldn't . Any help will be much appreciated. Thanks in advance.
#include <omp.h>
#include <iostream>
using namespace std;
using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");

int
main (int argc, char *argv[])
{
  //cout <<omp_get_thread_num() << omp_get_num_threads() <<endl;
  #pragma omp parallel 
for (int i=0; i<5;i++){
for (int j=0;j<5;j++){
int k;
k=i+j;
}
.......}

But I end up getting error:

Log:
s-3.24.1$ CCFLAGS_EXTRA="-fopenmp" ./waf build  scratch/first
Waf: Entering directory `/home/dhawasks/Project/ns3/ns-allinone-3.24.1/ns-3.24.1/build'
[2419/2481] Linking build/scratch/first
scratch/first.cc.1.o: In function `main':
first.cc:(.text+0xdd): undefined reference to `GOMP_parallel_start'
first.cc:(.text+0xee): undefined reference to `GOMP_parallel_end'
collect2: error: ld returned 1 exit status

Waf: Leaving directory `/home/dhawasks/Project/ns3/ns-allinone-3.24.1/ns-3.24.1/build'
Build failed
 -> task in 'first' failed (exit status 1): 
{task 3062160076L: cxxprogram first.cc.1.o -> first}
['/usr/bin/g++', '-pthread', '-pthread', 'scratch/first.cc.1.o', '-o', '/home/dhawasks/Project/ns3/ns-allinone-3.24.1/ns-3.24.1/build/scratch/first', '-Wl,-Bstatic', '-Wl,-Bdynamic', '-Wl,--no-as-needed', '-L.', '-lns3.24.1-test-debug', '-lns3.24.1-lr-wpan-debug', '-lns3.24.1-netanim-debug', '-lns3.24.1-lte-debug', '-lns3.24.1-spectrum-debug', '-lns3.24.1-antenna-debug', '-lns3.24.1-aodv-debug', '-lns3.24.1-dsr-debug', '-lns3.24.1-mesh-debug', '-lns3.24.1-visualizer-debug', '-lns3.24.1-wave-debug', '-lns3.24.1-wifi-debug', '-lns3.24.1-applications-debug', '-lns3.24.1-csma-layout-debug', '-lns3.24.1-dsdv-debug', '-lns3.24.1-flow-monitor-debug', '-lns3.24.1-wimax-debug', '-lns3.24.1-nix-vector-routing-debug', '-lns3.24.1-olsr-debug', '-lns3.24.1-point-to-point-layout-debug', '-lns3.24.1-sixlowpan-debug', '-lns3.24.1-tap-bridge-debug', '-lns3.24.1-internet-debug', '-lns3.24.1-bridge-debug', '-lns3.24.1-point-to-point-debug', '-lns3.24.1-mpi-debug', '-lns3.24.1-buildings-debug', '-lns3.24.1-config-store-debug', '-lns3.24.1-propagation-debug', '-lns3.24.1-uan-debug', '-lns3.24.1-mobility-debug', '-lns3.24.1-energy-debug', '-lns3.24.1-csma-debug', '-lns3.24.1-fd-net-device-debug', '-lns3.24.1-virtual-net-device-debug', '-lns3.24.1-topology-read-debug', '-lns3.24.1-network-debug', '-lns3.24.1-stats-debug', '-lns3.24.1-core-debug', '-lrt', '-lgsl', '-lgslcblas', '-lm', '-lsqlite3', '-lgtk-x11-2.0', '-lgdk-x11-2.0', '-latk-1.0', '-lgio-2.0', '-lpangoft2-1.0', '-lpangocairo-1.0', '-lgdk_pixbuf-2.0', '-lcairo', '-lpango-1.0', '-lfontconfig', '-lgobject-2.0', '-lglib-2.0', '-lfreetype', '-lxml2']
dhawasks@ubuntu:~/Project/ns3/ns-allinone-3.24.1/ns-3.24.1$ 

pdbarnes

unread,
Feb 17, 2016, 9:41:25 PM2/17/16
to ns-3-users
I think compiler flags have to be given during configuration:

$ CCFLAGS_EXTRA="-fopenmp" ./waf configure ...
$ ./waf build

sandesh d s

unread,
Feb 17, 2016, 10:45:52 PM2/17/16
to ns-3-users
I tried with it still no help:
Steps:

CCFLAGS_EXTRA="-fopenmp" ./waf configure ...
./waf build

CCFLAGS_EXTRA="-fopenmp" ./waf configure ...
CCFLAGS_EXTRA="-fopenmp" ./waf build

I even tried with CXX instead of CC . Still no luck.
Log:
dhawasks@ubuntu:~/Project/ns3/ns-allinone-3.24.1/ns-3.24.1$ CXXFLAGS_EXTRA="-fopenmp" ./waf build 
Waf: Entering directory `/home/dhawasks/Project/ns3/ns-allinone-3.24.1/ns-3.24.1/build'
[1815/1837] Linking build/scratch/first
scratch/first.cc.1.o: In function `main':
/home/dhawasks/Project/ns3/ns-allinone-3.24.1/ns-3.24.1/build/../scratch/first.cc:31: undefined reference to `GOMP_parallel_start'
/home/dhawasks/Project/ns3/ns-allinone-3.24.1/ns-3.24.1/build/../scratch/first.cc:33: undefined reference to `GOMP_parallel_end'
collect2: error: ld returned 1 exit status

Waf: Leaving directory `/home/dhawasks/Project/ns3/ns-allinone-3.24.1/ns-3.24.1/build'
Build failed
 -> task in 'first' failed (exit status 1): 
{task 3064207532L: cxxprogram first.cc.1.o -> first}
['/usr/bin/g++', '-pthread', '-pthread', 'scratch/first.cc.1.o', '-o', '/home/dhawasks/Project/ns3/ns-allinone-3.24.1/ns-3.24.1/build/scratch/first', '-Wl,-Bstatic', '-Wl,-Bdynamic', '-Wl,--no-as-needed', '-L.', '-lns3.24.1-test-debug', '-lns3.24.1-lr-wpan-debug', '-lns3.24.1-netanim-debug', '-lns3.24.1-lte-debug', '-lns3.24.1-spectrum-debug', '-lns3.24.1-antenna-debug', '-lns3.24.1-aodv-debug', '-lns3.24.1-dsr-debug', '-lns3.24.1-mesh-debug', '-lns3.24.1-visualizer-debug', '-lns3.24.1-wave-debug', '-lns3.24.1-wifi-debug', '-lns3.24.1-applications-debug', '-lns3.24.1-csma-layout-debug', '-lns3.24.1-dsdv-debug', '-lns3.24.1-flow-monitor-debug', '-lns3.24.1-wimax-debug', '-lns3.24.1-nix-vector-routing-debug', '-lns3.24.1-olsr-debug', '-lns3.24.1-point-to-point-layout-debug', '-lns3.24.1-sixlowpan-debug', '-lns3.24.1-tap-bridge-debug', '-lns3.24.1-internet-debug', '-lns3.24.1-bridge-debug', '-lns3.24.1-point-to-point-debug', '-lns3.24.1-mpi-debug', '-lns3.24.1-buildings-debug', '-lns3.24.1-config-store-debug', '-lns3.24.1-propagation-debug', '-lns3.24.1-uan-debug', '-lns3.24.1-mobility-debug', '-lns3.24.1-energy-debug', '-lns3.24.1-csma-debug', '-lns3.24.1-fd-net-device-debug', '-lns3.24.1-virtual-net-device-debug', '-lns3.24.1-topology-read-debug', '-lns3.24.1-network-debug', '-lns3.24.1-stats-debug', '-lns3.24.1-core-debug', '-lrt', '-lgsl', '-lgslcblas', '-lm', '-lsqlite3', '-lgtk-x11-2.0', '-lgdk-x11-2.0', '-latk-1.0', '-lgio-2.0', '-lpangoft2-1.0', '-lpangocairo-1.0', '-lgdk_pixbuf-2.0', '-lcairo', '-lpango-1.0', '-lfontconfig', '-lgobject-2.0', '-lglib-2.0', '-lfreetype', '-lxml2']
dhawasks@ubuntu:~/Project/ns3/ns-allinone-3.24.1/ns-3.24.1$ 

Tom Henderson

unread,
Feb 17, 2016, 11:00:01 PM2/17/16
to ns-3-...@googlegroups.com
On 02/17/2016 07:45 PM, sandesh d s wrote:
> I tried with it still no help:
> Steps:
> CCFLAGS_EXTRA="-fopenmp" ./waf configure ...
> ./waf build

perhaps try to link also with '-lgomp' (add it to your LINKFLAGS)?

- Tom

sandesh d s

unread,
Feb 18, 2016, 3:35:35 AM2/18/16
to ns-3-users
No luck.
Tried it like this: CCFLAGS_EXTRA="-fopenmp" LINKFLAGS_EXTRA="-lgomp" ./waf build  scratch/first

It cant even recognize #pragma

Peter Barnes

unread,
Feb 18, 2016, 8:13:44 PM2/18/16
to sandes...@gmail.com, ns-3-...@googlegroups.com, NS developers mailing list
[Adding ns-3-dev list; see below]

@sandesh:  Perhaps use ./waf —verbose to see the actual compilation and link commands, to help diagnose your issue with OpenMP.


I checked wscript and waf.  The correct way seems to be at configure, using these environment variables:

CCFLAGS_EXTRA added to CCFLAGS, used in compiling C
CXXFLAGS_EXTRA added to CXXFLAGS, using in compiling C++ and C
LINKFLAGS_EXTRA added to LINKFLAGS, which is at front of link command
LDFLAGS_EXTRA added to LDFLAGS, which is at end of link command

CCFLAGS doesn't seem to be use directly by any compile commands.  C compilation uses CFLAGS.  There is some mucking about  in .waf-1.8.16…/waflib/extras/compat15.py:
  - change CCFLAGS to CFLAGS
  - warn that attribute ccflags was renamed to cflags

Meanwhile our top level wscript uses CCFLAGS…

@ns-3-dev:  perhaps for clarity we should update wscript to use CFLAGS directly?

Peter

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/Mcq6G3Ms91I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.

____________
Peter Barnes
pd...@mac.com

sandesh d s

unread,
Feb 18, 2016, 9:08:43 PM2/18/16
to Peter Barnes, ns-3-...@googlegroups.com, NS developers mailing list
Thanks a loot. I will try this out and update .

Thanks again. :).

--
Regards and Thanks
 
Sandes D S

sandesh d s

unread,
Feb 18, 2016, 10:48:06 PM2/18/16
to ns-3-users, pd...@mac.com, ns-dev...@isi.edu
Thank you so much Peter. It worked.
To unsubscribe from this group and all its topics, send an email to ns-3-users+unsubscribe@googlegroups.com.

To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.

____________
Peter Barnes
pd...@mac.com

Reply all
Reply to author
Forward
0 new messages