Ocean Modeling Discussion

ROMS/TOMS

Search for:
It is currently Wed Oct 17, 2018 4:24 am




Post new topic Reply to topic  [ 7 posts ] 

All times are UTC

Author Message
PostPosted: Mon Feb 05, 2018 9:21 am 
Offline

Joined: Wed Feb 01, 2017 2:40 pm
Posts: 14
Location: University of Naples - Federico II
Hello,

I want to add a C function (to compute the resident set size memory used by ROMS) in the compiling process. I need to compile the object C file together the object fortran files.

This part in the makefile (line 185)?
Code:
#--------------------------------------------------------------------------
#  Set Pattern rules.
#--------------------------------------------------------------------------

%.o: %.F

%.o: %.f90
    cd $(SCRATCH_DIR); $(FC) -c $(FFLAGS) $(notdir $<)

%.f90: %.F
    $(CPP) $(CPPFLAGS) $(MY_CPP_FLAGS) $< > $*.f90
    $(CLEAN) $*.f90


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 05, 2018 4:38 pm 
Offline
User avatar

Joined: Wed Jul 02, 2003 5:29 pm
Posts: 3515
Location: IMS/UAF, USA
I needed to add a C function for the waves-in-a-circle problem. I believe the chunk of makefile you show does nothing at all. It's all in the functions. I added these to https://github.com/kshedstrom/roms/blob/kate_svn/makefile:
Code:
  c_sources  :=

Code:
# $(call source-to-object, source-file-list)
c-source-to-object = $(call source-dir-to-binary-dir,       \
                     $(subst .c,.o,$(filter %.c,$1))        \
                     $(subst .cc,.o,$(filter %.cc,$1)))

# $(call make-c-library, library-name, source-file-list)
define make-c-library
   libraries += $(SCRATCH_DIR)/$1
   c_sources += $2

   $(SCRATCH_DIR)/$1: $(call source-dir-to-binary-dir,    \
                      $(subst .c,.o,$(filter %.c,$2))     \
                      $(subst .cc,.o,$(filter %.cc,$2)))
        $(AR) $(ARFLAGS) $$@ $$^
        $(RANLIB) $$@
endef

# $(call one-c-compile-rule, binary-file, source-file)
define one-c-compile-rule
  $1: $2
        cd $$(SCRATCH_DIR); $$(CXX) -c $$(CXXFLAGS) $$<

endef
Then in your compilers file you also need:
Code:
               CC := gcc
              CXX := g++
           CFLAGS :=
         CXXFLAGS :=

Code:
ifdef USE_DEBUG
           FFLAGS += -g -fbounds-check
           CFLAGS += -g
         CXXFLAGS += -g
else
           FFLAGS += -O3 -ffast-math
           CFLAGS += -O3
         CXXFLAGS += -O3
endif
Finally, you need to invoke the compiling of your C code. I forget how we did that before. It was for the Hong Kong workshop, files which are no longer being served by ARSC with the demise of ARSC. I can poke around later for them.


Top
 Profile  
Reply with quote  
PostPosted: Tue Feb 06, 2018 1:13 am 
Offline
User avatar

Joined: Wed Jul 02, 2003 5:29 pm
Posts: 3515
Location: IMS/UAF, USA
Hah, I didn't do so much work back in 2011. I just needed one new C routine, so I did this in Master/Module.mk:
Code:
diff --git a/Master/Module.mk b/Master/Module.mk
index 4ff5e1b..a9c943d 100644
--- a/Master/Module.mk
+++ b/Master/Module.mk
@@ -18,8 +18,8 @@ ifdef LD_WINDOWS
 $(BIN):        $(libraries) $(local_objs)
        $(LD) $(FFLAGS) $(local_objs) -o $@ $(libraries) $(LIBS_WIN32) $(LDFLAGS)
 else
-$(BIN):        $(libraries) $(local_objs)
-       $(LD) $(FFLAGS) $(LDFLAGS) $(local_objs) -o $@ $(libraries) $(LIBS)
+$(BIN):        $(libraries) $(local_objs) $(SCRATCH_DIR)/bessi.o
+       $(LD) $(FFLAGS) $(LDFLAGS) $(local_objs) $(SCRATCH_DIR)/bessi.o -o $@ $(libraries) $(LIBS)
 endif
 
 $(eval $(compile-rules))
In other words, I added $(SCRATCH_DIR)/bessi.o to the dependencies and to the link list. Then in the makefile, I added these lines below the "all:" target, directions for creating $(SCRATCH_DIR)/bessi.o:
Code:
$(SCRATCH_DIR)/bessi.o: $(MY_ANALYTICAL_DIR)/bessi.c
[TAB]gcc -c $< -o $@
Note that you *must* have a tab before "gcc".


Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 07, 2018 8:23 am 
Offline

Joined: Wed Feb 01, 2017 2:40 pm
Posts: 14
Location: University of Naples - Federico II
Wow thanks a lot! I will try it now :D


Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 07, 2018 2:28 pm 
Offline

Joined: Wed Feb 01, 2017 2:40 pm
Posts: 14
Location: University of Naples - Federico II
Thanks kate,

I updated all the code you cited.

and the makefile:
Code:
#--------------------------------------------------------------------------
#  Build target directories.
#--------------------------------------------------------------------------

.PHONY: all

all: $(SCRATCH_DIR) $(SCRATCH_DIR)/MakeDepend $(BIN) rm_macros

$(SCRATCH_DIR)/memuse.o: $(MY_ANALYTICAL_DIR)/memuse.c
    gcc -c $< -o $@


but after the compiling process I get this:
Code:
ar: creating /home/ocean/WC13/I4DVAR/Build/libUTIL.a
master.f90:122:25:

    print*, 'Mem Used:: ', memuse(), 'KB'
                         1
Error: Function ‘memuse’ at (1) has no IMPLICIT type
make: *** [/home/ldamore/ocean/WC13/I4DVAR/Build/master.o] Error 1
make: *** Waiting for unfinished jobs....

memuse() is defined in the memuse.c. So I did not compile the C object file together with the other files in fortran. Where am I wrong?


Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 07, 2018 4:27 pm 
Offline
User avatar

Joined: Wed Jul 02, 2003 5:29 pm
Posts: 3515
Location: IMS/UAF, USA
Actually, that's not what it's complaining about. It's complaining that you didn't declare the type of memuse in the Fortran code. Does memuse return an integer or a real? You have to tell the compiler since we have turned on IMPLICIT NONE (we don't want it making assumptions for us). At the top of your code, just add something like:
Code:
real(r8) :: memuse
or
Code:
integer :: memuse


Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 07, 2018 9:29 pm 
Offline

Joined: Wed Feb 01, 2017 2:40 pm
Posts: 14
Location: University of Naples - Federico II
kate wrote:
Actually, that's not what it's complaining about. It's complaining that you didn't declare the type of memuse in the Fortran code. Does memuse return an integer or a real? You have to tell the compiler since we have turned on IMPLICIT NONE (we don't want it making assumptions for us). At the top of your code, just add something like:
Code:
real(r8) :: memuse
or
Code:
integer :: memuse


Oh yes, you are right. I'm a noob on Fortran :D

Thanks.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group