mirror of
https://github.com/PhasicFlow/phasicFlow.git
synced 2025-07-28 03:27:05 +00:00
Zoltan is added as thirdParty package
This commit is contained in:
51
thirdParty/Zoltan/src/matlab/README
vendored
Normal file
51
thirdParty/Zoltan/src/matlab/README
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
# @HEADER
|
||||
#
|
||||
########################################################################
|
||||
#
|
||||
# Zoltan Toolkit for Load-balancing, Partitioning, Ordering and Coloring
|
||||
# Copyright 2012 Sandia Corporation
|
||||
#
|
||||
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
# the U.S. Government retains certain rights in this software.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the Corporation nor the names of the
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
|
||||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
# Questions? Contact Karen Devine kddevin@sandia.gov
|
||||
# Erik Boman egboman@sandia.gov
|
||||
#
|
||||
########################################################################
|
||||
#
|
||||
# @HEADER
|
||||
This directory contains a crude Matlab interface to Zoltan
|
||||
for partitioning sparse matrices (by rows or columns).
|
||||
This is not a finished product, but work in progress that you
|
||||
may find useful. This version is quite slow (inefficient) since it
|
||||
is based on file input/output instead of a direct mex interface.
|
||||
You will need to build the zdrive test driver in Zoltan ('make zdrive')
|
||||
before calling the zoltan Matlab function.
|
||||
|
222
thirdParty/Zoltan/src/matlab/mmread.m
vendored
Normal file
222
thirdParty/Zoltan/src/matlab/mmread.m
vendored
Normal file
@ -0,0 +1,222 @@
|
||||
function [A,rows,cols,entries,rep,field,symm] = mmread(filename)
|
||||
%
|
||||
% function [A] = mmread(filename)
|
||||
%
|
||||
% function [A,rows,cols,entries,rep,field,symm] = mmread(filename)
|
||||
%
|
||||
% Reads the contents of the Matrix Market file 'filename'
|
||||
% into the matrix 'A'. 'A' will be either sparse or full,
|
||||
% depending on the Matrix Market format indicated by
|
||||
% 'coordinate' (coordinate sparse storage), or
|
||||
% 'array' (dense array storage). The data will be duplicated
|
||||
% as appropriate if symmetry is indicated in the header.
|
||||
%
|
||||
% Optionally, size information about the matrix can be
|
||||
% obtained by using the return values rows, cols, and
|
||||
% entries, where entries is the number of nonzero entries
|
||||
% in the final matrix. Type information can also be retrieved
|
||||
% using the optional return values rep (representation), field,
|
||||
% and symm (symmetry).
|
||||
%
|
||||
|
||||
mmfile = fopen(filename,'r');
|
||||
if ( mmfile == -1 )
|
||||
disp(filename);
|
||||
error('File not found');
|
||||
end;
|
||||
|
||||
header = fgets(mmfile);
|
||||
if (header == -1 )
|
||||
error('Empty file.')
|
||||
end
|
||||
|
||||
% NOTE: If using a version of Matlab for which strtok is not
|
||||
% defined, substitute 'gettok' for 'strtok' in the
|
||||
% following lines, and download gettok.m from the
|
||||
% Matrix Market site.
|
||||
[head0,header] = strtok(header); % see note above
|
||||
[head1,header] = strtok(header);
|
||||
[rep,header] = strtok(header);
|
||||
[field,header] = strtok(header);
|
||||
[symm,header] = strtok(header);
|
||||
head1 = lower(head1);
|
||||
rep = lower(rep);
|
||||
field = lower(field);
|
||||
symm = lower(symm);
|
||||
if ( length(symm) == 0 )
|
||||
disp(['Not enough words in header line of file ',filename])
|
||||
disp('Recognized format: ')
|
||||
disp('%%MatrixMarket matrix representation field symmetry')
|
||||
error('Check header line.')
|
||||
end
|
||||
if ( ~ strcmp(head0,'%%MatrixMarket') )
|
||||
error('Not a valid MatrixMarket header.')
|
||||
end
|
||||
if ( ~ strcmp(head1,'matrix') )
|
||||
disp(['This seems to be a MatrixMarket ',head1,' file.']);
|
||||
disp('This function only knows how to read MatrixMarket matrix files.');
|
||||
disp(' ');
|
||||
error(' ');
|
||||
end
|
||||
|
||||
% Read through comments, ignoring them
|
||||
|
||||
commentline = fgets(mmfile);
|
||||
while length(commentline) > 0 & commentline(1) == '%',
|
||||
commentline = fgets(mmfile);
|
||||
end
|
||||
|
||||
% Read size information, then branch according to
|
||||
% sparse or dense format
|
||||
|
||||
if ( strcmp(rep,'coordinate')) % read matrix given in sparse
|
||||
% coordinate matrix format
|
||||
|
||||
[sizeinfo,count] = sscanf(commentline,'%d%d%d');
|
||||
while ( count == 0 )
|
||||
commentline = fgets(mmfile);
|
||||
if (commentline == -1 )
|
||||
error('End-of-file reached before size information was found.')
|
||||
end
|
||||
[sizeinfo,count] = sscanf(commentline,'%d%d%d');
|
||||
if ( count > 0 & count ~= 3 )
|
||||
error('Invalid size specification line.')
|
||||
end
|
||||
end
|
||||
rows = sizeinfo(1);
|
||||
cols = sizeinfo(2);
|
||||
entries = sizeinfo(3);
|
||||
|
||||
if ( strcmp(field,'real') ) % real valued entries:
|
||||
|
||||
[T,count] = fscanf(mmfile,'%f',3);
|
||||
T = [T; fscanf(mmfile,'%f')];
|
||||
if ( size(T) ~= 3*entries )
|
||||
message = ...
|
||||
str2mat('Data file does not contain expected amount of data.',...
|
||||
'Check that number of data lines matches nonzero count.');
|
||||
disp(message);
|
||||
error('Invalid data.');
|
||||
end
|
||||
T = reshape(T,3,entries)';
|
||||
A = sparse(T(:,1), T(:,2), T(:,3), rows , cols);
|
||||
|
||||
elseif ( strcmp(field,'complex')) % complex valued entries:
|
||||
|
||||
T = fscanf(mmfile,'%f',4);
|
||||
T = [T; fscanf(mmfile,'%f')];
|
||||
if ( size(T) ~= 4*entries )
|
||||
message = ...
|
||||
str2mat('Data file does not contain expected amount of data.',...
|
||||
'Check that number of data lines matches nonzero count.');
|
||||
disp(message);
|
||||
error('Invalid data.');
|
||||
end
|
||||
T = reshape(T,4,entries)';
|
||||
A = sparse(T(:,1), T(:,2), T(:,3) + T(:,4)*sqrt(-1), rows , cols);
|
||||
|
||||
elseif ( strcmp(field,'pattern')) % pattern matrix (no values given):
|
||||
|
||||
T = fscanf(mmfile,'%f',2);
|
||||
T = [T; fscanf(mmfile,'%f')];
|
||||
if ( size(T) ~= 2*entries )
|
||||
message = ...
|
||||
str2mat('Data file does not contain expected amount of data.',...
|
||||
'Check that number of data lines matches nonzero count.');
|
||||
disp(message);
|
||||
error('Invalid data.');
|
||||
end
|
||||
T = reshape(T,2,entries)';
|
||||
A = sparse(T(:,1), T(:,2), ones(entries,1) , rows , cols);
|
||||
|
||||
end
|
||||
|
||||
elseif ( strcmp(rep,'array') ) % read matrix given in dense
|
||||
% array (column major) format
|
||||
|
||||
[sizeinfo,count] = sscanf(commentline,'%d%d');
|
||||
while ( count == 0 )
|
||||
commentline = fgets(mmfile);
|
||||
if (commentline == -1 )
|
||||
error('End-of-file reached before size information was found.')
|
||||
end
|
||||
[sizeinfo,count] = sscanf(commentline,'%d%d');
|
||||
if ( count > 0 & count ~= 2 )
|
||||
error('Invalid size specification line.')
|
||||
end
|
||||
end
|
||||
rows = sizeinfo(1);
|
||||
cols = sizeinfo(2);
|
||||
entries = rows*cols;
|
||||
if ( strcmp(field,'real') ) % real valued entries:
|
||||
A = fscanf(mmfile,'%f',1);
|
||||
A = [A; fscanf(mmfile,'%f')];
|
||||
if ( strcmp(symm,'symmetric') | strcmp(symm,'hermitian') | strcmp(symm,'skew-symmetric') )
|
||||
for j=1:cols-1,
|
||||
currenti = j*rows;
|
||||
A = [A(1:currenti); zeros(j,1);A(currenti+1:length(A))];
|
||||
end
|
||||
elseif ( ~ strcmp(symm,'general') )
|
||||
disp('Unrecognized symmetry')
|
||||
disp(symm)
|
||||
disp('Recognized choices:')
|
||||
disp(' symmetric')
|
||||
disp(' hermitian')
|
||||
disp(' skew-symmetric')
|
||||
disp(' general')
|
||||
error('Check symmetry specification in header.');
|
||||
end
|
||||
A = reshape(A,rows,cols);
|
||||
elseif ( strcmp(field,'complex')) % complx valued entries:
|
||||
tmpr = fscanf(mmfile,'%f',1);
|
||||
tmpi = fscanf(mmfile,'%f',1);
|
||||
A = tmpr+tmpi*i;
|
||||
for j=1:entries-1
|
||||
tmpr = fscanf(mmfile,'%f',1);
|
||||
tmpi = fscanf(mmfile,'%f',1);
|
||||
A = [A; tmpr + tmpi*i];
|
||||
end
|
||||
if ( strcmp(symm,'symmetric') | strcmp(symm,'hermitian') | strcmp(symm,'skew-symmetric') )
|
||||
for j=1:cols-1,
|
||||
currenti = j*rows;
|
||||
A = [A(1:currenti); zeros(j,1);A(currenti+1:length(A))];
|
||||
end
|
||||
elseif ( ~ strcmp(symm,'general') )
|
||||
disp('Unrecognized symmetry')
|
||||
disp(symm)
|
||||
disp('Recognized choices:')
|
||||
disp(' symmetric')
|
||||
disp(' hermitian')
|
||||
disp(' skew-symmetric')
|
||||
disp(' general')
|
||||
error('Check symmetry specification in header.');
|
||||
end
|
||||
A = reshape(A,rows,cols);
|
||||
elseif ( strcmp(field,'pattern')) % pattern (makes no sense for dense)
|
||||
disp('Matrix type:',field)
|
||||
error('Pattern matrix type invalid for array storage format.');
|
||||
else % Unknown matrix type
|
||||
disp('Matrix type:',field)
|
||||
error('Invalid matrix type specification. Check header against MM documentation.');
|
||||
end
|
||||
end
|
||||
|
||||
%
|
||||
% If symmetric, skew-symmetric or Hermitian, duplicate lower
|
||||
% triangular part and modify entries as appropriate:
|
||||
%
|
||||
|
||||
if ( strcmp(symm,'symmetric') )
|
||||
A = A + A.' - diag(diag(A));
|
||||
entries = nnz(A);
|
||||
elseif ( strcmp(symm,'hermitian') )
|
||||
A = A + A' - diag(diag(A));
|
||||
entries = nnz(A);
|
||||
elseif ( strcmp(symm,'skew-symmetric') )
|
||||
A = A - A';
|
||||
entries = nnz(A);
|
||||
end
|
||||
|
||||
fclose(mmfile);
|
||||
% Done.
|
||||
|
276
thirdParty/Zoltan/src/matlab/mmwrite.m
vendored
Normal file
276
thirdParty/Zoltan/src/matlab/mmwrite.m
vendored
Normal file
@ -0,0 +1,276 @@
|
||||
function [ err ] = mmwrite(filename,A,comment,field,precision)
|
||||
%
|
||||
% Function: mmwrite(filename,A,comment,field,precision)
|
||||
%
|
||||
% Writes the sparse or dense matrix A to a Matrix Market (MM)
|
||||
% formatted file.
|
||||
%
|
||||
% Required arguments:
|
||||
%
|
||||
% filename - destination file
|
||||
%
|
||||
% A - sparse or full matrix
|
||||
%
|
||||
% Optional arguments:
|
||||
%
|
||||
% comment - matrix of comments to prepend to
|
||||
% the MM file. To build a comment matrix,
|
||||
% use str2mat. For example:
|
||||
%
|
||||
% comment = str2mat(' Comment 1' ,...
|
||||
% ' Comment 2',...
|
||||
% ' and so on.',...
|
||||
% ' to attach a date:',...
|
||||
% [' ',date]);
|
||||
% If ommitted, a single line date stamp comment
|
||||
% will be included.
|
||||
%
|
||||
% field - 'real'
|
||||
% 'complex'
|
||||
% 'integer'
|
||||
% 'pattern'
|
||||
% If ommitted, data will determine type.
|
||||
%
|
||||
% precision - number of digits to display for real
|
||||
% or complex values
|
||||
% If ommitted, full working precision is used.
|
||||
%
|
||||
|
||||
if ( nargin == 5)
|
||||
mattype = field;
|
||||
% precision = 16;
|
||||
elseif ( nargin == 4)
|
||||
mattype = field;
|
||||
precision = 16;
|
||||
elseif ( nargin == 3)
|
||||
mattype = 'real'; % placeholder, will check after FIND-ing A
|
||||
precision = 16;
|
||||
elseif ( nargin == 2)
|
||||
comment = '';
|
||||
% Check whether there is an imaginary part:
|
||||
mattype = 'real'; % placeholder, will check after FIND-ing A
|
||||
precision = 16;
|
||||
end
|
||||
|
||||
mmfile = fopen([filename],'w');
|
||||
if ( mmfile == -1 )
|
||||
error('Cannot open file for output');
|
||||
end;
|
||||
|
||||
|
||||
[M,N] = size(A);
|
||||
|
||||
%%%%%%%%%%%%% This part for sparse matrices %%%%%%%%%%%%%%%%
|
||||
if ( issparse(A) )
|
||||
|
||||
[I,J,V] = find(A);
|
||||
if ( sum(abs(imag(nonzeros(V)))) > 0 )
|
||||
Vreal = 0;
|
||||
else
|
||||
Vreal = 1;
|
||||
end
|
||||
|
||||
if ( ~ strcmp(mattype,'pattern') & Vreal )
|
||||
mattype = 'real';
|
||||
elseif ( ~ strcmp(mattype,'pattern') )
|
||||
mattype = 'complex';
|
||||
end
|
||||
%
|
||||
% Determine symmetry:
|
||||
%
|
||||
if ( M ~= N )
|
||||
symm = 'general';
|
||||
issymm = 0;
|
||||
NZ = length(V);
|
||||
else
|
||||
issymm = 1;
|
||||
NZ = length(V);
|
||||
for i=1:NZ
|
||||
if ( A(J(i),I(i)) ~= V(i) )
|
||||
issymm = 0;
|
||||
break;
|
||||
end
|
||||
end
|
||||
if ( issymm )
|
||||
symm = 'symmetric';
|
||||
ATEMP = tril(A);
|
||||
[I,J,V] = find(ATEMP);
|
||||
NZ = nnz(ATEMP);
|
||||
else
|
||||
isskew = 1;
|
||||
for i=1:NZ
|
||||
if ( A(J(i),I(i)) ~= - V(i) )
|
||||
isskew = 0;
|
||||
break;
|
||||
end
|
||||
end
|
||||
if ( isskew )
|
||||
symm = 'skew-symmetric';
|
||||
ATEMP = tril(A);
|
||||
[I,J,V] = find(ATEMP);
|
||||
NZ = nnz(ATEMP);
|
||||
elseif ( strcmp(mattype,'complex') )
|
||||
isherm = 1;
|
||||
for i=1:NZ
|
||||
if ( A(J(i),I(i)) ~= conj(V(i)) )
|
||||
isherm = 0;
|
||||
break;
|
||||
end
|
||||
end
|
||||
if ( isherm )
|
||||
symm = 'hermitian';
|
||||
ATEMP = tril(A);
|
||||
[I,J,V] = find(ATEMP);
|
||||
NZ = nnz(ATEMP);
|
||||
else
|
||||
symm = 'general';
|
||||
NZ = nnz(A);
|
||||
end
|
||||
else
|
||||
symm = 'general';
|
||||
NZ = nnz(A);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
% Sparse coordinate format:
|
||||
|
||||
rep = 'coordinate';
|
||||
|
||||
|
||||
fprintf(mmfile,'%%%%MatrixMarket matrix %s %s %s\n',rep,mattype,symm);
|
||||
[MC,NC] = size(comment);
|
||||
if ( MC == 0 )
|
||||
fprintf(mmfile,'%% Generated %s\n',[date]);
|
||||
else
|
||||
for i=1:MC,
|
||||
fprintf(mmfile,'%%%s\n',comment(i,:));
|
||||
end
|
||||
end
|
||||
fprintf(mmfile,'%d %d %d\n',M,N,NZ);
|
||||
cplxformat = sprintf('%%d %%d %% .%dg %% .%dg\n',precision,precision);
|
||||
realformat = sprintf('%%d %%d %% .%dg\n',precision);
|
||||
if ( strcmp(mattype,'real') )
|
||||
for i=1:NZ
|
||||
fprintf(mmfile,realformat,I(i),J(i),V(i));
|
||||
end;
|
||||
elseif ( strcmp(mattype,'complex') )
|
||||
for i=1:NZ
|
||||
fprintf(mmfile,cplxformat,I(i),J(i),real(V(i)),imag(V(i)));
|
||||
end;
|
||||
elseif ( strcmp(mattype,'pattern') )
|
||||
for i=1:NZ
|
||||
fprintf(mmfile,'%d %d\n',I(i),J(i));
|
||||
end;
|
||||
else
|
||||
err = -1;
|
||||
disp('Unsupported mattype:')
|
||||
mattype
|
||||
end;
|
||||
|
||||
%%%%%%%%%%%%% This part for dense matrices %%%%%%%%%%%%%%%%
|
||||
else
|
||||
if ( sum(abs(imag(nonzeros(A)))) > 0 )
|
||||
Areal = 0;
|
||||
else
|
||||
Areal = 1;
|
||||
end
|
||||
if ( ~strcmp(mattype,'pattern') & Areal )
|
||||
mattype = 'real';
|
||||
elseif ( ~strcmp(mattype,'pattern') )
|
||||
mattype = 'complex';
|
||||
end
|
||||
%
|
||||
% Determine symmetry:
|
||||
%
|
||||
if ( M ~= N )
|
||||
issymm = 0;
|
||||
symm = 'general';
|
||||
else
|
||||
issymm = 1;
|
||||
for j=1:N
|
||||
for i=j+1:N
|
||||
if (A(i,j) ~= A(j,i) )
|
||||
issymm = 0;
|
||||
break;
|
||||
end
|
||||
end
|
||||
if ( ~ issymm ) break; end
|
||||
|
||||
end
|
||||
if ( issymm )
|
||||
symm = 'symmetric';
|
||||
else
|
||||
isskew = 1;
|
||||
for j=1:N
|
||||
for i=j+1:N
|
||||
if (A(i,j) ~= - A(j,i) )
|
||||
isskew = 0;
|
||||
break;
|
||||
end
|
||||
end
|
||||
if ( ~ isskew ) break; end
|
||||
end
|
||||
if ( isskew )
|
||||
symm = 'skew-symmetric';
|
||||
elseif ( strcmp(mattype,'complex') )
|
||||
isherm = 1;
|
||||
for j=1:N
|
||||
for i=j+1:N
|
||||
if (A(i,j) ~= conj(A(j,i)) )
|
||||
isherm = 0;
|
||||
break;
|
||||
end
|
||||
end
|
||||
if ( ~ isherm ) break; end
|
||||
end
|
||||
if ( isherm )
|
||||
symm = 'hermitian';
|
||||
else
|
||||
symm = 'general';
|
||||
end
|
||||
else
|
||||
symm = 'general';
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
% Dense array format:
|
||||
|
||||
rep = 'array';
|
||||
[MC,NC] = size(comment);
|
||||
fprintf(mmfile,'%%%%MatrixMarket mtx %s %s %s\n',rep,mattype,symm);
|
||||
for i=1:MC,
|
||||
fprintf(mmfile,'%%%s\n',comment(i,:));
|
||||
end;
|
||||
fprintf(mmfile,'%d %d\n',M,N);
|
||||
cplxformat = sprintf('%% .%dg %% .%dg\n', precision,precision);
|
||||
realformat = sprintf('%% .%dg\n', precision);
|
||||
if ( ~ strcmp(symm,'general') )
|
||||
rowloop = 'j';
|
||||
else
|
||||
rowloop = '1';
|
||||
end
|
||||
if ( strcmp(mattype,'real') )
|
||||
for j=1:N
|
||||
for i=eval(rowloop):M
|
||||
fprintf(mmfile,realformat,A(i,j));
|
||||
end
|
||||
end
|
||||
elseif ( strcmp(mattype,'complex') )
|
||||
for j=1:N
|
||||
for i=eval(rowloop):M
|
||||
fprintf(mmfile,cplxformat,real(A(i,j)),imag(A(i,j)));
|
||||
end
|
||||
end
|
||||
elseif ( strcmp(mattype,'pattern') )
|
||||
err = -2
|
||||
disp('Pattern type inconsistant with dense matrix')
|
||||
else
|
||||
err = -2
|
||||
disp('Unknown matrix type:')
|
||||
mattype
|
||||
end
|
||||
end
|
||||
|
||||
fclose(mmfile);
|
60
thirdParty/Zoltan/src/matlab/plotcolors.m
vendored
Normal file
60
thirdParty/Zoltan/src/matlab/plotcolors.m
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% This matlab function returns a unique color/symbol pair for plotting.
|
||||
% The total number of color/symbol pairs needed and the index of this
|
||||
% color/symbol are taken as input arguments.
|
||||
%
|
||||
% Written by Michael Wolf
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
function [colorV,symb] = plotcolors(cindex,numcolors)
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%% For 4 or fewer colors
|
||||
if numcolors <= 4
|
||||
switch cindex
|
||||
case 1
|
||||
colorV = [1 0 0];
|
||||
case 2
|
||||
colorV = [0 1 0];
|
||||
case 3
|
||||
colorV = [0 0 1];
|
||||
otherwise
|
||||
colorV = [0 1 1];
|
||||
end
|
||||
symb = '.';
|
||||
%% For colors
|
||||
else
|
||||
% cmap = lines(numcolors);
|
||||
% cmap = hsv(numcolors);
|
||||
|
||||
%% ten distinct colors, add more later
|
||||
diffColors=8;
|
||||
cmap(1,:) = [ 1 0 0]; % red
|
||||
cmap(2,:) = [ 0 1 0]; % green
|
||||
cmap(3,:) = [ 0 0 1]; % blue
|
||||
cmap(4,:) = [ 0 1 1]; % cyan
|
||||
cmap(5,:) = [ 1 0 1]; % magenta
|
||||
cmap(6,:) = [ 0 0 0]; % black
|
||||
cmap(7,:) = [ 1 0.67 0]; % orange
|
||||
cmap(8,:) = [ 0.6 0.6 0.6]; % gray
|
||||
% cmap(9,:) = [0.75 0.75 0]; % dark yellow
|
||||
% cmap(10,:) = [ 0 0.4 0]; % dark green
|
||||
|
||||
colorV = cmap(mod(cindex-1,diffColors)+1,:);
|
||||
|
||||
|
||||
if floor((cindex-1)/diffColors) == 0
|
||||
symb = '.';
|
||||
else
|
||||
symb = 'o';
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
end
|
6
thirdParty/Zoltan/src/matlab/zdrive.matlab
vendored
Normal file
6
thirdParty/Zoltan/src/matlab/zdrive.matlab
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
zdrive debug level = 0
|
||||
#Decomposition Method = hypergraph
|
||||
Zoltan Parameters = lb_approach=partition
|
||||
Zoltan Parameters = graph_package=phg
|
||||
File Name = matlab
|
||||
Parallel Disk Info = number=0
|
214
thirdParty/Zoltan/src/matlab/zoltPartSpy.m
vendored
Normal file
214
thirdParty/Zoltan/src/matlab/zoltPartSpy.m
vendored
Normal file
@ -0,0 +1,214 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
% This matlab function produces spy-like plots in which the nonzeros are
|
||||
% colored based on the partition that owns them.
|
||||
%
|
||||
% The function takes 3 arguments: the filename of a matrix in matrix market
|
||||
% format, the name of the zoltan output file containg partition info, and
|
||||
% the type of partitioning ('1DRow', '1DColumn', '1.5DRow', '1.5DColumn').
|
||||
%
|
||||
% Written by Michael Wolf
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
function partSpyZoltan(matFilename,partFilename,partType)
|
||||
if nargin ~= 3
|
||||
error('Wrong number of input arguments. \n %s', ...
|
||||
'Usage: partSpyZoltan mtxFile partitionFile PartitionType')
|
||||
end
|
||||
|
||||
|
||||
% Parse zdrive output file, Erik Boman's code
|
||||
fp = fopen(partFilename, 'r');
|
||||
if (~fp)
|
||||
error('Could not open partition file\n');
|
||||
end
|
||||
|
||||
% Skip all lines before 'GID'
|
||||
word = 'abc';
|
||||
while (~strncmp(word, 'GID', 3))
|
||||
% Read only first word, ignore rest of line
|
||||
word = fscanf(fp,'%s',1);
|
||||
fscanf(fp,'%*[^\n]',1);
|
||||
end
|
||||
|
||||
% Read the partition numbers; file has 4 fields per line
|
||||
[P, num] = fscanf(fp, '%d', [4,inf]);
|
||||
% First two rows in P (columns in output file) give the partition vector
|
||||
part = zeros(size(P(1,:)));
|
||||
part(P(1,:)) = P(2,:);
|
||||
|
||||
|
||||
|
||||
|
||||
if strcmp(partType, '1DColumn')
|
||||
partSpyZolt1DC(matFilename,part);
|
||||
elseif strcmp(partType, '1DRow')
|
||||
partSpyZolt1DR(matFilename,part);
|
||||
elseif strcmp(partType, '1.5DColumn')
|
||||
partSpyZolt1_5DC(matFilename,part);
|
||||
elseif strcmp(partType, '1.5DRow')
|
||||
partSpyZolt1_5DR(matFilename,part);
|
||||
else
|
||||
error('Unsupported partitioning scheme ''%s''',partType);
|
||||
end
|
||||
|
||||
end
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% for zoltan with stripped partition information
|
||||
% 1d column partitioning
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
function partSpyZolt1DC(matFilename,part)
|
||||
|
||||
A = mmread(matFilename);
|
||||
|
||||
numParts=max( part ) +1;
|
||||
|
||||
numParts
|
||||
|
||||
for i=1:numParts
|
||||
[colors(i,:),symbols(i)]=plotcolors(i,numParts);
|
||||
x{i}=[];
|
||||
y{i}=[];
|
||||
end
|
||||
|
||||
[i,j,val] = find(A);
|
||||
n=length(i);
|
||||
|
||||
for cnt=1:n
|
||||
x{part(j(cnt))+1}(end+1) = j(cnt);
|
||||
y{part(j(cnt))+1}(end+1) = i(cnt);
|
||||
end
|
||||
|
||||
figure;
|
||||
hold on;
|
||||
for cnt=1:numParts
|
||||
plot(x{cnt},y{cnt}, symbols(cnt), 'Color', colors(cnt,:), ...
|
||||
'MarkerSize', 6);
|
||||
end
|
||||
|
||||
view([0 0 -1])
|
||||
end
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% for zoltan with stripped partition information
|
||||
% 1d row partitioning
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
function partSpyZolt1DR(matFilename,part)
|
||||
|
||||
A = mmread(matFilename);
|
||||
|
||||
numParts=max( part ) +1;
|
||||
|
||||
numParts
|
||||
|
||||
for i=1:numParts
|
||||
[colors(i,:),symbols(i)]=plotcolors(i,numParts);
|
||||
x{i}=[];
|
||||
y{i}=[];
|
||||
end
|
||||
|
||||
[i,j,val] = find(A);
|
||||
n=length(i);
|
||||
|
||||
|
||||
for cnt=1:n
|
||||
x{part(i(cnt))+1}(end+1) = j(cnt);
|
||||
y{part(i(cnt))+1}(end+1) = i(cnt);
|
||||
end
|
||||
|
||||
figure;
|
||||
hold on;
|
||||
for cnt=1:numParts
|
||||
plot(x{cnt},y{cnt}, symbols(cnt), 'Color', colors(cnt,:), ...
|
||||
'MarkerSize', 6);
|
||||
end
|
||||
|
||||
view([0 0 -1])
|
||||
end
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% for zoltan with stripped partition information
|
||||
% 1.5d col partitioning
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
function partSpyZolt1_5DC(matFilename,part)
|
||||
|
||||
A = mmread(matFilename);
|
||||
|
||||
numParts=max( part ) +1;
|
||||
|
||||
numParts
|
||||
|
||||
for i=1:numParts
|
||||
[colors(i,:),symbols(i)]=plotcolors(i,numParts);
|
||||
x{i}=[];
|
||||
y{i}=[];
|
||||
end
|
||||
|
||||
[i,j,val] = find(A);
|
||||
n=length(i);
|
||||
|
||||
for cnt=1:n
|
||||
if i(cnt) >= j(cnt)
|
||||
x{part(j(cnt))+1}(end+1) = j(cnt);
|
||||
y{part(j(cnt))+1}(end+1) = i(cnt);
|
||||
else
|
||||
x{part(i(cnt))+1}(end+1) = j(cnt);
|
||||
y{part(i(cnt))+1}(end+1) = i(cnt);
|
||||
end
|
||||
end
|
||||
|
||||
figure;
|
||||
hold on;
|
||||
for cnt=1:numParts
|
||||
plot(x{cnt},y{cnt}, symbols(cnt), 'Color', colors(cnt,:), ...
|
||||
'MarkerSize', 6);
|
||||
end
|
||||
|
||||
view([0 0 -1])
|
||||
end
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% for zoltan with stripped partition information
|
||||
% 1.5d row partitioning
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
function partSpyZolt1_5DR(matFilename,part)
|
||||
|
||||
A = mmread(matFilename);
|
||||
|
||||
numParts=max( part ) +1;
|
||||
|
||||
numParts
|
||||
|
||||
for i=1:numParts
|
||||
[colors(i,:),symbols(i)]=plotcolors(i,numParts);
|
||||
x{i}=[];
|
||||
y{i}=[];
|
||||
end
|
||||
|
||||
[i,j,val] = find(A);
|
||||
n=length(i);
|
||||
|
||||
for cnt=1:n
|
||||
if i(cnt) >= j(cnt)
|
||||
x{part(i(cnt))+1}(end+1) = j(cnt);
|
||||
y{part(i(cnt))+1}(end+1) = i(cnt);
|
||||
else
|
||||
x{part(j(cnt))+1}(end+1) = j(cnt);
|
||||
y{part(j(cnt))+1}(end+1) = i(cnt);
|
||||
end
|
||||
end
|
||||
|
||||
figure;
|
||||
hold on;
|
||||
for cnt=1:numParts
|
||||
plot(x{cnt},y{cnt}, symbols(cnt), 'Color', colors(cnt,:), ...
|
||||
'MarkerSize', 6);
|
||||
end
|
||||
|
||||
view([0 0 -1])
|
||||
end
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
108
thirdParty/Zoltan/src/matlab/zoltan.m
vendored
Normal file
108
thirdParty/Zoltan/src/matlab/zoltan.m
vendored
Normal file
@ -0,0 +1,108 @@
|
||||
function [part,perm] = zoltan(A, p, method, dir, opt)
|
||||
% function [part,perm] = zoltan(A, p, method, dir, opt)
|
||||
%
|
||||
% Partition a sparse matrix along rows or cols,
|
||||
% using the Zoltan graph and hypergraph partitioner.
|
||||
% Balance number of row/columns, or the nonzeros.
|
||||
%
|
||||
% Input: (only first argument is required)
|
||||
% A, a sparse matrix
|
||||
% p, the number of parts (partitions)
|
||||
% method, 'graph' or 'hypergraph'
|
||||
% dir, the cut direction (1=rows, 2=cols)
|
||||
% opt, Zoltan partitioning options
|
||||
%
|
||||
% Output:
|
||||
% part, a partition vector with values in 0..p-1
|
||||
% perm, a permutation vector to order A by the partition numbers
|
||||
%
|
||||
% Written by Erik Boman.
|
||||
% (C) Copyright Sandia Corporation, 2006-2007
|
||||
|
||||
if (nargin<5)
|
||||
opt = [];
|
||||
end
|
||||
if (nargin<4)
|
||||
dir = 1;
|
||||
end
|
||||
if (nargin<3)
|
||||
method = 'hypergraph';
|
||||
end
|
||||
if (nargin<2)
|
||||
p = 2;
|
||||
end
|
||||
|
||||
% For graph model, symmetrize
|
||||
if (strcmp(method,'graph'))
|
||||
[m,n] = size(A);
|
||||
if (m==n) % Square
|
||||
S = (A~=0); % Structure only
|
||||
if (norm(S-S','fro'))
|
||||
A = A+A';
|
||||
end
|
||||
else % Rectangular
|
||||
if (dir==1)
|
||||
A = A*A';
|
||||
else
|
||||
A = A'*A;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
% Write matrix to file
|
||||
mmwrite('matlab.mtx', A);
|
||||
|
||||
% Copy standard zdrive input file (overwrite old zdrive.inp)
|
||||
copyfile ('zdrive.matlab', 'zdrive.inp');
|
||||
fp = fopen('zdrive.inp', 'a');
|
||||
|
||||
% Append load balance method
|
||||
fprintf(fp, 'Decomposition method = %s\n', method);
|
||||
|
||||
%% Direction determines row or column partition
|
||||
if (dir==1)
|
||||
fprintf(fp, 'File Type = matrixmarket, objects=rows\n');
|
||||
elseif (dir==2)
|
||||
fprintf(fp, 'File Type = matrixmarket, objects=cols\n');
|
||||
else
|
||||
error('Invalid value for dir; must be 1 or 2!');
|
||||
end
|
||||
|
||||
% Append number of parts
|
||||
fprintf(fp, 'Zoltan parameter = num_global_parts=%d\n', p);
|
||||
% Append other options
|
||||
if (opt)
|
||||
% Loop over options
|
||||
for option = opt
|
||||
fprintf(fp, 'Zoltan parameter = %s\n', option);
|
||||
end
|
||||
end
|
||||
|
||||
% Run zdrive to partition the matrix
|
||||
% zdrive must be in your path.
|
||||
!zdrive
|
||||
|
||||
% Parse zdrive output file
|
||||
fp = fopen('matlab.out.1.0', 'r');
|
||||
if (~fp)
|
||||
error('Could not open zdrive output file\n');
|
||||
end
|
||||
% Skip all lines before 'GID'
|
||||
word = 'abc';
|
||||
while (~strncmp(word, 'GID', 3))
|
||||
% Read only first word, ignore rest of line
|
||||
word = fscanf(fp,'%s',1);
|
||||
fscanf(fp,'%*[^\n]',1);
|
||||
end
|
||||
% Read the partition numbers; file has 4 fields per line
|
||||
[P, num] = fscanf(fp, '%d', [4,inf]);
|
||||
% First two rows in P (columns in output file) give the partition vector
|
||||
part = zeros(size(P(1,:)));
|
||||
part(P(1,:)) = P(2,:);
|
||||
|
||||
% Construct corresponding permutation vector
|
||||
perm = [];
|
||||
for i= 0:p-1
|
||||
perm = [perm, find(part==i)];
|
||||
end
|
||||
|
Reference in New Issue
Block a user