Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

libomp workaround for Linux, Mac #897

Merged
merged 4 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Simulation/Simulators/QuantumSimulator/QuantumSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public partial class QuantumSimulator : SimulatorBase, IQSharpCore, IType1Core,
[DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "seed")]
private static extern void SetSeed(uint id, UInt32 seedValue);

[DllImport("libomp", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "omp_get_num_threads")]
private static extern int OmpGetNumberOfThreads();

/// <summary>
/// Creates a an instance of a quantum simulator.
/// </summary>
Expand All @@ -45,6 +48,14 @@ public partial class QuantumSimulator : SimulatorBase, IQSharpCore, IType1Core,
(int?)randomNumberGeneratorSeed
)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// We don't need this value, but explicitly calling an OMP function should trigger the load of libomp
// by .NET from the runtimes folder for the current platform, such that the later library load by the
// simulator does not need to know where to search for it.
var threadCount = OmpGetNumberOfThreads();
}

Id = Init();
// Make sure that the same seed used by the built-in System.Random
// instance is also used by the native simulator itself.
Expand Down