hi,
i’m intending to release a set of generic nodes introducing the big integer data type for calculations > int64 - this is pretty easy so far, as the bigInteger structure fortunately is included in the system.numerics namespace!
i’ve successfully had vvvv come back from calculating 15mio^2mio (took several hours, resulting number is about 10mio digits long)!!!
now, as these calculations can take a while, eg 10mio^50k takes about 2 seconds, i’d like to have these bigInt plugins open a thread for the calculations, ie not block vvvv while they’re calculating:
-
this would mean a thread for each slice in the input, would this work/even make sense? what happens if there’s more slices than threads possible. should i just limit the possible input count? doesn’t feel right :)
-
i’ve tried threading my plugin, but with no luck; as soon as i hit “Calculate”, vvvv freezes until the result is there (as it does without threading code):
- region usings
using System;
using System.ComponentModel.Composition;
using System.Numerics;
using System.Threading;
using VVVV.PluginInterfaces.V1;
using VVVV.PluginInterfaces.V2;
using VVVV.Utils.VColor;
using VVVV.Utils.VMath;using VVVV.Core.Logging;
- endregion usings
namespace VVVV.Nodes
{
#region PluginInfo
[PluginInfo(Name = “Power”, Category = “BigInteger”, Help = “Basic template with one value in/out”, Tags = “”)](PluginInfo(Name = “Power”, Category = “BigInteger”, Help = “Basic template with one value in/out”, Tags = “”))
#endregion PluginInfo
public class BigIntegerPowerNode : IPluginEvaluate
{
#region fields & pins
[Input(“Base”, DefaultValue = 1.0)](Input(“Base”, DefaultValue = 1.0))
public ISpread FInput;[Input("Exponent", DefaultValue = 1.0)](Input("Exponent", DefaultValue = 1.0)) public ISpread<int> FInput2; [Input("Calculate", DefaultValue = 1.0, IsBang =true, IsSingle =true, Visibility = PinVisibility.OnlyInspector)](Input("Calculate", DefaultValue = 1.0, IsBang =true, IsSingle =true, Visibility = PinVisibility.OnlyInspector)) public ISpread<int> FDoIt; [Output("Output")](Output("Output")) public ISpread<BigInteger> FOutput; [Output("AsString")](Output("AsString")) public ISpread<string> FString; [Import()](Import()) public ILogger FLogger; #endregion fields & pins static BigInteger result; //called when data for any output pin is requested public void Evaluate(int SpreadMax) { FOutput.SliceCount = SpreadMax; BigInteger bigIntFromInt64 = new BigInteger(FInput[0](0)); if (FDoIt[0](0) == 1){ for (int i = 0; i < SpreadMax; i++) { Thread myNewThread = new Thread[) => BigIntPow(bigIntFromInt64,FInput2[i](i)](https://vvvv.org/documentation/)-=>-BigIntPow(bigIntFromInt64,FInput2[i](i)); myNewThread.Start(); FString[i](i) = result.ToString(); } } } private static void BigIntPow(BigInteger Base, int Exponent) { result = BigInteger.Pow(Base,Exponent); } }
}
- region usings
now i know i’m already threading for each input slice here, but im testing with single sliced spreads only…
also i believe to understand that it’s my if statement stopping my plugin to run independent of vvvv itself; but tbh i don’t know as it’s the first time i’m trying to do a threaded plugin at all and i’m not sure on how to structure this properly…
any help/input on this, ie example plugins successfully threading parametrized methods from which i can learn, would be much appreciated!!
i’ve also attached my plugin with a test patch computing 10mio^50k! R.I.P. INF.00 :)
thanks a lot!
BigIntegerPower.zip (34.4 kB)