- 博客(30)
- 收藏
- 关注
原创 STL: multimap class
multimap 特点: 1) 根据key值,能快速访问value 2) 元素根据key值进行了排序 3) 一个key值可以对应多个value直接上程序看用法:#include<fstream>#include<iostream>#include<math.h>#include<map>using namespace std;int main(int argc,char** argv
2016-03-25 03:13:26
573
转载 Boost skeleton-content 问题
看起来boost 中skeleton-content 并没有那么好用,看下列:root试图传递一个complex 的vector给其他process:#include "stdafx.h"#include <boost/mpi.hpp>#include <boost/mpi/skeleton_and_content.hpp>#include <boost/serialization/compl
2016-03-08 23:02:16
507
原创 Boost mpi gatherv example
#include "stdafx.h"#include <boost/mpi.hpp>#include <iostream>#include <vector>#include "VecAndMatrix.h"namespace mpi = boost::mpi;#define Nelement 17class cPoint{private: friend class boost::
2016-03-05 01:19:26
982
原创 boost mpi send recv-vector<class>
接上例:如果vector中元素是class,要将他们分给不同进程,程序如下:#include "stdafx.h"#include <boost/mpi.hpp>#include <iostream>#include <vector>#include "VecAndMatrix.h"namespace mpi = boost::mpi;class cPoint{private: fr
2016-03-01 05:12:04
665
原创 Boost MPI send and recv
#include "stdafx.h"#include <boost/mpi.hpp>#include <iostream>#include <vector>#include "VecAndMatrix.h"namespace mpi = boost::mpi;class cPoint{private: friend class boost::serialization::acces
2016-02-27 11:56:40
852
原创 Boost MPI scatter
boost::mpi::scatter 可以把一个vector中的元素传递给其他所有进程。#include "stdafx.h"#include <boost/mpi.hpp>#include <boost/serialization/string.hpp>#include <vector>#include <string>#include <iostream>namespace mpi
2016-02-27 07:08:28
1244
原创 Application of Boost MPI
Boost MPI provides a convenient wrapper to send/receive c++ objects.#include "stdafx.h"#include <boost/mpi.hpp>#include <iostream>#include <vector>#include <string>namespace mpi = boost::mpi;using
2016-02-26 05:48:05
587
原创 MS-MPI+boost 编译
First, the MPI should work, Before using Boost MPI, the computer should have a working MPI implementation. Boost MPI should work with any MPI implementation. The following codes can be used to test if
2016-02-26 03:46:20
2562
1
原创 MPI-MPI_Scatterv vector
Goal: 有一个vector, 对每个元素进行一个除法操作,然后将结果再收集到主结点。直接上程序:#include"stdafx.h"#include"mpi.h"#include"stdio.h"#include"stdlib.h"#include<iostream>#define N 20using namespace std;int main(int argc,char* ar
2016-02-17 23:06:51
2298
原创 CPP-vector erase while looping
从一个vector 删除元素:#include <vector>#include <iostream>using namespace std;int main(){ std::vector<double> myDouble; std::vector<double> ::iterator it; for(int i=1;i<11;i++){myDouble.push_ba
2016-02-11 08:25:11
680
翻译 CPP-static members
某些情况,一个类中所有对象有一些公有成分。在面向对象的环境中,称之为类变量(class variables). C++中称为静态成员(static members). 有趣的是,一个静态数据成员只在一个单个的实例中存在,但这个实例被这个类中所有对象分享。静态数据成员的好例子是用来记录给定时刻一个确定类型的对象数目的变量。拿银行账户为例,账户持有人,金额数等是普通数据成员。然而利息率是个静态数据成员:
2015-12-18 06:19:42
536
翻译 CPP-Templates
如果我们要处理一批数据,则可以构造一个vector container. 假设数据是整数。随后我们需要类似的操作,但操作数是double。我们就要重新实现前面的container. 另外例子包括构造一个比较大小的函数,如果函数是整数,双精度,或者字符,我们需要分别实现。这显然是重复。为了解决此类问题,c++推出了摸版类。类似概念还有函数摸版。 见下例子:#include <iostream>us
2015-12-15 05:41:06
382
原创 CPP-operator==, <overloading
如果已经定义了operator==,那么operator!=很容易实现,只要调用operator==,然后取反。bool Array::operator!=(const Array& v) const{ return !((*this) == v);}这个函数的形式实际上和具体的类无关。即如果定义了operator==,那么总能根据这个模式定义operatot!=. 同样,如果定义了<,
2015-12-14 22:51:58
916
翻译 CPP-operator= overloding
c++很好的一个优点就是根据用户定义的类,操作符有不同的意义。这就叫operator overloading. 一般通过在类中提供一个特别的成员函数来实现。可以被overloading的操作符有以下几种:= (assignment operator)+ - * (binary arithmetic operators)+= -= *= (compound assignment operators
2015-12-14 08:57:19
662
翻译 C++ Operators
就类而言,c++几乎没有预先定义的操作符。当使用类定义自己的类型时,往往希望能够有适用于这些自定义类型的操作。 当定义自己操作符时,需要写一个名字是operatorX的函数,X代表操作符,如operator+, operator是c++保留字。 1)基本上所有预定义的操作符都能够被重载。而且只有标准操作列表中的才能够被重载。 2)重载的操作符和预先定义的操作符应该有相同的操作数。例如,oper
2015-12-11 23:32:14
670
翻译 CPP-Constructor, destructors and inheritance
Constructor, destructors and inheritance 和别的对象类似,导出类的对象也能够用构造函数初始化。当调用构造函数时候,从基类继承过来的数据成员也必须初始化。这个通过调用基类的构造函数实现。而导出类对象中剩下的部分则通过调用导出类特定的构造函数初始化。继续用前面person, employee, programmer类做例子。class Person{publi
2015-10-15 05:38:01
559
翻译 CPP-Inheritance
Derived Classes 如果已经有一个一般的类,现在要基于此类建立另外一个类。此时就要用到类的继承。例如,现在已经有个类employee, 想建立一个manager类。manager是特殊的employee. 可以用继承机制来建立。class Manager : public Employee{ public: new member functions
2015-10-10 05:24:41
443
翻译 CPP-constant object & pointer this
1: 常对象(constant objects) 对象通常是指类型为类的一种变量。我们已知可以声明常变量和函数参数,这对类也适用。如:const Clock ck;如果试图调用一个成员函数去改变常对象:ck.tick(); //error或者,如果调用一个有指针或引用(reference)指向可变的Clock作为参数:void f1(Clock *cp);void f2(Clock& cr);
2015-09-24 04:20:30
507
翻译 CPP-Calling constructors(调用构造函数)
构造函数的调用: 构造函数和普通函数调用有所区别,看以下生成类Clock对象的几条语句:Clock c1;Clock c2(8,25,30);Clock c3=Clock(22,15,10)Clock *p1,*p2;p1=new Clock;p2=new Clock(14,5,40);第一行:类Clock的默认构造函数将被自动调用,意味着c1的数据成员被设置为0. 第二和第三行在声明一
2015-09-20 00:28:29
761
翻译 CPP-Constructors
当declare一个普通变量时候,可以初始化,类却不允许这么做。例如:class C{int i=0; //ERROR, initialization forbiddenconst int k=0;//ERROR, initialization forbidden当declare一个类的对象时候,此对象中所有数据成员是没有初始化的状态,直到用其他方式来初始化此对象。最简单的方式是用constru
2015-09-20 00:14:25
723
翻译 CPP-类的位置(Placement of class)
当写简单程序时候,所有东西可以放在一个文件中,但程序较大时,这样做并不明智。前面我们讨论过如何将程序分割,即应该成对的构建程序文件。对每个函数定义文件(definition),应该有相应的函数声明头文件(declaration). 对类,我们有类似的原则。即应该成对的创建文件,一个头文件和一个定义文件。类的定义被放在头文件中,相应的定义文件放置成员函数的定义,只有内联函数的实现才可以放在头文件中,其
2015-09-19 06:36:36
709
翻译 CPP-类定义(Class definitions)
Member function 的declaration和普通函数一样。仅有的差别是放在类的定义里面。同样数据成员的declaration和普通变量也一样,只是放在类的定义里面。保留字public和private用来实现信息隐藏。public暗示被宣称的属性在类的定义的后续部分是可见的。即到处都可获得。private暗示只能在类的内部获得。 如果没有指明是public或private,类中所有成员默
2015-09-19 03:59:16
4202
原创 Example-2-MPI_Scatterv,MPI_Send,MPI_Recv
此例将例1扩展一点,根进程分散数据后,进程间再进行数据交换,具体来说,第i个进程发送一定量的数据到第i+1和第i-1个进程。注意每个进程要更新当前数据,数据交换过程如下图所示:
2015-08-20 06:23:49
954
原创 Example-1-MPI_Scatterv and MPI_Gather
目的:利用例子说明collective communication函数功能
2015-08-19 02:43:36
1709
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人