Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Ansys linking problem.

yonghwayi
Beginner
3,006 Views

yonghwayi_0-1699392017461.png

I am currently trying to implement ANSYS simulations using UPF (user programmable features) of ANSYS R21 1, but I cannot obtain Fortran compiler 2019, so I am using OPEN API.

However, since the linking between ansys and Fortran continues to fail.

So, I wonder if it is not possible to implement it with the latest version of the Open API.

Also, please tell me how to purchase Intel Parallel Studio 2019.

0 Kudos
12 Replies
andrew_4619
Honored Contributor III
2,980 Views

Do you have a log file of the output of the compile and link operations that show errors generated by Intel Compiler or the Microsoft Linker?  It is highly probably that some option changes will allow successful operation with the latest OneAPI. 

0 Kudos
yonghwayi
Beginner
2,953 Views

A LOG file linked to ANSYS using the OPEN API is attached. Could you possibly tell me why the linking failed?

0 Kudos
andrew_4619
Honored Contributor III
2,942 Views

Well the linking doesn't show any errors only some warnings. There is one "

The system cannot find the path specified.

 

and also there is also:

compiling Fortran file usercreep.F

 But it doesn't show  and output from the compiler. You need to have a look at the script/batch file or post it.

0 Kudos
yonghwayi
Beginner
2,903 Views

Is there any problem with ANSCUST.Bat?

 

@Echo off
cls
setlocal EnableDelayedExpansion
rem These need to change, for each new release. You might need to change
rem the SetParameters function, if the compiler changes. Otherwise, the
rem rest of the script should not need changing.
rem

set "VSVER=vs2019"
set "IFORT_HOME=%IFORT_COMPILER19%"
set "VCINPATH=%VS2019INSTALLDIR%\VC\Tools\MSVC\14.20.27508"

rem Yes, we are saving the current working directory, and we chdir back
rem into it, at various points in this script. Normally, this script is
rem run from a cmd.exe prompt, and it works fine without this. But, we
rem have automated test scripts, that call this script, and things fail,
rem if we don't explicitly move back into the working directory.
set "ACWORKDIR=%cd%"


rem :::::::::::::::::::::::::::::::
rem :: ::
rem :: E X E C U T I V E ::
rem :: ::
rem :::::::::::::::::::::::::::::::

call :SetParameters || goto :END
call :ShowBanner || goto :END
call :AskAboutAero || goto :END
call :CompileStuff || goto :END
call :LinkStuff || goto :END
call :CopyDlls || goto :END

goto :END


rem :::::::::::::::::::::::::::::::
rem :: ::
rem :: F U N C T I O N S ::
rem :: ::
rem :::::::::::::::::::::::::::::::

:SetParameters
set "PLATFORM_DIR=winx64"
set "IFORT_PLATFORM=intel64"
set "BIT_TARGET=64"

call "%~dp0/set_revn.bat"
call "%IFORT_HOME%\bin\compilervars.bat" %IFORT_PLATFORM% %VSVER%

set "ROOT_DIR=!AWP_ROOT%revn%!"
set "INCLUDE=%ROOT_DIR%\ansys\customize\Include;%INCLUDE%"
set "LIB=%ROOT_DIR%\ansys\Custom\Lib\%PLATFORM_DIR%;%LIB%"
exit /B 0


:ShowBanner
echo.
echo. ***********************************************************************
echo.
echo. This is the Mechanical APDL revision %revncust% ANSCUST batch file. It is
echo. used to link User Programmable Features, into versions of the M-APDL
echo. program, on Microsoft Windows %BIT_TARGET%-bit systems.
echo.
echo. ****** IMPORTANT !!!! ******
echo.
echo. The provided user subroutine source files reside in this folder:
echo. {InstallDir}\customize\user\
echo.
echo. Please copy the source file^(s^), that you wish to modify, from the above
echo. folder, into your working folder, to include them in your link. ^(The
echo. default working folder is {InstallDir}\custom\user\%PLATFORM_DIR%\ .^)
echo.
echo. If you want to use a different working folder, then also copy these other
echo. files, from the default working folder, to your actual working folder:
echo.
echo. ANSCUST.BAT
echo. ansysex.def
echo. ansys.lrf files
echo. app.manifest
echo.
echo. When you are done copying, run ANSCUST.BAT from your working folder.
echo.
echo. ***********************************************************************
pause
exit /B 0


:AskAboutAero
set "AERO=FALSE"
set /A ECNT=10

:AAA1
echo.
set /P ANSW=Do you want to link the Wind Turbine Aeroelastic library with Mechanical APDL? (Y or N):

