Monday, September 20, 2010

How to debug ABAQUS user subroutines using gdb

This post describes the way to debug an user subroutine (e.g. USDFLD) with ABAQUS using gdb on opensuse linux platform.

First, you have to include -ggdb switch in the compiler section of abaqus_v6.env file. This file can be copied from <abaqus install dir>/6.6-1/site/ into working directory. A sample file is attached at the end of this post.

Next submit your job with following command:
<abaqus install dir>/Commands/abaqus job=<jobname> user=<user subrotine file>

Get the process id of this job with following command:
ps -A | grep standard

Now start gdb attached to above process as follows:
gdb -p <PID>

The gdb will start and pause the job wherever it is at the time of starting gdb session. Define your break points with "b" command and resume job execution with "c" command.

That's all!

Sample abaqus_v6.env file on opensuse linux:

#
#        System-Wide ABAQUS Environment File
#       -------------------------------------
pre_memory = "3000 mb"
standard_memory = "3000 mb"
standard_parallel = ALL
mp_mode = MPI
mp_file_system = (DETECT,DETECT)
mp_environment_export = ('ABA_CM_BUFFERING',
                         'ABA_DDM_DEBUG',
                         'ABA_ELP_SURFACE_SPLIT',
                         'ABA_ELP_SUSPEND',
                         'ABA_MEMORY_MODE',
                         'ABA_MPI_MESSAGE_TRACKING',
                         'ABA_MPI_VERBOSE_LEVEL',
                         'ABA_PATH',
                         'ABA_RESOURCE_MONITOR',
                         'ABA_RESOURCE_USEMALLINFO',
                         'ABAQUS_LANG',
                         'ABAQUSLM_LICENSE_FILE',
                         'ABQ_CRTMALLOC',
                         'ABQ_DATACHECK',
                         'ABQ_RECOVER',
                         'ABQ_RESTART',
                         'ABQ_SPLITFILE',
                         'ABQ_XPL_WINDOWDUMP',
                         'ABQ_XPL_PARTITIONSIZE',
                         'ABQLMHANGLIMIT',
                         'ABQLMQUEUE',
                         'ABQLMUSER',
             'CCI_INITIAL_EXCHANGE',
                         'ABAQUS_CCI_DEBUG',
             'CCI_RENDEZVOUS',
                         'DOMAIN',
                         'DOMAIN_CPUS',
                         'FLEXLM_DIAGNOSTICS',
                         'FOR0006',
                         'FOR0064',
                         'LD_PRELOAD',
                         'MP_NUMBER_OF_THREADS',
                         'MPC_GANG',
                         'MPI_PROPAGATE_TSTP',
                         'MPI_SOCKBUFSIZE',
                         'MPI_WORKDIR',
                         'NCPUS',
                         'OMP_DYNAMIC',
                         'OMP_NUM_THREADS',
                         'PAIDUP',
                         'PARALLEL_METHOD',
                         'RAIDEV_NDREG_LAZYMEM')

#
# Linux (Opteron/EM64T) Settings:
#
# Compile and Link command for user subroutines.
# Compile_cpp and link_exe for ABAQUS/Make.
#
import os, uti, re, driverUtils, glob

fortDefPath = "/"
ccDefPath = "/"
fortCompiler = "gfortran"
cppCompiler = "gcc"

if os.path.exists(os.path.join(fortDefPath, fortCompiler)):
    fortCmd = os.path.join(fortDefPath, fortCompiler)
else:
    fortCmd = fortCompiler

if os.path.exists(os.path.join(ccDefPath, cppCompiler)):
    cppCmd = os.path.join(ccDefPath, cppCompiler)
else:
    cppCmd = cppCompiler

os.environ['ABA_GNU'] = 'on'
if os.environ.has_key('ABA_GNU'):
    import string, os, uti
    plat = string.upper(uti.getPlatform())
    if uti.getVersion()[:3] == '6.5':
        libPath = os.path.join(os.environ['ABA_HOME'], 'cae', 'External ')
    else:
        libPath = os.path.join(os.environ['ABA_HOME'], 'External ')
    
    if plat == 'LINUX':
            plat = 'LINUX32'
#    print "libPath= ",libPath,"plat= (new)",plat
    
    compile_cpp = ('g++ -c -DABQ_LINUX -DABQ_%s -DABQ_IO_STANDARDS ' %(plat) +
                           '-DABQ_USE_STANDARD_HEADER -DFOR_TRAIL -DHAS_BOOL ' +
                           '-DASSERT_ENABLED -D_BSD_TYPES -D_BSD_SOURCE -D_GNU_SOURCE ' +
                           '-D_POSIX_SOURCE -D_XOPEN_SOURCE_EXTENDED -D_XOPEN_SOURCE -DHAVE_OPENGL ' +
                           '-D_POSIX_SOURCE -D_XOPEN_SOURCE_EXTENDED -D_XOPEN_SOURCE -DHAVE_OPENGL ' +
                           '-DHKS_OPEN_GL -DTYPENAME=typename -DGL_GLEXT_PROTOTYPES ' +
                           '-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -w -O0 -I%I')
                           
    compile_fortran = ( "gfortran -c -O -fPIC -fno-second-underscore -I%I -ggdb" )
    
#    link_sl = ( 'gfortran -Wl,-warn-once -Wl,-export-dynamic -shared %E -Wl,-soname,%U -o ' +
#                        '%U %F %A %B -Wl,-Bdynamic -L' + libPath +
#                        '-lifport -lifcoremt -lgcc -lg2c -lm -lc' )
#
#    link_exe = ('gfortran -o %J %F %M %L %B %O -L' + libPath +
#                '-lifport -lifcoremt -lgcc -lg2c -lm -lc' )

    link_sl = ( 'gfortran -Wl,-warn-once -Wl,-export-dynamic -shared %E -Wl,-soname,%U -o ' +
                        '%U %F %A %B -Wl,-Bdynamic -L' + libPath +
                        '-lifport -lifcoremt -lgcc -lgfortran -lm -lc' )

    link_exe = ('gfortran -o %J %F %M %L %B %O -L' + libPath +
                '-lifport -lifcoremt -lgcc -lgfortran -lm -lc' )

    del plat, libPath

mp_rsh_command = 'rsh -n -l %U %H %C'

# Remove the temporary names from the namespace
del cppCmd
del fortCmd
del ccDefPath
del cppCompiler
del fortDefPath
del fortCompiler

import driverUtils, os
graphicsEnv = driverUtils.locateFile(os.environ['ABA_PATH'],'site','graphicsConfig','env')
if graphicsEnv:
    execfile(graphicsEnv)
else:
    raise 'Cannot find the graphics configuration environment file (graphicsConfig.env)'

del driverUtils, os, graphicsEnv
abaquslm_license_file="27000@nilesh-laptop"

doc_root="http://nilesh-laptop:2080/v6.6"

No comments:

Post a Comment