Scheduled Downtime
On Tuesday 24 October 2023 @ 5pm MT the forums will be in read only mode in preparation for the downtime. On Wednesday 25 October 2023 @ 5am MT, this website will be down for maintenance and expected to return online later in the morning.
Normal Operations
The forums are back online with normal operations. If you notice any issues or errors related to the forums, please reach out to help@ucar.edu

compiler flags

sachinP

Sachin Patade
New Member
I have added one fortran routine to cesm which need to be compiled with special flag `python3-config --ldflags --embed`. I am using this routine to call some python function using c interface.
Where I can modify the compilation option in cesm?
Can I compile this FORTRAN module with mentioned python flags with rest of model code?
 

jedwards

CSEG and Liaisons
Staff member
Yes you can. Create a new dependency file or add to an existing one. The following Dependency file names are supported:
$(CASEROOT)/Depends.$(COMPILER) $(CASEROOT)/Depends.$(MACH) $(CASEROOT)/Depends.$(MACH).$(COMPILER)

The location of this file depends on the cesm version you have - in cesm 2.1 its in cime/config/cesm/machines, in cesm23 it's in
ccs_config/machines. You should be able to determine the format by examining one of the existing files.
 

sachinP

Sachin Patade
New Member
Hi,

I need to compile one of the module in cesm 'crm_physics.F90' by linking it with object file of another module forpy_mod.F90
In short I need to execute following command to compile crm_physics.F90

ifort -c crm_physics.F90 forpy_mod.o `python3-config --ldflags --embed`

I have created my own Depend file that I have attached here where I have added extra compilation flags.

However model is not able to compile. I have attached the compilation log file here.
It looks like I am not able to link crm_physics.F90 with forpy_mod. I will appreciate your help in this regards.


Thanks in advance,
Sachin
 

sachinP

Sachin Patade
New Member
Hi,
I am not able to attache the files. After attache files when I try to post rthe eply I could not see the attachment.
 

jedwards

CSEG and Liaisons
Staff member
The error message should be clear - typically you need to add a .txt to the end of the file name.
 

sachinP

Sachin Patade
New Member
Please see attached built log file and other files that I mentioned earlier.
 

Attachments

  • builtlog.txt
    324 KB · Views: 5
  • crm_physics.txt
    131.3 KB · Views: 2
  • builtlog.txt
    324 KB · Views: 2
  • DependssachinP.txt
    252 bytes · Views: 2

jedwards

CSEG and Liaisons
Staff member
So it looks like the compile of the forpy_mod is fine but you aren't linking the python routines you need at the end.
I think that the `python3-config --ldflags --embed` needs to be added to the LDFLAGS and doesn't need to be in
Depends where you have it.
 

sachinP

Sachin Patade
New Member
Yes. I agree.
Can you please tell me in which file LDFLAG is set in general?
Do I need to set it for specific file crm_physcs.F90?

Thanks
 

jedwards

CSEG and Liaisons
Staff member
LDFLAGS is set for the link step (the final step of building the model) You didn't mention which model version you are using,
for cesm2.1 you would set it in config_compilers.xml, for cesm2.3 you set it in ccs_config/machines/cmake_macros
 

sachinP

Sachin Patade
New Member
Thank you for suggestion.
I tried to change the ldflag in config_compilers.xml file. I made changes in the following part of the file

<compiler COMPILER="intel">
<CFLAGS>
<base> -qno-opt-dynamic-align -fp-model precise -std=gnu99 </base>
<append compile_threaded="TRUE"> -qopenmp </append>
<append DEBUG="FALSE"> -O2 -debug minimal </append>
<append DEBUG="TRUE"> -O0 -g </append>
</CFLAGS>
<CPPDEFS>
<!-- Intel Developer Zone -->
<append> -DFORTRANUNDERSCORE -DCPRINTEL</append>
</CPPDEFS>
<CXX_LDFLAGS>
<base> -cxxlib </base>
</CXX_LDFLAGS>
<base> -lpython3.8 </base> ###(I changed the flag here)


I am using -lpython3.8 for linking with python. However, with this change I am still getting similar error in built.

Is there anything wrong with my changes with ldflag. I have also tried the flag `python3-config --ldflags --embed`

Thank you.
 

jedwards

CSEG and Liaisons
Staff member
When I run `python3-config --ldflags --embed` on my system I get:
-L/glade/work/jedwards/conda/cheyenne/lib/python3.9/config-3.9-x86_64-linux-gnu -L/glade/work/jedwards/conda/cheyenne/lib -lpython3.9 -lcrypt -lpthread -ldl -lutil -lrt -lm

Do you get something similar? Your config_compilers.xml should look something like:
<LDFLAGS>
<append>-L/glade/work/jedwards/conda/cheyenne/lib/python3.9/config-3.9-x86_64-linux-gnu -L/glade/work/jedwards/conda/cheyenne/lib -lpython3.9 -lcrypt -lpthread -ldl -lutil -lrt -lm </append>
</LDFLAGS>
 

sachinP

Sachin Patade
New Member
when I run `python3-config --ldflags --embed` on my machine I get
-L/usr/lib/python3.8/config-3.8-x86_64-linux-gnu -L/usr/lib -lpython3.8 -lcrypt -lpthread -ldl -lutil -lm -lm
which looks similar to what you have on your system.
I added LDFLAG as
<LDFLAGS>
<append> -L/usr/lib/python3.8/config-3.8-x86_64-linux-gnu -L/usr/lib -lpython3.8 -lcrypt -lpthread -ldl -lutil -lm -lm </append>
</LDFLAGS>

in config_compiles.xml file but problem persists with same error.
 
Top