if /I "%ANSW%"=="Y" (
set "AERO=TRUE"
exit /B 0

) else if /I "%ANSW%"=="N" (
set "AERO=FALSE"
exit /B 0

) else (
set /a ECNT=ECNT-1

if "%ECNT%"=="0" (
echo.
echo. giving up ...
echo.
exit /B 1
)

echo.
echo. Please answer Y or N
echo.
)

goto :AAA1


:CompileStuff
setlocal EnableDelayedExpansion
cd "%ACWORKDIR%"

del /q compile.log compile_error.txt >NUL 2>&1

if exist *.obj ( del /Q *.obj >NUL 2>&1 )
if exist ANSYS.exe ( del /Q ANSYS.exe >NUL 2>&1 )
if exist ANSYS.exp ( del /Q ANSYS.exp >NUL 2>&1 )
if exist ANSYS.lib ( del /Q ANSYS.lib >NUL 2>&1 )
if exist ANSYS.map ( del /Q ANSYS.map >NUL 2>&1 )

set "CUSTMACROS=/DNOSTDCALL /DARGTRAIL /DPCWIN64_SYS /DPCWINX64_SYS /DPCWINNT_SYS /DCADOE_ANSYS"
set "CMACS=/DCURVEFIT_EXPORTS /D_X86=1 /DOS_WIN32 /DWIN32 /D__STDC__"
set "CSWITCH=/O2 /Gy- /EHsc /Zi /c /W3 /MD"
set "FMACS=/D__EFL /DFORTRAN"
set "FSWITCH= /O2 /fpp /4Yportlib /auto /c /Fo.\ /MD /watch:source"

if exist *.F (
rem The "logo" is the banner that the compilers print-out, when they first
rem start processing. We only want to see that once, for each type of file
rem we process.
rem
set "LOGOMAC="

for /F "usebackq tokens=*" %%P in ( `dir /B "*.F"` ) do (
echo.
echo. compiling Fortran file %%P
echo.
ifort !LOGOMAC! %CUSTMACROS% %FMACS% %FSWITCH% %%P >>compile.log 2>&1
set "LOGOMAC=/nologo"
)
)


if exist *.c (
set "LOGOMAC="

for /F "usebackq tokens=*" %%P in ( `dir /B "*.c"` ) do (
echo.
echo. compiling C file %%P
echo.
cl !LOGOMAC! %CUSTMACROS% %CMACS% /D__MS_VC_INSTALL_PATH="%VCINPATH%" %CSWITCH% %%P >>compile.log 2>&1
set "LOGOMAC=/nologo"
)
)


if exist *.cpp (
set "LOGOMAC="

for /F "usebackq tokens=*" %%P in ( `dir /B "*.cpp"` ) do (
echo.
echo. compiling C++ file %%P
echo.
rem cl !LOGOMAC! %CUSTMACROS% %CMACS% %CSWITCH% %%P >>compile.log 2>&1
cl !LOGOMAC! %CUSTMACROS% %CMACS% /D__MS_VC_INSTALL_PATH="%VCINPATH%" %CSWITCH% %%P >>compile.log 2>&1
set "LOGOMAC=/nologo"
)
)

if not exist compile.log (
echo.
echo. no local files to compile - is this what you wanted?
echo.
) else (
findstr /I /C:": error" compile.log >compile_error.txt

if !errorlevel!==0 (
@Echo off
echo.
echo. ******************************************************************************
echo.
echo. COMPILER ERROR! CHECK compile.log FOR MORE INFORMATION
echo.
echo.
echo. ******************************************************************************
echo.
endlocal
exit /B 1
)
del /Q compile_error.txt
)

endlocal
exit /B 0


:LinkStuff
cd "%ACWORKDIR%"

if exist ANSYS.exe ( del /Q ANSYS.exe )

if "%AERO%" == "TRUE" (
type ansys.lrf >ansys.lrf.sav
echo "%ROOT_DIR%\ansys\Custom\User\%PLATFORM_DIR%\Aeroelastic\*.obj">>ansys.lrf

link @ansys.lrf 2>&1 | findstr /V /R /c:"^ansyslib..lib.* LNK4099: PDB" /c:"^zlibwapi.lib.* LNK4099: PDB"
type ansys.lrf.sav >ansys.lrf
del /q ansys.lrf.sav

) else (

link @ansys.lrf 2>&1 | findstr /V /R /c:"^ansyslib..lib.* LNK4099: PDB" /c:"^zlibwapi.lib.* LNK4099: PDB"
)

if %ERRORLEVEL% GEQ 1 (
set "ltxt=LINK ERROR!"
set enum=1
) else if not exist ansys.exe (
set "ltxt=LINK ERROR!"
set enum=1
) else (
set "ltxt=Link was successful!"
set enum=0
)

echo.
echo. ************************************************************************
echo.
echo. %ltxt%
echo.
echo. ************************************************************************
echo.

exit /B %enum%


:CopyDlls
rem We offer this, because some customers have multiple versions of ANSYS/MAPDL
rem in their paths. By copying libraries here, we guarantee that if they run
rem this custom version, it will link with the correct version of the libraries.
rem
cd "%ACWORKDIR%"

echo.
echo. ************************************************************************
echo.
echo. The next question will give you the opportunity to copy the necessary
echo. runtime DLLs. Note, this only needs to be done once. You can answer
echo. "N" for all subsequent invocations of %0.
echo.
echo. ************************************************************************
echo.

:CD1
set /P "ANSW=Do you want to copy the runtime DLLs? (Y or N): "

if /I "%ANSW%"=="Y" (
copy /y "%ROOT_DIR%\ansys\Bin\%PLATFORM_DIR%\"*.dll .
copy /y "%ROOT_DIR%\commonfiles\AAS\bin\%PLATFORM_DIR%\"*.dll .
exit /B 0
) else if /I "%ANSW%"=="N" (
exit /B 0
) else (
echo.
echo "Please answer Y or N!"
echo.
goto CD1
)

exit /B 0


:END
endlocal

0 Kudos
JohnNichols
Valued Contributor III
2,888 Views

You are being a bit unrealistic expecting people who know little about ANSYS to look at a long batch file and spot the error. 

1. There should be posts on the ANSYS Forum site or on the web that discuss this problem

2. Run it and report the errors, you may need to run it one line at a time using a console, welcome to the real world 

3. Based on your comments, I presume you are a graduate student? If so ask at your university.

0 Kudos
andrew_4619
Honored Contributor III
2,860 Views

Well John he posted the script because I ask him/her to and I am happy to answer within the constraints of my knowledge. The analysis product ANSYS/Nastran/Optistruct/Abaqus/LS-Dyna are also not entirely unknown to me.

0 Kudos
andrew_4619
Honored Contributor III
2,860 Views

Well the script has:

set "IFORT_HOME=%IFORT_COMPILER19%"

 

near the top. So that will only work if you have the 2019 Intel Fortran installed. My system has  IFORT_COMPILER23 (open a CMD wuindow and type SET) so I would change that to %IFORT_COMPILER23% and see what happens.....

 

 

0 Kudos
jimdempseyatthecove
Honored Contributor III
2,847 Views

What are the "!" in 

set "ROOT_DIR=!AWP_ROOT%revn%!"

supposed to do.

HELP SET shows "!" as an unary operator when /A is in effect.

 

Jim Dempsey

0 Kudos
mecej4
Honored Contributor III
2,362 Views

The '!' character is used to signify "delayed expansion" in Windows batch files, please see https://ss64.com/nt/delayedexpansion.html .

0 Kudos
manuellucasso
Beginner
2,394 Views

Any update on the topic?

 

I have faced similar issues and my error is this below:

Linking usermat ...
Microsoft (R) Incremental Linker Version 14.29.30154.0
Copyright (C) Microsoft Corporation. All rights reserved.

-out:usermatLib.dll
-def:usermatLibex.def
-dll
-machine:X64
-map
-manifest:embed
-defaultlib:ANSYS.lib
-defaultlib:ansMemManager.lib
-defaultlib:ansOpenMP.lib
*.obj
LINK : warning LNK4001: no object files specified; libraries used
Creating library usermatLib.lib and object usermatLib.exp
LINK : error LNK2001: unresolved external symbol _DllMainCRTStartup
usermatLib.exp : error LNK2001: unresolved external symbol USERMAT
usermatLib.dll : fatal error LNK1120: 2 unresolved externals

 

 

If any one has any idea, I would highly appreciate.

0 Kudos
andrew_4619
Honored Contributor III
2,378 Views

Well that just says the Fortran file for the entry point of the dll  was not compiled or was compiled and failed or was compiled but the .obj file was created in the wrong place for the link command.  You need to dig a bit deeper and see if there are any other error logs for the compile stage maybe.

0 Kudos
manuellucasso
Beginner
2,340 Views

Hi Andrew and others,

 

Thank you, for your input. When I was trying to compile the dll files I had these output:

 

manuellucasso_0-1709397856568.png

 

@mecej4 and @jimdempseyatthecove,

 

I am not sure if I understood your comments. Should I remove the ! from the set "ROOT_DIR=!AWP_ROOT%revn%!"?

I had some link warnings related to /delayload - not sure what they mean.

 

Regards

 

 

 

 

0 Kudos
Reply