forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoarray.cpp
More file actions
38 lines (33 loc) · 1.26 KB
/
coarray.cpp
File metadata and controls
38 lines (33 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//===-- runtime/coarray.cpp -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "flang/Runtime/coarray.h"
#include "flang-rt/runtime/descriptor.h"
#include "flang-rt/runtime/type-info.h"
namespace Fortran::runtime {
extern "C" {
RT_EXT_API_GROUP_BEGIN
void RTDEF(ComputeLastUcobound)(
int num_images, const Descriptor &lcobounds, const Descriptor &ucobounds) {
int corank = ucobounds.GetDimension(0).Extent();
int64_t *lcobounds_ptr = (int64_t *)lcobounds.raw().base_addr;
int64_t *ucobounds_ptr = (int64_t *)ucobounds.raw().base_addr;
int64_t index = 1;
for (int i = 0; i < corank - 1; i++) {
index *= ucobounds_ptr[i] - lcobounds_ptr[i] + 1;
}
if (corank == 1)
ucobounds_ptr[0] = num_images - lcobounds_ptr[0] + 1;
else if (index < num_images)
ucobounds_ptr[corank - 1] =
(num_images / index) + (num_images % index != 0);
else
ucobounds_ptr[corank - 1] = lcobounds_ptr[corank - 1];
}
RT_EXT_API_GROUP_END
}
} // namespace Fortran::runtime