Skip to content

std.parallelism fatal flaw?#4399

Closed
burner wants to merge 1 commit intodlang:masterfrom
burner:parallelism_fatal_flaw
Closed

std.parallelism fatal flaw?#4399
burner wants to merge 1 commit intodlang:masterfrom
burner:parallelism_fatal_flaw

Conversation

@burner
Copy link
Member

@burner burner commented Jun 3, 2016

Big parts of the std.parallelism unittests where not run for a very long time.
Apparently they do not even compile anymore. This PR refactors the unittests
so they are at least run once by default. While refactoring I found a couple of
problems with the unittests. Such as, local unittest function being unable to
access the current stackframe. This destroyed some constructs used by
std.parallelism.

I'm a noob when it comes to std.parallelism. I found this bug while scoping
imports. I need help on this!

foreach (i; 0..1_000_000) {}
}
// Get around weird bugs having to do w/ sqrt being an intrinsic:
//real[][] sqrtMatrix = poolInstance.amap!parallelSqrt(matrix);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amap can not call parallelSqrt that that local function was trying to access poolInstance which is located on the same stack

@burner burner force-pushed the parallelism_fatal_flaw branch from 322ddd1 to 67e0411 Compare June 3, 2016 09:40
)
);
// Get around weird bugs having to do w/ sqrt being an intrinsic:
real[][] sqrtMatrix = poolInstance.amap!parallelSqrt(matrix);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amap can not call parallelSqrt that that local function was trying to access poolInstance which is located on the same stack

@joakim-noah
Copy link
Contributor

Well, it is a stress test, but yeah, probably nobody was running it and it's better to have it run once like this by the tester, so it's kept up to date.

assert(poolInstance.workerIndex() == 0);
// These unittests are intended more for actual testing and not so much
// as examples.
void stressTest2(int poolSize)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh - what was the reason to expose such test methods publicly?
Shouldn't they be private and have version(unittest)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created this function to have runnable one or multiple times. Eventually, this will be private. But this is not the problem here. Please keep the nitpicking to a minimum for now.

@burner
Copy link
Member Author

burner commented Jun 16, 2016

@joakim-noah not only that but the design concept used by the test is no longer supported by D. Which begs the question if std.parallelism is still a working phobos module or if it needs to be deprecated.

{
static import std.math;
return std.math.isNaN(f);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@burner shouldn't these be one import?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so to, but isNaN was passed as a function to a function of parallelism. But this code has not been run at least since isNaN became a template. This is just code trying to get the tests into a compileable state.

// matrix.
static real[] parallelSqrt(real[] nums)
{
return poolInstance.amap!(mySqrt)(nums);
Copy link
Contributor

@JackStouffer JackStouffer Jun 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your first problem is that static functions aren't allowed to access poolInstance

@dnadlinger
Copy link
Contributor

Before being quite so fatalistic and going around suggesting modules to be deprecated, you might want to make sure which of the issues actually existed before you touched the code. isNaN having become a template is taken into account easily enough, and after that, enabling the test by default seems to work without any further issues (auto-tester still pending, see #4484 for test results).

@burner burner force-pushed the parallelism_fatal_flaw branch from 67e0411 to b60c33b Compare June 28, 2016 09:00
@burner
Copy link
Member Author

burner commented Jun 28, 2016

@klickverbot I recreated your PR here. The difference is that I moved the two unittests into a function that takes the number of runs as an argument. Now I get:

std/parallelism.d(4467): Error: static function std.parallelism.testFunction2.parallelSqrt cannot access frame of function std.parallelism.testFunction2
std/parallelism.d(4495): Error: static function std.parallelism.testFunction2.parallelSum cannot access frame of function std.parallelism.testFunction2

I really could need some help. I do not see the problem.

@JackStouffer
Copy link
Contributor

std/parallelism.d(4467): Error: static function std.parallelism.testFunction2.parallelSqrt cannot access frame of function std.parallelism.testFunction2
std/parallelism.d(4495): Error: static function std.parallelism.testFunction2.parallelSum cannot access frame of function std.parallelism.testFunction2

I really could need some help. I do not see the problem.

As I said in my earlier comment, it means exactly what it says: you're trying to get a variable that belongs to testFunction2 inside of a static function. Specifically, you're trying to access poolInstance.

@burner
Copy link
Member Author

burner commented Jun 29, 2016

std/parallelism.d(4467): Error: template instance amap!(mySqrt) cannot use local 'mySqrt' as parameter to non-global template amap(functions...)
std/parallelism.d(4470): Error: template instance amap!(parallelSqrt) cannot use local 'parallelSqrt' as parameter to non-global template amap(functions...)
std/parallelism.d(4499): Error: template instance amap!(parallelSum) cannot use local 'parallelSum' as parameter to non-global template amap(functions...)

IMO the problem is that unittest block statements are somehow different from function block statements. And the test/use-case of std.parallelism used that fact.

@dnadlinger
Copy link
Contributor

dnadlinger commented Jun 29, 2016

If you keep it using the global poolInstance and the Sqrt/Sum functions static, it should work.

@JackStouffer
Copy link
Contributor

Ping @burner

@burner
Copy link
Member Author

burner commented Jul 14, 2016

I hadn't had much time lately. But its on my list

@wilzbach
Copy link
Contributor

Hmm we should really enable the test suite. There's some random (un)-coverage business going on in at least these places of std.parallelism:

636:    throw exception;

https://codecov.io/gh/dlang/phobos/compare/86050a1c59eda327fa263549f0b53e56a4cfa9ed...2749175ceb24e4b780725677b7e233f65e4f791c/changes

3755 assert(lastException);
3756 lastException.next = e;
3757 lastException = findLastException(e);

https://codecov.io/gh/dlang/phobos/compare/77f1a9067b59395f8444cb2d01047680aebcfe5f...2e05f29d3c4cc7690198c3ad0d06eb23293da48a/changes

@burner burner closed this May 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants