From f391a0873f4fee61b39e24ce96337296f82045b0 Mon Sep 17 00:00:00 2001 From: antonl Date: Thu, 5 Feb 2026 09:17:53 +0100 Subject: [PATCH] working mpi link in the commlibrary --- build.bat | 14 ++++++++++---- src/commlayer.cu | 23 +++++++++++++++++++++++ src/main.cu | 2 -- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/build.bat b/build.bat index 133e8cc..c39e0c0 100644 --- a/build.bat +++ b/build.bat @@ -1,4 +1,4 @@ -@echo off +@rem @echo off setlocal @rem I rely on environment variables here. @@ -8,19 +8,24 @@ setlocal set nvccArch=sm_120 set commLayerSource=commlayer set mainSource=main + set CommonXCompFlags=/W3 /O2 /EHsc set DllXcompilerFlags="%CommonXCompFlags% /MD" set ExeXcompilerFlags="%CommonXCompFlags% /MT" set IgnoreWarnings=-Wno-deprecated-gpu-targets +set MPIIncludes=-I"%MSMPI_INC%\" +set MPILibPath=-L"%MSMPI_LIB64%\" set CudaIncludes=-I"%CUDA_PATH%\include" -I"%CUDSS_PATH%\include" set OtherIncludes=-Iinclude set CudaLibPaths=-L"%CUDA_PATH%\lib\x64" -L"%CUDSS_PATH%\lib\12" -nvcc -c -o build/%commLayerSource%.obj src/%commLayerSource%.cu ^ +set LibraryLinks=-lcudss -lcudart + +nvcc -v -c -o build/%commLayerSource%.obj src/%commLayerSource%.cu ^ -arch=%nvccArch% ^ - %CudaIncludes% %OtherIncludes% %CudaLibPaths% ^ - -lcudss -lcudart ^ + %CudaIncludes% %OtherIncludes% %MPIIncludes% %CudaLibPaths% %MPILibPath% ^ + %LibraryLinks% ^ %IgnoreWarnings% ^ -Xcompiler %DllXcompilerFlags% @@ -32,6 +37,7 @@ if %ERRORLEVEL% NEQ 0 ( nvcc -shared -o build/%commLayerSource%.dll build/%commLayerSource%.obj ^ -arch=%nvccArch% ^ %IgnoreWarnings% ^ + %MPILibPath% -lmsmpi ^ -Xcompiler %DllXcompilerFlags% ^ -Xlinker "/NODEFAULTLIB:LIBCMT" diff --git a/src/commlayer.cu b/src/commlayer.cu index 7448a77..882b74c 100644 --- a/src/commlayer.cu +++ b/src/commlayer.cu @@ -1,14 +1,37 @@ #include #include +#include + #define __CSCUDSS_EXPORT extern "C" __declspec(dllexport) +__CSCUDSS_EXPORT int cudssCommRank(void *comm, int *rank) { + int result = MPI_Comm_rank((*(MPI_Comm*)comm), rank); + return result; +} + +__CSCUDSS_EXPORT int cudssCommSize(void *comm, int *size) { + int result = MPI_Comm_size((*(MPI_Comm*)comm), size); + return result; +} + + + __CSCUDSS_EXPORT int libraryMain() { + MPI_Init(0,0); std::cout << "HELLO LIBRARY" << std::endl; + + int rank; + int size; + int Comm = MPI_COMM_WORLD; + cudssCommRank(&Comm, &rank); + cudssCommSize(&Comm, &size); + std::cout << "Rank: " << rank << ", size: " << size << std::endl; + MPI_Finalize(); return 0; } diff --git a/src/main.cu b/src/main.cu index f31393d..b5d461c 100644 --- a/src/main.cu +++ b/src/main.cu @@ -8,8 +8,6 @@ #include "util.h" - - /* ============================================================================ * Version Information * ============================================================================ */