Add/Remove C compiler Flags

15 views
Skip to first unread message

theodor tudose

unread,
Dec 17, 2023, 6:43:12 PM12/17/23
to upc-users
Hello upc-users,

I am fairly new to UPC as I have just started using it for a school project and I was wondering if it would be possible to add or remove certain C compiler flags set when building UPC, as I have encountered some padding issues with a C structure.
I was not able to find an explicit answer on how to add/remove flags, but if I missed one that you are aware of, please feel free to redirect me there.

Thanks

This is upcc (the Berkeley Unified Parallel C compiler), v. 2022.10.0
  (getting remote translator settings...)
----------------------+---------------------------------------------------------
 UPC Runtime          | v. 2022.10.0, built on Dec 17 2023 at 23:50:38
----------------------+---------------------------------------------------------
 UPC-to-C translator  | v. 2.28.4, built on Oct 27 2022 at 22:40:34
                      | host 140-211-168-66-openstack.osuosl.org
                      | linux-powerpc/64
                      | gcc v9.3.0
----------------------+---------------------------------------------------------
 Translator location  | http://upc-translator.lbl.gov/upcc-2022.10.0.cgi
----------------------+---------------------------------------------------------
 networks supported   | smp udp
----------------------+---------------------------------------------------------
 default network      | udp
----------------------+---------------------------------------------------------
 pthreads support     | available (if used, default is 2 pthreads per process)
----------------------+---------------------------------------------------------
 Configured with      | '--with-translator=http://upc-translator.lbl.gov/upcc-2
                      | 022.10.0.cgi' '--with-cflags='
                      | '--prefix=/usr/local/berkeley_upc/opt'
                      | '--with-multiconf-magic=opt'
----------------------+---------------------------------------------------------
 Configure features   | trans_bupc,pragma_upc_code,driver_upcc,runtime_upcr,
                      | gasnet,upc_collective,upc_io,upc_memcpy_async,
                      | upc_memcpy_vis,upc_ptradd,upc_thread_distance,upc_tick,
                      | upc_sem,upc_dump_shared,upc_trace_printf,upc_trace_mask,
                      | upc_local_to_shared,upc_all_free,upc_atomics,pupc,
                      | upc_types,upc_castable,upc_nb,nodebug,notrace,nostats,
                      | nodebugmalloc,nogasp,segment_fast,os_linux,cpu_x86_64,
                      | cpu_64,cc_gnu,packedsptr,upc_io_64
----------------------+---------------------------------------------------------
 Configure id         | theo-GF63 Sun Dec 17 23:46:54 EET 2023 theo
----------------------+---------------------------------------------------------
 Binary interface     | 64-bit x86_64-pc-linux-gnu
----------------------+---------------------------------------------------------
 Runtime interface #  | Runtime supports 3.0 -> 3.14: Translator uses 3.6
----------------------+---------------------------------------------------------
                      |  --- BACKEND SETTINGS (for udp network) ---
----------------------+---------------------------------------------------------
 C compiler           | /usr/bin/gcc
                      |   GNU/11.4.0/11.4.0
                      |   gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 Copyright
                      |   (C) 2021 Free Software Foundation, Inc.
----------------------+---------------------------------------------------------
 C compiler flags     | -O3 --param max-inline-insns-single=35000 --param
                      | inline-unit-growth=10000 --param
                      | large-function-growth=200000 -Wno-array-bounds
                      | -Wno-stringop-overflow -Wno-unused -Wunused-result
                      | -Wno-unused-parameter -Wno-address
----------------------+---------------------------------------------------------
 linker               | /usr/bin/g++
                      |   GNU/11.4.0/11.4.0
                      |   g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 Copyright
                      |   (C) 2021 Free Software Foundation, Inc.
