Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
fmpi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
raphael.bach
fmpi
Commits
69208110
Verified
Commit
69208110
authored
3 years ago
by
raphael.bach
Browse files
Options
Downloads
Patches
Plain Diff
Refactor `fmpi_reduce`
parent
3feb2764
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/fmpi_reduce.h
+18
-7
18 additions, 7 deletions
include/fmpi_reduce.h
include/internal/generic/fmpi_reduce_generic.h
+13
-13
13 additions, 13 deletions
include/internal/generic/fmpi_reduce_generic.h
src/fmpi_reduce.c
+28
-29
28 additions, 29 deletions
src/fmpi_reduce.c
with
59 additions
and
49 deletions
include/fmpi_reduce.h
+
18
−
7
View file @
69208110
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
* @license{
* @license{
* BSD Zero Clause License
* BSD Zero Clause License
*
*
* Copyright (c) 2022 by Raphael Bach
*
* Permission to use, copy, modify, and/or distribute this software for any
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
* purpose with or without fee is hereby granted.
*
*
...
@@ -24,11 +26,8 @@
...
@@ -24,11 +26,8 @@
/*==============================================================================
/*==============================================================================
INCLUDE
INCLUDE
==============================================================================*/
==============================================================================*/
// C Standard Library
// External
// Internal
// Internal
#include
"fmpi_ctx.h"
#include
"internal/generic/fmpi_reduce_generic.h"
#include
"internal/fmpi_reduce_internal.h"
/*==============================================================================
/*==============================================================================
PUBLIC FUNCTION
PUBLIC FUNCTION
==============================================================================*/
==============================================================================*/
...
@@ -50,7 +49,19 @@
...
@@ -50,7 +49,19 @@
*/
*/
#define fmpi_local_reduce_prod(ctx, array, length) \
#define fmpi_local_reduce_prod(ctx, array, length) \
FMPI_GENERIC_FUNC(array, local_reduce_prod, FMPI_REDUCE_PROD_TYPES)(ctx, array, length)
FMPI_GENERIC_FUNC(array, local_reduce_prod, FMPI_REDUCE_PROD_TYPES)(ctx, array, length)
/*------------------------------------------------------------------------------
fmpi_reduce_prod()
------------------------------------------------------------------------------*/
/**
* TODO
*
* @param ctx : TODO
* @param array : TODO
*
* @example{
* TODO
* }
*/
#define fmpi_reduce_prod(ctx, array) \
#define fmpi_reduce_prod(ctx, array) \
FMPI_GENERIC_FUNC(array, reduce_prod, FMPI_REDUCE_PROD_TYPES)(ctx, array)
FMPI_GENERIC_FUNC(array, reduce_prod, FMPI_REDUCE_PROD_TYPES)(ctx, array)
/*==============================================================================
/*==============================================================================
...
...
This diff is collapsed.
Click to expand it.
include/internal/fmpi_reduce_
internal
.h
→
include/internal/
generic/
fmpi_reduce_
generic
.h
+
13
−
13
View file @
69208110
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
* @license{
* @license{
* BSD Zero Clause License
* BSD Zero Clause License
*
*
* Copyright (c) 2022 by Raphael Bach
*
* Permission to use, copy, modify, and/or distribute this software for any
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
* purpose with or without fee is hereby granted.
*
*
...
@@ -24,27 +26,25 @@
...
@@ -24,27 +26,25 @@
/*==============================================================================
/*==============================================================================
INCLUDE
INCLUDE
==============================================================================*/
==============================================================================*/
// C Standard Library
#include
<stddef.h>
// size_t
// Internal
// Internal
#include
"fmpi_ctx.h"
#include
"fmpi_generic.h"
#include
"fmpi_generic.h"
/*==============================================================================
/*==============================================================================
MACRO
MACRO
==============================================================================*/
==============================================================================*/
struct
fmpi_ctx
;
#define FMPI_REDUCE_PROD_TYPES \
#define FMPI_REDUCE_PROD_TYPES \
FMPI_TYPE_REAL
FMPI_TYPE_REAL
#define FMPI_
PROTO_LOCAL_REDUCE_PROD(T)
\
#define FMPI_
REDUCE_DECLARATION(T)
\
T fmpi_local_reduce_prod_##T(
struct fmpi_ctx * const ctx, T * const array, int length)
T fmpi_local_reduce_prod_##T(
\
const struct fmpi_ctx * ctx, const T * array, size_t length \
#define FMPI_PROTO_REDUCE_PROD(T)
\
);
\
T fmpi_reduce_prod_##T(struct fmpi_ctx * c
onst ctx, T *
const array)
T fmpi_reduce_prod_##T(
const
struct fmpi_ctx * c
tx,
const
T *
array)
FMPI_DECLARE_FUNC
(
FMPI_DECLARE_FUNCS
(
FMPI_REDUCE_DECLARATION
,
FMPI_REDUCE_PROD_TYPES
);
FMPI_PROTO_LOCAL_REDUCE_PROD
,
FMPI_REDUCE_PROD_TYPES
);
FMPI_DECLARE_FUNC
(
FMPI_PROTO_REDUCE_PROD
,
FMPI_REDUCE_PROD_TYPES
);
/*==============================================================================
/*==============================================================================
GUARD
GUARD
==============================================================================*/
==============================================================================*/
...
...
This diff is collapsed.
Click to expand it.
src/fmpi_reduce.c
+
28
−
29
View file @
69208110
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
* @license{
* @license{
* BSD Zero Clause License
* BSD Zero Clause License
*
*
* Copyright (c) 2022 by Raphael Bach
*
* Permission to use, copy, modify, and/or distribute this software for any
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
* purpose with or without fee is hereby granted.
*
*
...
@@ -26,40 +28,39 @@
...
@@ -26,40 +28,39 @@
#include
<stdint.h>
#include
<stdint.h>
#include
<stdio.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<stdlib.h>
#include
<string.h>
// Internal
// Internal
#include
"fmpi_futhark.h"
#include
"internal/fmpi_ctx.h"
#include
"fmpi_mpi.h"
#include
"internal/fmpi_futhark.h"
#include
"internal/fmpi_fut.h"
#include
"internal/fmpi_futhark_entry.h"
#include
"internal/fmpi_generic.h"
#include
"internal/fmpi_mpi.h"
#include
"internal/generic/fmpi_generic.h"
/*==============================================================================
/*==============================================================================
STRUCT
STRUCT
==============================================================================*/
==============================================================================*/
/*==============================================================================
/*==============================================================================
PUBLIC FUNCTION
PUBLIC FUNCTION
==============================================================================*/
==============================================================================*/
#define FMPI_DEFINE_LOCAL_REDUCE_PROD(T) \
#define FMPI_REDUCE_DEFINITION(T) \
FMPI_PROTO_LOCAL_REDUCE_PROD(T) \
T fmpi_local_reduce_prod_##T( \
{ \
const struct fmpi_ctx * const ctx, const T * const array, const size_t length \
){ \
assert(ctx != NULL); \
assert(ctx != NULL); \
assert(array != NULL); \
assert(array != NULL); \
\
struct futhark_##T##_1d * data = fmpi_futhark_new_1d_##T(ctx, array, length);\
struct futhark_##T##_1d * xs = fmpi_new_##T##_1d(ctx, array, length);\
T result = FMPI_TYPE_DEFAULT_##T; \
T result = FMPI_DEFAULT_VALUE_##T; \
const int err = futhark_entry_reduce_prod_##T(ctx->fut->ctx, &result, data); \
futhark_entry_reduce_prod_##T(ctx->futhark, &result, xs); \
if(err != 0) { \
fmpi_futhark_abort_on_error(ctx, CPL_STRINGIFY(futhark_entry_reduce_prod_##T())); \
fmpi_futhark_check_error(ctx->fut, CPL_STRINGIFY(futhark_entry_reduce_prod_##T)); \
fmpi_futhark_sync(ctx); \
} \
fmpi_free_##T##_1d(ctx, xs); \
fmpi_futhark_sync(ctx->fut); \
fmpi_futhark_free_1d_##T(ctx, data); \
return result; \
return result; \
}
}\
T fmpi_reduce_prod_##T(const struct fmpi_ctx * const ctx, const T * const array) \
#define FMPI_DEFINE_REDUCE_PROD(T) \
FMPI_PROTO_REDUCE_PROD(T) \
{ \
{ \
assert(ctx != NULL); \
assert(ctx != NULL); \
assert(array != NULL); \
assert(array != NULL); \
\
T result = FMPI_TYPE_DEFAULT_##T; \
T result = FMPI_DEFAULT_VALUE_##T; \
/*! @cast MPI uses `int` for `size`. */
\
/*! @cast MPI uses `int` for `size`. */
\
/* Casting `int` to `size_t` should be safe if the value isn't negative. */
\
/* Casting `int` to `size_t` should be safe if the value isn't negative. */
\
/* This is asserted in`fmpi_init()`.*/
\
/* This is asserted in`fmpi_init()`.*/
\
...
@@ -67,17 +68,15 @@ FMPI_PROTO_REDUCE_PROD(T) \
...
@@ -67,17 +68,15 @@ FMPI_PROTO_REDUCE_PROD(T) \
if(fact_global == NULL) { \
if(fact_global == NULL) { \
fprintf(stderr, "malloc(fact_global) failed!\n"); \
fprintf(stderr, "malloc(fact_global) failed!\n"); \
} \
} \
int err_id = MPI_Gather(array, 1, FMPI_
MPI_DATA
TYPE_##T, fact_global, 1, FMPI_
MPI_DATA
TYPE_##T, ctx->mpi->root, MPI_COMM_WORLD); \
int err_id = MPI_Gather(array, 1, FMPI_TYPE
_MPI
_##T, fact_global, 1, FMPI_TYPE
_MPI
_##T, ctx->mpi->root, MPI_COMM_WORLD); \
if(fmpi_mpi_
has
_error(ctx->mpi, err_id, "MPI_Gather()")) { \
if(fmpi_mpi_
check
_error(ctx->mpi, err_id, "MPI_Gather()")
== true
) { \
free(fact_global); \
free(fact_global); \
fmpi_abort(ctx); \
} \
} \
if(fmpi_mpi_is_root(ctx->mpi)) { \
if(fmpi_mpi_is_root(ctx->mpi)) { \
result = fmpi_local_reduce_prod_##T(ctx, fact_global, ctx->mpi->size); \
result = fmpi_local_reduce_prod_##T(ctx, fact_global,
(size_t)
ctx->mpi->size); \
} \
} \
free(fact_global); \
free(fact_global); \
return result; \
return result; \
}
}
FMPI_DEFINE_FUNC
(
FMPI_DEFINE_LOCAL_REDUCE_PROD
,
FMPI_REDUCE_PROD_TYPES
)
FMPI_DEFINE_FUNCS
(
FMPI_REDUCE_DEFINITION
,
FMPI_REDUCE_PROD_TYPES
)
FMPI_DEFINE_FUNC
(
FMPI_DEFINE_REDUCE_PROD
,
FMPI_REDUCE_PROD_TYPES
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment