Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Reorganize "domain" code #732

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/C-interface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(HEADERS-C
bml_convert.h
bml_copy.h
bml_diagonalize.h
bml_domain.h
bml_elemental.h
bml_export.h
bml_getters.h
Expand Down Expand Up @@ -48,6 +49,7 @@ set(SOURCES-C
bml_convert.c
bml_copy.c
bml_diagonalize.c
bml_domain.c
bml_elemental.c
bml_export.c
bml_getters.c
Expand Down
139 changes: 1 addition & 138 deletions src/C-interface/bml_allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,24 +199,6 @@ bml_deallocate(
}
}

/** Deallocate a domain.
*
* \ingroup allocate_group_C
*
* \param D[in,out] The domain.
*/
void
bml_deallocate_domain(
bml_domain_t * D)
{
bml_free_memory(D->localRowMin);
bml_free_memory(D->localRowMax);
bml_free_memory(D->localRowExtent);
bml_free_memory(D->localDispl);
bml_free_memory(D->localElements);
bml_free_memory(D);
}

/** Clear a matrix.
*
* \ingroup allocate_group_C
Expand Down Expand Up @@ -587,125 +569,6 @@ bml_identity_matrix(
return NULL;
}

/** Allocate a default domain for a bml matrix.
*
* \ingroup allocate_group_C
*
* \param N The number of rows
* \param M The number of columns
* \param distrib_mode The distribution mode
* \return The domain
*/
bml_domain_t *
bml_default_domain(
int N,
int M,
bml_distribution_mode_t distrib_mode)
{
int avgExtent, nleft;
int nRanks = bml_getNRanks();

bml_domain_t *domain = bml_allocate_memory(sizeof(bml_domain_t));

domain->localRowMin = bml_allocate_memory(nRanks * sizeof(int));
domain->localRowMax = bml_allocate_memory(nRanks * sizeof(int));
domain->localRowExtent = bml_allocate_memory(nRanks * sizeof(int));
domain->localDispl = bml_allocate_memory(nRanks * sizeof(int));
domain->localElements = bml_allocate_memory(nRanks * sizeof(int));

domain->totalProcs = nRanks;
domain->totalRows = N;
domain->totalCols = M;

domain->globalRowMin = 0;
domain->globalRowMax = domain->totalRows;
domain->globalRowExtent = domain->globalRowMax - domain->globalRowMin;

switch (distrib_mode)
{
case sequential:
{
// Default - each rank contains entire matrix, even when running distributed
for (int i = 0; i < nRanks; i++)
{
domain->localRowMin[i] = domain->globalRowMin;
domain->localRowMax[i] = domain->globalRowMax;
domain->localRowExtent[i] =
domain->localRowMax[i] - domain->localRowMin[i];
domain->localElements[i] =
domain->localRowExtent[i] * domain->totalCols;
domain->localDispl[i] = 0;
}

}
break;

case distributed:
{
// For completely distributed
avgExtent = N / nRanks;
domain->maxLocalExtent = ceil((float) N / (float) nRanks);
domain->minLocalExtent = avgExtent;

for (int i = 0; i < nRanks; i++)
{
domain->localRowExtent[i] = avgExtent;
}
nleft = N - nRanks * avgExtent;
if (nleft > 0)
{
for (int i = 0; i < nleft; i++)
{
domain->localRowExtent[i]++;
}
}

/** For first rank */
domain->localRowMin[0] = domain->globalRowMin;
domain->localRowMax[0] = domain->localRowExtent[0];

/** For middle ranks */
for (int i = 1; i < (nRanks - 1); i++)
{
domain->localRowMin[i] = domain->localRowMax[i - 1];
domain->localRowMax[i] =
domain->localRowMin[i] + domain->localRowExtent[i];
}

/** For last rank */
if (nRanks > 1)
{
int last = nRanks - 1;
domain->localRowMin[last] = domain->localRowMax[last - 1];
domain->localRowMax[last] =
domain->localRowMin[last] + domain->localRowExtent[last];
}

/** Number of elements and displacement per rank */
for (int i = 0; i < nRanks; i++)
{
domain->localElements[i] =
domain->localRowExtent[i] * domain->totalCols;
domain->localDispl[i] =
(i ==
0) ? 0 : domain->localDispl[i - 1] +
domain->localElements[i - 1];
}
}
break;

case graph_distributed:
LOG_ERROR("graph_distibuted not available\n");
break;

default:
LOG_ERROR("unknown distribution method\n");
break;
}

return domain;
}

/** Update a domain for a bml matrix.
*
* \ingroup allocate_group_C
Expand All @@ -716,7 +579,7 @@ bml_default_domain(
* \param nnodesInPart Number of nodes in each part
*/
void
bml_update_domain(
bml_update_domain_matrix(
bml_matrix_t * A,
int *localPartMin,
int *localPartMax,
Expand Down
10 changes: 1 addition & 9 deletions src/C-interface/bml_allocate.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ void bml_free_ptr(
void bml_deallocate(
bml_matrix_t ** A);

void bml_deallocate_domain(
bml_domain_t * D);

void bml_clear(
bml_matrix_t * A);

Expand Down Expand Up @@ -76,12 +73,7 @@ bml_matrix_t *bml_identity_matrix(
int M,
bml_distribution_mode_t distrib_mode);

bml_domain_t *bml_default_domain(
int N,
int M,
bml_distribution_mode_t distrib_mode);

void bml_update_domain(
void bml_update_domain_matrix(
bml_matrix_t * A,
int *localPartMin,
int *localPartMax,
Expand Down
20 changes: 0 additions & 20 deletions src/C-interface/bml_copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,26 +142,6 @@ bml_reorder(
}
}

/** Copy a domain.
*
* \param A Domain to copy
* \param B Copy of Domain A
*/
void
bml_copy_domain(
bml_domain_t * A,
bml_domain_t * B)
{
int nRanks = bml_getNRanks();

memcpy(B->localRowMin, A->localRowMin, nRanks * sizeof(int));
memcpy(B->localRowMax, A->localRowMax, nRanks * sizeof(int));
memcpy(B->localRowExtent, A->localRowExtent, nRanks * sizeof(int));
memcpy(B->localDispl, A->localDispl, nRanks * sizeof(int));
memcpy(B->localElements, A->localElements, nRanks * sizeof(int));
}


/** Save current domain for bml matrix.
*
* \param A Matrix with domain
Expand Down
4 changes: 0 additions & 4 deletions src/C-interface/bml_copy.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ void bml_reorder(
bml_matrix_t * A,
int *perm);

void bml_copy_domain(
bml_domain_t * A,
bml_domain_t * B);

void bml_save_domain(
bml_matrix_t * A);

Expand Down
Loading