Skip to content

Commit

Permalink
Revert "Reorganize "domain" code" (#747)
Browse files Browse the repository at this point in the history
This reverts commit 37f6087.
  • Loading branch information
jeanlucf22 authored Dec 11, 2023
1 parent 5033308 commit 4915807
Show file tree
Hide file tree
Showing 22 changed files with 306 additions and 263 deletions.
2 changes: 0 additions & 2 deletions src/C-interface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ 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 @@ -49,7 +48,6 @@ 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: 138 additions & 1 deletion src/C-interface/bml_allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,24 @@ 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 @@ -569,6 +587,125 @@ 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 @@ -579,7 +716,7 @@ bml_identity_matrix(
* \param nnodesInPart Number of nodes in each part
*/
void
bml_update_domain_matrix(
bml_update_domain(
bml_matrix_t * A,
int *localPartMin,
int *localPartMax,
Expand Down
10 changes: 9 additions & 1 deletion src/C-interface/bml_allocate.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ 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 @@ -73,7 +76,12 @@ bml_matrix_t *bml_identity_matrix(
int M,
bml_distribution_mode_t distrib_mode);

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

void bml_update_domain(
bml_matrix_t * A,
int *localPartMin,
int *localPartMax,
Expand Down
20 changes: 20 additions & 0 deletions src/C-interface/bml_copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,26 @@ 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: 4 additions & 0 deletions src/C-interface/bml_copy.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ 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

0 comments on commit 4915807

Please # to comment.