# Tag Info

21

I've always wondered about the scalability of MathLink (now officially "Wolfram Symbolic Transfer Protocol"). This is the protocol used by Mathematica to communicate between the front end and the kernel, and the basis of the Parallel package. It has quite low bandwidth and high latency relative to, for example, MPI libraries. I also wonder how many MathLink ...

20

dat = {0.71, 0.685, 0.16, 0.82, 0.73, 0.44, 0.89, 0.02, 0.47, 0.65}; Module[{t = 0}, Split[dat, (t += #) <= 1 || (t = 0) &] ] {{0.71, 0.685}, {0.16, 0.82, 0.73}, {0.44, 0.89}, {0.02, 0.47, 0.65}} Credit to Simon Woods for getting me to think about using Or in applications like this. Performance I decided to make an attempt at a higher ...

14

I am sure you can easily install also Linux on it and then you could contact Vladyslav Shtabovenko, the current maintainer of FeynCalc (https://github.com/vsht) and ask him about hard problems in High Energy Physics he would like to benchmark on such a King-Kong machine. Either him or somebody else could also provide you with more complicated examples of ...

14

You can accomplish this using DeleteDuplicatesBy, by first taking your two input lists and making a matrix out of them, and then deleting the rows where the last element (the element that came from myNewList) is a duplicate. Then you transpose back and assign the sublists of the reduced matrix to the new lists you want. {myListDuplicatesDeleted, ...

13

Select[ IntegerPartitions[24, {8}, Range[5]], #.# == 86 & ] {{5, 5, 4, 2, 2, 2, 2, 2}, {5, 5, 3, 3, 3, 2, 2, 1}, {5, 4, 4, 4, 2, 2, 2, 1}, {5, 4, 4, 3, 3, 3, 1, 1}, {4, 4, 4, 4, 4, 2, 1, 1}} Slightly more general approach (in case where IntegerPartitions is not what we need): ClearAll[ar, a]; ar = Array[a, 8] ar /. Solve[Flatten@{ ...

12

Comparable to other results: Lookup[Thread[myNewList -> myList], DeleteDuplicates@myNewList] {1,3} Seems most appropriate (fast and concise) for the OP task (V.10): Values@AssociationThread[myNewList -> myList] {1,2} P.S. Learned the general idea from this post of Mr.Wizard. Addenum: Some notes concerning speed. @Mr.Wizard suggested ...

11

I would choose a problem that exploits the unique power of Mathematica, in particular the natural functions involving graph theory, symbolic math, graphics, and the high compute power you have available. So I would choose some image recognition and clustering problem such as: Take some large number of images ($\sim\!\!10^8$) and perform deep learning on ...

9

4 TB memory? N-body of course; dir = 2; T = 10; k = 1; l = 10; n = l^3; v = 6; q[i_] := (-1)^i m[i_] := RandomReal[5] Rem[o_] := l (o - IntegerPart[o]) eqns = Table[ {D[Subscript[r, i][t], {t, 2}] m[i] == Sum[ Normalize[Subscript[r, i][t] - Subscript[r, j][t]] k q[ i] q[j]/(Subscript[r, i][t] - Subscript[r, ...

8

A slightly different approach with Reduce (or Solve) We define: matC = Range[5]; (* the list of the integers from which we build a list *) Let us use a vector to indicate the multiplicities of any integer: matX = Array[ x, 5 ]; (* @Kuba: that's more concise, indeed *) So x[1] will tell us how many times $1$ appears a possible solution. We can then ...

7

You can do it probably most efficiently in compiled code, if you're not too concerned about precision. Here you can use the listability of compiled functions over tensor arguments. Your function is basically the Mandelbrot iteration: mandelbrot = Compile[{{c, _Complex, 0}, {d, _Integer, 0}}, Block[{i = 0, z = c}, While[Abs[z] < 2.0 && i < ...

7

Here's my take at making a function as fast as possible. main = Module[{idxs = sub[Accumulate@#]}, InternalPartitionRagged[#, idxs]] &; sub = Compile[{{list, _Real, 1}}, Block[{i, l = Length[list], ref = 1., bag = InternalBag[{0}]}, For[i = 1, i <= l, i++, If[list[[i]] >= ref || i == l, InternalStuffBag[bag, i]; ref = ...

7

The following two expressions are equivalent. Table[RandomReal[], {10^8}]; // AbsoluteTiming {7.99593, Null} RandomReal[1., 10^8]; // AbsoluteTiming {1.20604, Null} The second expression shows the advantage of RandomReal over Random. Edit Another consideration is the generator used. For example, when the Mersenne twister is specified, there is not ...

6

You can also use FindHamiltonianCycle. To convert Hamiltonian path problem to Hamiltonian cycle problem, just add one vertex and connect it to all other vertices. After that just run FindHamiltonianCycle[g, All] For example, countHamiltonianPaths[g_] := Length[ FindHamiltonianCycle[ AdjacencyGraph[PadRight[AdjacencyMatrix[g], (VertexCount[g] + ...

6

The following is approx 30 times faster: (imageData = Flatten@ImageData@image; mean = Mean@imageData; nonzeroPixels = Total@Unitize@imageData; zeroPixels = Length@imageData - nonzeroPixels; stdDeviation = StandardDeviation@imageData) // Timing

6

Your Func is far beyond best. As mentioned before, currently you'd better set effort on learning to code in "Mathematica-style" rather than try to relieve the slowness (which is mostly caused by bad coding in my view) with Compile. Here's an uncompiled function that's about 300 times faster than your Func: func = Function[{l0, l1, l2, ll3}, Module[{l3 = ...

6

InternalPartitionRagged uses Accumulate internally to generate a list of positions from the sub-list lengths, then MapThread and Take to extract the corresponding elements from the array. You can check the internal definition with Needs["GeneralUtilities"]; PrintDefinitions[InternalPartitionRagged] The reason for pointing this out is that answers which ...

6

(1) Convolution with Plus and Times can be done via FFT. (2) The overall speed complexity cannot be less than the size-of-result complexity. Point (1) might help to explain why the standard ListConvolve is fast under most circumstances. Point (2) on the examples in this post should help to explain why LC2 is likely to be slow. To make this clear we can ...

5

Module[{f}, f[x_] := (f[x] = 0; 1); Pick[myList, f /@ myNewList, 1]] {1, 3}

5

This might be faster (you will need to install libpng): Needs["CCompilerDriver"] loadpng$source=" // Load a PNG image from a file into memory. // Placed into the public domain by Mark Adler, January 24, 2016 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #include <setjmp.h> #include ... 5 f[x_, y_] := Module[{new}, If[Total[new = Append[x, y]] >= 1, Sow[new]; {}, new]] Reap[Fold[f, {}, dat]][[2, 1]] 5 OK, a partial answer without considering h["TestDataTable",All]: In the plot it is much faster to move the pars inside CDF. (Computing CDF numerically vs. symbolically, I guess.) AbsoluteTiming[d1 = CDF[f[a, b, c, p] /. pars, x];] (* <1s *) AbsoluteTiming[d2 = CDF[f[a, b, c, p], x] /. pars;] (* 14s *) And it is faster to first compute the functions ... 4 To take advantage of that kind of memory, you really want to do some parallel processing. Mathematica's parallel processing focuses on data-parallelism, or more simply, embarrassingly parallel problems. So you might try out various Monte Carlo simulations. I don't recommend trying to reproduce full MPI functionality with LinkCreate et al. In the case ... 4 The more I've thought about this question, the more my answer (above) has changed. Now my answer is this: Assuming there is a high-bandwidth connection to the Wolfram server, choose a problem that relies on Mathematica's superior handling of curated data. Create an enormous problem that relies on curated financial data, geographic data, biological data, ... 4 Here's a quick helper function to do so. It first finds the position of each$1$in the original matrix using Position; it then selects$n$of these positions randomly using RandomSample and replaces their value with$-1\$ using ReplacePart: Clear[flipsome] flipsome[matrix_?MatrixQ, n_Integer] := ReplacePart[matrix, RandomSample[Position[matrix, 1], n] ...

4

This is not really very efficient but here goes. We can create a rational function that is effectively a generating function in three variables, one to force 8 factors, one to force a sum e1ual to 24, one to force a sum of squares equal to 86. The other parameters just keep track of what factors get used in a coefficient. vals = Range[5]; aa = Array[a, 5]; ...

4

What I am most interested in is described in Oleksandr's answer. Here's something else I would also try: There are several built-in functions that take advantage of parallelization without any special settings (and without using the Parallel tools framework). I would like to know how well these scale to a high number of cores. Examples: Matrix ...

4

Since Sum holds its arguments, it ends up computing Mean[x] and Mean[y] in every step in the sum. Try Total[(x - Mean[x])(y - Mean[y])]/Total[(x - Mean[x])^2] which uses vectorized operations. In general, Sum is most suited to compute sums of symbolic quantities, sums with symbolic limits etc. Total or Tr is much faster for numeric stuff.

4

Pieter, here is one suggestion: - try a FEM calculation on a huge and complicatd structure, eg. stress around clusters of cracks :)

4

I love the brevity and elegance of garej's second method and I would probably Accept it for that reason if nothing else, were this my Question. Nevertheless it seems that using the position method referenced in the question is actually faster. positionDuplicates[list_] := GatherBy[Range @ Length @ list, list[[#]] &] a = RandomReal[1, 1*^6]; b = ...

3

With RegionNearest RegionNearest is a function that basically processes the region and returns a function of type RegionNearestFunction which is optimized for finding the nearest point in the region quickly. You should use the returned function to find the closest point in the region. As it is now you are recomputing this function again and again, which ...

Only top voted, non community-wiki answers of a minimum length are eligible