----------------------+---------------------------------------------------------
 linker flags         | -O2 -Wno-array-bounds -Wno-stringop-overflow
                      | -Wno-unused -Wunused-result -Wno-unused-parameter
                      | -Wno-address -L/usr/local/berkeley_upc/opt/lib
                      | -lupcr-udp-seq -lumalloc
                      | -L/usr/local/berkeley_upc/opt/lib -lgasnet-udp-seq
                      | -lamudp -L/usr/lib/gcc/x86_64-linux-gnu/11 -lgcc -lm
----------------------+---------------------------------------------------------

Paul H. Hargrove

unread,
Dec 17, 2023, 8:18:37 PM12/17/23
to theodor tudose, upc-users
Theodor,

Without more detail about your needs, I am left with two possible interpretations of your question.
I'll attempt to answer both.  

The first possibility that comes to mind is that you want every invocation of `gcc` and/or `g++` by `upcc` to include specific options.
If that is the case, then you should specify the options when running the `configure` script by including something like these:
   --with-cflags='-fsomething-special' --with-cxxflags='-fsomething-special'
Alternatively, the `CFLAGS` and `CXXFLAGS` environment variables can be set at configure time.
The use of configure-time environment settings is documented near the end of the "CHOOSING THE BACK-END C and C++ COMPILERS" section of the `INSTALL.TXT` (online here), where the `-q64` flag to IBM's compilers is used as the example.

The other possibility that comes to mind is that you want `upcc` to pass flags to `gcc` or `g++` sometimes but not always.
In that case, I recommend the `-Wc` and `-Wl` options to `upcc`.
Documentation for these options appears in the upcc manpage (online at https://upc.lbl.gov/docs/user/upcc.html)
Example 1: passing `-fno-strict-aliasing` to the compilation stage:
    upcc -Wc,-fno-strict-aliasing ...
Example 2: passing `-fuse-ld=gold` to the link stage:
    upcc -Wl,-fuse-lf=gold ...

One possibility that I've not attempted to address here is that there are issues with structure alignment introduced by the UPC-to-C source-to-source translation step.  If that is your issue, then I suspect there are no options of `gcc` and `g++` to address it, but there is an alternative source-to-source translator you could set up which may.
So, let us know if neither of the options above addresses your issue.

-Paul

--
You received this message because you are subscribed to the Google Groups "upc-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to upc-users+...@lbl.gov.
To view this discussion on the web visit https://groups.google.com/a/lbl.gov/d/msgid/upc-users/67ce34c9-bf73-42cb-a85c-358b6e387ce6n%40lbl.gov.


--
Paul H. Hargrove <PHHar...@lbl.gov>
Pronouns: he, him, his
Computer Languages & Systems Software (CLaSS) Group
Computer Science Department
Lawrence Berkeley National Laboratory
Message has been deleted

Paul H. Hargrove

unread,
Dec 17, 2023, 8:59:08 PM12/17/23
to theodor tudose, upc-users
Theodor,

There is no well-defined mechanism to remove options, but they can be overridden.

If you do not want optimization at all, then passing `-g` to `upcc` is one way to eliminate the use of `-O3`.
However, that will also disable optimizations and add assertions and sanity checks in the runtime libraries, which significantly impacts performance but is very useful for debugging.

If you just want to disable optimization of your code while using optimized runtime libraries, then I recommend passing `-Wc,-O0` to `upcc` restore the `gcc` default of no optimization  Similarly, `-Wc,-O2` passed to `upcc` can be used to lower the level of optimization.

To override `-Wunused-result` one can pass `-Wc,-Wno-unused-result` to `upcc`.

You can use the UPCC_FLAGS environment variables when running `upcc` to make these the default:
   export UPCC_FLAGS="-Wc,-O0 -Wc,-Wno-unused-result"

-Paul

On Sun, Dec 17, 2023 at 5:29 PM theodor tudose <theot...@gmail.com> wrote:
Hello Paul,
Thank you for the prompt answer. What I actually wanted to do was compile the code without some of the existing flags flags. For example if I wanted to not use the -O3 and the -Wunused-result flags, what would be the best approach?
Theodor
Reply all
Reply to author
Forward
Message has been deleted
0 new messages