StanfordLegion / legion

The Legion Parallel Programming System
https://legion.stanford.edu
Apache License 2.0
675 stars 146 forks source link

How do I partition a 3D index space? #1604

Closed AngryBear2 closed 9 months ago

AngryBear2 commented 9 months ago

I'm trying to partition a three-dimensional index space according to its third dimension.In the example, I split it into two parts. image When I output the upper and lower limits of 3D space in the task, I found that he always partitioned in my second dimension, so I wanted to ask this question. image And as I write this, these post-partitioned tasks don't seem to be parallel. When I output the node that is executed, it is always 0. image

rohany commented 9 months ago

There is no guarantee about what kind of partitioning create_equal_partition gives you. If you have a better idea about how to partition your index spaces, then you need to use other partitioning functions, like create_partition_by_restriction or create_partition_by_domain.

And as I write this, these post-partitioned tasks don't seem to be parallel. When I output the node that is executed, it is always 0.

If you only print point_data[0] you will only see zero, as your color_bounds are (0,0,0) to (0,0,num_heads-1). Try printing all of task->index_point. It has an overloaded operator<< for use with std::cout.

AngryBear2 commented 9 months ago

@rohany After following your advice, sir, I partitioned the third dimension of my 3D index space using create_partition_by_restriction, but I'm still a little confused about this API, image I know that Transform<3,3> transform; means that the color space and area space are divided into three dimensions, and I don't quite understand why when transform[2][2]=block_size, my code seems to be perfectly divided in the third dimension. What is the meaning of this transform assignment?

rohany commented 9 months ago

The comments on create_partition_by_restriction in legion.h explain what computation is being done, but it is a little confusing. Each point in the color space is multiplied against the transform matrix, and then that is added to extent to get the bounds of the rectangle for each point in the color space. In the mathematical sense, it expresses a linear transformation on the color space points.

For this sort of thing, I find it easier to start with create_partition_by_domain, where you construct a DomainPointColoring that maps each point in your color space to a Rect containing the bounds of the rectangle referenced by that color space point. To do this, you'll have to write down a formula that computes the rectangle bounds for each point in your color space. Once you do that and are happy with the partitioning, you can put in the extra work (if you want) to switch to create_partition_by_restriction, which the runtime can process a little more efficiently than the create_partition_by_domain operation.

lightsighter commented 9 months ago

I'd actually recommend starting with create_partition_by_blockify which is a special case of create_partition_by_restriction that will make a disjoint partition the way many users expect simply by specifying the "blocking factors" along each dimension. It is important to recognize though that create_partition_by_restriction is more general and considerably more powerful and there are partitions that you can make using create_partition_by_restriction that you can't with create_partition_by_blockify (e.g. aliased partitions).

AngryBear2 commented 9 months ago

Yes, I also realize that create_partition_by_restriction is a very flexible way to partition, thanks for the help.

AngryBear2 commented 9 months ago

I'd actually recommend starting with create_partition_by_blockify which is a special case of create_partition_by_restriction that will make a disjoint partition the way many users expect simply by specifying the "blocking factors" along each dimension. It is important to recognize though that create_partition_by_restriction is more general and considerably more powerful and there are partitions that you can make using create_partition_by_restriction that you can't with create_partition_by_blockify (e.g. aliased partitions).

When I need to implement a matrix transposition, my input area needs to be partitioned by row, so my output area needs to be partitioned by column, my Rect<3> color_bounds(Point<3>(0, 0, 0), Point<3>(0, num_slice-1, 0)) . No error is reported when the input area is partitioned, but a problem occurs when the output area is partitioned. When I submit the launcher and use the color_is generated by the color_bounds, my color_bounds is divided into the first dimension. I don't report errors in the output area, and I report errors in the input area. image image When I comment out part of the code in the output area, this error does not occur. image In this case, how do I start the IndexLauncher?