如何使用MPI并行化最大子数组问题?

问题描述

最大子数组问题包括找到在数组内部具有最大总和的子数组。

假设我有A = [-2,1,-3,4,-1,2,1-5,4],则最大子数组为[4,-1,1],总和为6。

下面的代码是max子数组问题的顺序答案

#include<iostream> 
#include<climits> 
using namespace std; 

int main() 
{ 
    int a[] = {-2,-3,4,-1,-2,1,5,-3}; 
    int size = sizeof(a)/sizeof(a[0]); 
    int max_so_far = INT_MIN,max_ending_here = 0; 

    for (int i = 0; i < size; i++) 
    { 
        max_ending_here = max_ending_here + a[i]; 
        if (max_so_far < max_ending_here) 
            max_so_far = max_ending_here; 

        if (max_ending_here < 0) 
            max_ending_here = 0; 
    } 
    cout << "Maximum contiguous sum is " << max_so_far; 
    return 0; 
} 

如何使用MPI并行处理此代码?

感谢您的帮助!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...