As suggested in the answer from the following post, I am trying to build my Fortran program using mpif90 with -acc=gpu flag.
Getting started with OpenACC + MPI Fortran program
I was shown the following error:
gfortran: error: unrecognized command line option ‘-acc=gpu’
I don't understand how I can use mpif90 to compile OpenACC parts of the code. Don't I need a compiler like nvfortran to tell the computer about my OpenACC directives in the code? It's so confusing for me to know how I can tell to the computer about both of my mpi and OpenACC parts of the code simultaneously.
I am posting my make file here for reference:
OBJECTS = Main.o Module.o Pre_processing.o boundary_conditions.o \
interpolation.o viscous_fluxes.o
MODULES = Module.mod
CASE = Riemann.f90
# FC= pgfortran
# FFLAG = -acc -fast -mcmodel=medium -ta=tesla:managed -Minfo=accel
# FFLAG = -fast -mcmodel=medium
FC= mpif90
FFLAG = -acc=gpu
output: a.out
a.out: $(MODULES) $(OBJECTS) cases/$(CASE)
$(FC) $(FFLAG) $(OBJECTS) cases/$(CASE) -o a.out
%.o: %.f90
$(FC) $(FFLAG) -c $<
%.mod: %.f90
$(FC) $(FFLAG) -c $<
.PHONY: clean
clean :
rm -f *.o *.mod *.out *.qdrep
I have following compilers installed on my PC which has two Nvidia A6000 GPU cards:
GNU Fortran (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 & nvfortran 21.9-0 64-bit target on x86-64 Linux -tp zen
Related
I am trying to cross compile my hello world app on C from Ubuntu linux for Windows platform. So, to compile the app I am using this Makefile:
CC = g++
IDIR = -Iinclude
SRC = src
CFLAGS = -Wall -Wextra
LFLAGS = -mwindows
main.out: main.o
$(CC) $(CFLAGS) $(IDIR) $(LFLAGS) $^ -o $#
main.o: $(SRC)/main.c
$(CC) $(CFLAGS) $(IDIR) -c -o $# $^
As the result of cmmand make -f windows.mk I have such error:
g++: error: unrecognized command line option ‘-mwindows’
I have already tried gcc and g++. Is there way to compile it without making my own crosscompiler?
To cross compile for windows you would need mingw-w64 or use i686-w64-mingw32-g++
sudo apt-get install mingw-w64 For more info :
https://arrayfire.com/cross-compile-to-windows-from-linux/
Thanks a lot #HolyBlackCat
I've tried to using x86_64-w64-mingw32-g++ instead of just g++ or gcc without -mwindows and it succeed.
I'm building a program for STM32F4 by using GNU-ARM-Gcc and Eclipse_make.exe to build the project. Everything works fine but the diagnostic message show on the terminal when compiling is too long and very hard to see. When each *.c file is compiled, the Terminal gives me a diagnostic message (see the paragraph below) can anyone give me the advice to show just a file name [delete gcc directory path, dependencies, header file path]. The makefile is generated by CubeMX. Here is makefile: https://github.com/loiefy/STM32-makefile/blob/main/Makefile
The example diagnostic message:
C:/Program Files (x86)/GNU Arm Embedded Toolchain/9 2020-q2-update/bin/arm-none-eabi-gcc -c -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32F407xx -IEngine/Src/website_c -IEngine/Inc -ILWIP/Target -IMiddlewares/Third_Party/LwIP/src/include -IMiddlewares/Third_Party/LwIP/system -IDrivers/STM32F4xx_HAL_Driver/Inc -IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy -IMiddlewares/Third_Party/LwIP/src/include/netif/ppp -IMiddlewares/Third_Party/LwIP/src/apps/httpd -IDrivers/CMSIS/Device/ST/STM32F4xx/Include -IMiddlewares/Third_Party/LwIP/src/include/lwip -IMiddlewares/Third_Party/LwIP/src/include/lwip/apps -IMiddlewares/Third_Party/LwIP/src/include/lwip/priv -IMiddlewares/Third_Party/LwIP/src/include/lwip/prot -IMiddlewares/Third_Party/LwIP/src/include/netif -IMiddlewares/Third_Party/LwIP/src/include/posix -IMiddlewares/Third_Party/LwIP/src/include/posix/sys -IMiddlewares/Third_Party/LwIP/system/arch -IDrivers/CMSIS/Include -IDrivers/CMSIS/Include -IEngine/Inc -ILWIP/Target -Og -Wall -fdata-sections -ffunction-sections -fdiagnostics-show-location=every-line -g -gdwarf-2 -MMD -MP -MF"build/mqtt.d" -Wa,-a,-ad,-alms=build/mqtt.lst Middlewares/Third_Party/LwIP/src/apps/mqtt/mqtt.c -o build/mqtt.o
The message I want to show: Middlewares/Third_Party/LwIP/src/apps/mqtt/mqtt.c was compiled
I had spent a day finding the echo command or another command has the same purpose to show the message inside the makefile. But I found nothing.
Thank you for your help
So make by default echo's each line it runs - your compiler line in the makefile:
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $#
Will output the execution line what you can do is:
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
#echo "compiling $<"
#$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $#
Note: the # prefix in make means dont print the command that is being executed. Hence even the echo line needs the # otherwise you would get the echo comping... getting printed as well as compiling ...
You may or may not want to do similar for all of your outputs. I some times conditionally do one or other based on a verbosity flag that can be passed in so that when you really want to see the actual compile line you can....
Two updates - see at the end of this post:
After two sleepless nights I decided (for the very first time) to directly ask for your support.
Problem:
When I try to cross-compile for Raspberry (RPI) a peace of code on my intel ubuntu it leads to the code which ends with a segmentation fault runtime error, when I run it on RPI
The same code compiled directly on the target RPI works just fine. The source code becomes to big to wait for compiling it on the RPI, therefore I wanted to accelerate the compilation on my Ubuntu.
Solution
1) follow the steps from http://elinux.org/RPi_Kernel_Compilation
2) Copy the "rootfs" from my target RPI including /lib /usr /opt
3) modify original project Makefile to point to the target libraries and include
4) enjoy fast compilation
Results:
Failed at the 4th point.
I can compile working kernel, modules and trivial Hello World application
I can compile my project and run it on RPI - it starts but always fails after a while with segmentation fault. Very likely after first use of alsa lib.
Remarks:
I use in my project two external libraries -> -lasound -lconfig++ -lconfig and several own classes in separate files.
This is my standard Makefile, which produces working code on RPI
CCC=g++
CXX=g++
RM=rm -f
WARNINGS=-W -Wall -Waggregate-return \
-Wcast-align -Wcast-qual -Wshadow \
-Wwrite-strings -Wno-unused-variable -Wno-unused-parameter
CPPFLAGS=-c -Wall -O3 -DFIXED_POINT=16 -DDEBUG=1 $(WARNINGS) -DREAL_FASTFIR -DFAST_FILT_UTIL
CFLAGS=-c
LDFLAGS=-g -Wall
LDLIBS=-lasound -lconfig++ -lconfig -lc -lm
SRCS=spectrum.cpp kiss_fft.c kiss_fftr.c oled.cpp mibridge.cpp
//OBJS=$(subst .c,.o,$(SRCS))
OBJS=spectrum.o kiss_fft.o kiss_fftr.o oled.o mibridge.o
all: spectrum
spectrum: $(OBJS)
$(CXX) $(LDFLAGS) -o spectrum $(OBJS) $(LDLIBS)
depend: .depend
.depend: $(SRCS)
rm -f ./.depend
$(CXX) $(CPPFLAGS) $(CFLAGS) -MM $^>>./.depend;
clean:
#touch *
$(RM) $(OBJS)
$(RM) *~ .dependtool
$(RM) spectrum
print-%:
#echo '$*=$($*)'
include .depend
... and this is the (problematic) Makefile I wanted to use for cross compiling:
TOOLCHAIN_PREFIX=$(HOME)/development/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-
SYSROOT=$(HOME)/development/raspberry/rootfs
CROSS_DIR=$(HOME)/development/raspberry/rootfs
CXX = $(TOOLCHAIN_PREFIX)g++
CC = $(TOOLCHAIN_PREFIX)gcc
LD = $(TOOLCHAIN_PREFIX)g++
RM=rm -f
INCLUDEDIR = ./
INCLUDEDIR += $(CROSS_DIR)/usr/include \
$(CROSS_DIR)/usr/include/arm-linux-gnueabihf
LIBRARYDIR= $(CROSS_DIR)/lib \
$(CROSS_DIR)/lib/arm-linux-gnueabihf \
$(CROSS_DIR)/usr/lib/arm-linux-gnueabihf \
$(CROSS_DIR)/opt/vc/lib
XLINK_LIBDIR= $(CROSS_DIR)/lib \
$(CROSS_DIR)/lib/arm-linux-gnueabihf \
$(CROSS_DIR)/usr/lib/arm-linux-gnueabihf \
$(CROSS_DIR)/opt/vc/lib
LIBRARY= asound config++ config
INCDIR = $(patsubst %,-I%,$(INCLUDEDIR))
LIBDIR = $(patsubst %,-L%,$(LIBRARYDIR))
LIB = $(patsubst %,-l%,$(LIBRARY))
XLINKDIR = $(patsubst %,-Xlinker -rpath-link=%,$(XLINK_LIBDIR))
WARNINGS=-W -Wall -Waggregate-return -Wcast-align -Wcast-qual -Wshadow -Wwrite-strings -Wno-unused-variable -Wno-unused-parameter -Wno-sequence-point -Wno-unused-but-set-variable -Wno-cast-align
OPT=-c -Wall -O3 -DFIXED_POINT=16 -DDEBUG=1 -DREAL_FASTFIR -DFAST_FILT_UTIL
OPT += -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s
CFLAGS=-c -mfloat-abi=hard
CXXFLAGS= $(OPT) $(WARNINGS) $(INCDIR)
LDFLAGS= $(LIBDIR) $(LIB) $(XLINKDIR) -lc -lm
SRCS=spectrum.cpp kiss_fft.c kiss_fftr.c oled.cpp mibridge.cpp
OBJS=spectrum.o kiss_fft.o kiss_fftr.o oled.o mibridge.o
all: spectrum
spectrum: $(OBJS)
$(CXX) --sysroot=$(SYSROOT) $(LDFLAGS) $(OBJS) -o spectrum
depend: .depend
.depend: $(SRCS)
rm -f ./.depend
$(CXX) $(CXXFLAGS) $(CFLAGS) -MM $^>>./.depend;
clean:
#touch *
$(RM) $(OBJS)
$(RM) *~ .dependtool
$(RM) spectrum
print-%:
#echo '$*=$($*)'
include .depend
The only difference I can see is the gcc version:
on Ubuntu:
gcc version 4.8.3 20140106 (prerelease) (crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11)*
on RPI:
gcc version 4.6.3 (Debian 4.6.3-14+rpi1)*
However simple "Hello World" and the first dozen of source code lines in my application work fine.
Another observation:
The bin code size on RPI is: 59906
The bin code size from cross is: 121254
Does it look like that the linker mixes something?
EDIT:
adding the results objdump -x
There are some differences, I tried to select in below two dumps:
Segmentation fault executable file has got:
spectrum: file format elf32-little
architecture: UNKNOWN!, flags 0x00000112:
...
Dynamic Section:
...
NEEDED libc.so.6
NEEDED libgcc_s.so.1
...
SYMBOL TABLE:
...
00000000 l d .ARM.attributes 00000000 .ARM.attributes
00000000 l df *ABS* 00000000 /home/peter/development/raspberry/rootfs/usr/lib/arm-linux-gnueabihf/crt1.o
The RPI version has many similarities, but these are some differences I could figure out:
spectrum: file format elf32-littlearm
architecture: arm, flags 0x00000112:
...
Dynamic Section:
...
NEEDED libm.so.6
NEEDED libc.so.6
NEEDED libgcc_s.so.1
NEEDED libpthread.so.0
...
Version References:
...
required from libm.so.6: <---- mising in the cross-compiled version
0x0d696914 0x00 02 GLIBC_2.4
private flags = 5000002: [Version5 EABI] [has entry point]
...
What is even more interesting in the RPI native (working) version there is completely missing reference to
crt1.o, crti.o, crtn.o,
If you suggest any particular entry from objdump, it will help me to find out more useful information.
EDIT 2
As recommended by #yegorich i tried strace and did not found any particular useful hint.
However I tried to debug - just to see where the segmentation comes from.
1. Compile with -g -ggdb
2. Run gdb my application
and the results are as follow:
Program received signal SIGSEGV, Segmentation fault.
0x0000d490 in demux(short*, short*, short*, CONFIG&) () at spectrum.cpp:530
530 if (PrgCfg.Sound_Channels[0] == 'M') {
Nothing particular. The same code runs with natively compiled code without any problems.
I did some changes in the code and the code crashes then in another point - without "any" feasible reason.
Then I added some "debug" printf and one of the variable changed its value, in scope I do nothing with this value. For me a clear signal that the memory has been "damaged" by my code.
Now I have to find where - the worst error ever.
I still do not understand why it does not happen if I compile the code with a native g++.
Any idea?
Any suggestion from your side is very appreciated.
Thank you.
Peter
I am trying to compile a program consisting of two source files:
wildcardtrie.h, wildcardtrie.cpp
using a Makefile. However, when I run GDB to debug, I get the following error:
Reading symbols from /home/meric/Documents/Random/SectionLeading/wildcardtrie...(no debugging symbols found)...done.
I have tried a number of different compiler flags, none of which worked. The thing that perplexes me is that I have used a nearly identical Makefile in other programs and missing symbols has never been a problem. I have included the Makefile below:
CC=g++
CFLAGS = -g -ggdb g++ -O0 -Wall -Wfloat-equal -Wtype-limits -Wpointer-arith -Wlogical- op -fno-diagnostics-show-option
LDFLAGS = -g -ggdb -std=c++0x
programs = wildcardtrie
all : $(programs)
clean:
rm -f $(programs) core *.o
.PHONY: clean all
I have tried removing '-g' and '-ggdb' in the compiler and linker flags, but nothing seems to work. When I call 'make', I get the following output on the terminal:
g++ -c -o wildcardtrie.o wildcardtrie.cpp
g++ -g -ggdb -std=c++0x wildcardtrie.o -o wildcardtrie
Any help would be greatly appreciated!
g++ -c -o wildcardtrie.o wildcardtrie.cpp
This clearly shows that -g is not on your compile line (which is exactly the cause of your problem).
To get -g there, either add it to CXXFLAGS (this is the preferred solution), or just write the compile rule explicitly (instead of relying on built-in make rule):
wildcardtrie.o: wildcardtrie.cpp
$(CC) $(CFLAGS) -o wildcardtrie.o wildcardtrie.cpp
Hi all: quick question: I'm in a situation where it would be useful to generate my C++ executable using only 'gcc' (without g++). Reason for this is that I have to submit the code to an automatic submission server which doesn't recognize the 'g++' (or 'c++', for that matter) command.
In my experiments, while I'm compiling gcc works well. Problem is, when I try to link the generated object files it gets messed up. Now, based on what I understood from the gcc man page (I may be way off, so tell me if I am), g++ is basically gcc, but it links the C++ library.
If this is true, how can I (if possible) explicitly link the C++ library without using the g++ (or c++) command?
EDIT: I'm adding the makefile to better illustrate the problem:
COMPILER = gcc
CFLAGS = -Wall -g -x c++
# MODULE COMPILATION
model: modules/model.h modules/sources/model.cpp
$(COMPILER) $(CFLAGS) -c modules/sources/model.cpp -o obj/model.o
algorithms: modules/algorithms.h modules/sources/algorithms.cpp
$(COMPILER) $(CFLAGS) -c modules/sources/algorithms.cpp -o obj/algorithms.o
io: modules/io.h modules/sources/io.cpp
$(COMPILER) $(CFLAGS) -c modules/sources/io.cpp -o obj/io.o
stopwatch: modules/stopwatch.h modules/sources/stopwatch.cpp
$(COMPILER) $(CFLAGS) -c modules/sources/stopwatch.cpp -o obj/stopwatch.o
# EXECUTABLE GENERATION
exe: model algorithms io stopwatch
$(COMPILER) $(CFLAGS) main.cpp obj/model.o obj/algorithms.o obj/io.o obj/stopwatch.o -o bin/process
# DEFAULT TEST CASE
run: exe
./bin/process -i data/nasa_small.log -a data/nasa_small.access -s data/nasa_small.stack
# CLEANING ROUTINE
clean:
rm -f obj/*
You can link the standard c++ library with the -l flag to gcc:
gcc cplusplus.o -lstdc++ -o myexe
If you run g++ with the "-v" option, it will show what command and options it uses. You should be able to deduce the correct gcc command line from there.